You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

793 lines
35 KiB
C#

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
using DSWeb.MvcShipping.Models.MsOpPlan;
using Microsoft.Practices.EnterpriseLibrary.Data;
using DSWeb.EntityDA;
using DSWeb.Areas.CommMng.Models;
using HcUtility.Comm;
using HcUtility.Core;
using System.Data.SqlClient;
using DSWeb.DataAccess;
using DSWeb.MvcShipping.Models.MsCodeServiceFeeTemplate;
using DSWeb.MvcShipping.DAL.MsCodeServiceFeeTemplateDAL;
using System.Web;
using DSWeb.MvcShipping.Models.MsSysBillNoSet;
using DSWeb.MvcShipping.DAL.MsSysBillNoSet;
using DSWeb.MvcShipping.DAL.MsChFeeDAL;
using DSWeb.MvcShipping.Models.MsChFee;
using DSWeb.MvcShipping.DAL.MsOpOtherDAL;
using DSWeb.MvcShipping.Models.MsOpOther;
using DSWeb.Areas.SysMng.DAL.SysUser;
using DSWeb.MvcShipping.DAL.MsInfoClient;
namespace DSWeb.MvcShipping.DAL.MsOpPlanDAL
{
public class MsOpPlanDAL
{
#region Inquery DataList
static public List<MsOpPlan> GetDataList(int start, int limit, string strCondition, string userid, string usercode, string companyid,bool issale,string sort = null)
{
if (issale)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and TOSALE=1 and SALE='"+usercode+"'";
}
else
{
strCondition = " TOSALE=1 and SALE='" + usercode + "'";
}
}
else
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
}
var strSql = new StringBuilder();
strSql.Append(@"SELECT * from (SELECT row_number() over (");
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql.Append(" order by " + sortstring);
}
else
{
strSql.Append(" order by SFNO ");
}
strSql.Append(@") as num , "); //
strSql.Append("op_plan.[BSNO],[MASTERNO],[CUSTNO],[BSSTATUS],[BSDATE],[ACCDATE],[BSSOURCE],[BSSOURCEDETAIL],[CUSTOMERNAME],[SALE]");
strSql.Append(",(SELECT TOP 1 STATUS FROM V_OP_STATUS WITH (NOLOCK) WHERE BSNO=op_plan.BSNO ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS");
strSql.Append(",[AMOUNT],[FEEDATE],[REMARK],[OTREMARK],[INPUTBY],[INPUTDATE],[CORPID],[TOSALE],[SFNO],dbo.F_GetBillDrFeeStatus(op_plan.MASTERNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_plan.MASTERNO) CRFEESTATUS");
strSql.Append(",I.TTLDR,I.TTLINVDR,(SELECT CUSTNO FROM OP_OTHER WHERE BSNO=op_plan.MASTERNO) BSCUSTNO,MODIFIEDUSER,MODIFIEDTIME FROM op_plan");
strSql.Append(" LEFT JOIN v_op_gain_dr_INV I ON (I.BSNO=op_plan.MASTERNO) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(@")as t ");
strSql.Append(string.Format("where t.num>={0} and t.num<={1} order by t.num", start, start + limit)); //
return SetData(strSql.ToString());
}
static public List<MsOpPlan> GetDataAllList(int start, int limit, string strCondition)
{
var strSql = new StringBuilder();
strSql.Append(@"SELECT * from (SELECT row_number() over (");
strSql.Append(" order by BSDATE desc");
strSql.Append(@") as num , "); //
strSql.Append("op_plan.[BSNO],[MASTERNO],[CUSTNO],[BSSTATUS],[BSDATE],[ACCDATE],[BSSOURCE],[BSSOURCEDETAIL],[CUSTOMERNAME],[SALE]");
strSql.Append(",(SELECT TOP 1 STATUS FROM V_OP_STATUS WITH (NOLOCK) WHERE BSNO=op_plan.BSNO ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS");
strSql.Append(",[AMOUNT],[FEEDATE],[REMARK],[OTREMARK],[INPUTBY],[INPUTDATE],[CORPID],[TOSALE],[SFNO],dbo.F_GetBillDrFeeStatus(op_plan.MASTERNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_plan.MASTERNO) CRFEESTATUS");
strSql.Append(",I.TTLDR,I.TTLINVDR,(SELECT CUSTNO FROM OP_OTHER WHERE BSNO=op_plan.MASTERNO) BSCUSTNO,MODIFIEDUSER,MODIFIEDTIME FROM op_plan");
strSql.Append(" LEFT JOIN v_op_gain_dr_INV I ON (I.BSNO=op_plan.MASTERNO) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
strSql.Append(@")as t ");
strSql.Append(string.Format("where t.num>={0} and t.num<={1} order by t.num", start, start + limit)); //
return SetData(strSql.ToString());
}
public static int getTotalCount(string strCondition, string userid, string usercode, string companyid, bool issale)
{
if (issale)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and TOSALE=1 and SALE='" + usercode + "'";
}
else
{
strCondition = " TOSALE=1 and SALE='" + usercode + "'";
}
}
else
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
}
StringBuilder strSql = new StringBuilder();
strSql.Append("select count(*) ");
strSql.Append(" from op_plan ");
strSql.Append(" LEFT JOIN v_op_gain_dr_INV I ON (I.BSNO=op_plan.MASTERNO) ");
if (!string.IsNullOrEmpty(strCondition))
{
strSql.Append(" where " + strCondition);
}
int cnt = 0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
cnt = Convert.ToInt32(reader[0]);
}
}
return cnt;
}
static public string GetDataListStr(string strCondition, string userid, string usercode, string companyid, bool issale, string sort = null)
{
if (issale)
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and TOSALE=1 and SALE='" + usercode + "'";
}
else
{
strCondition = " TOSALE=1 and SALE='" + usercode + "'";
}
}
else
{
var rangstr = GetRangDAStr("index", userid, usercode, companyid);
if (!string.IsNullOrEmpty(rangstr))
{
if (!string.IsNullOrEmpty(strCondition))
{
strCondition = strCondition + " and " + rangstr;
}
else
{
strCondition = rangstr;
}
}
}
//
String strSql = "SELECT op_plan.[BSNO],[MASTERNO],[CUSTNO],[BSSTATUS],[BSDATE],[ACCDATE],[BSSOURCE],[BSSOURCEDETAIL],[CUSTOMERNAME],[SALE]";
strSql = strSql + ",(SELECT TOP 1 STATUS FROM V_OP_STATUS WITH (NOLOCK) WHERE BSNO=op_plan.BSNO ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS";
strSql = strSql + ",[AMOUNT],[FEEDATE],[REMARK],[OTREMARK],[INPUTBY],[INPUTDATE],[CORPID],[TOSALE],[SFNO],dbo.F_GetBillDrFeeStatus(op_plan.MASTERNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_plan.MASTERNO) CRFEESTATUS";
strSql = strSql + ",I.TTLDR,I.TTLINVDR,(SELECT CUSTNO FROM OP_OTHER WHERE BSNO=op_plan.MASTERNO) BSCUSTNO,MODIFIEDUSER,MODIFIEDTIME,'' DRINVSTATUS FROM op_plan";
strSql = strSql + " LEFT JOIN v_op_gain_dr_INV I ON (I.BSNO=op_plan.MASTERNO)";
if (!string.IsNullOrEmpty(strCondition))
{
strSql += " where " + strCondition;
}
var sortstring = DatasetSort.Getsortstring(sort);
if (!string.IsNullOrEmpty(sortstring))
{
strSql += " order by " + sortstring;
}
else
{
strSql += " order by BSDATE desc";
}
return strSql.ToString();
}
static public MsOpPlan GetData(string condition)
{
String strSql = "SELECT op_plan.[BSNO],[MASTERNO],[CUSTNO],[BSSTATUS],[BSDATE],[ACCDATE],[BSSOURCE],[BSSOURCEDETAIL],[CUSTOMERNAME],[SALE]";
strSql = strSql + ",(SELECT TOP 1 STATUS FROM V_OP_STATUS WITH (NOLOCK) WHERE BSNO=op_plan.BSNO ORDER BY COMPTIME DESC,INPUTTIME DESC) as OPSTATUS";
strSql = strSql + ",[AMOUNT],[FEEDATE],[REMARK],[OTREMARK],[INPUTBY],[INPUTDATE],[CORPID],[TOSALE],[SFNO],dbo.F_GetBillDrFeeStatus(op_plan.MASTERNO) DRFEESTATUS,dbo.F_GetBillCrFeeStatus(op_plan.MASTERNO) CRFEESTATUS ";
strSql = strSql + ",I.TTLDR,I.TTLINVDR,(SELECT CUSTNO FROM OP_OTHER WHERE BSNO=op_plan.MASTERNO) BSCUSTNO,MODIFIEDUSER,MODIFIEDTIME FROM op_plan";
strSql = strSql + " LEFT JOIN v_op_gain_dr_INV I ON (I.BSNO=op_plan.MASTERNO)";
if (!string.IsNullOrEmpty(condition))
{
strSql += " where " + condition;
}
var list=SetData(strSql);
if (list.Count > 0)
{
return list[0];
}
return new MsOpPlan();
}
private static List<MsOpPlan> SetData(String strSql)
{
var headList = new List<MsOpPlan>();
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
MsOpPlan data = new MsOpPlan();
#region Set DB data to Object
data.BSNO = Convert.ToString(reader["BSNO"]);
data.MASTERNO = Convert.ToString(reader["MASTERNO"]);
data.BSSTATUS = Convert.ToString(reader["BSSTATUS"]);
data.OPSTATUS = Convert.ToString(reader["OPSTATUS"]);
data.DRFEESTATUS = getfeestatus(Convert.ToString(reader["DRFEESTATUS"]));
data.CRFEESTATUS = getfeestatus(Convert.ToString(reader["CRFEESTATUS"]));
data.CUSTNO = Convert.ToString(reader["CUSTNO"]);
data.BSCUSTNO = Convert.ToString(reader["BSCUSTNO"]);
data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]);
data.BSDATE = Convert.ToString(reader["BSDATE"]);
data.ACCDATE = Convert.ToString(reader["ACCDATE"]);
data.BSSOURCE = Convert.ToString(reader["BSSOURCE"]);
data.BSSOURCEDETAIL = Convert.ToString(reader["BSSOURCEDETAIL"]);
data.SALE = Convert.ToString(reader["SALE"]);
data.CORPID = Convert.ToString(reader["CORPID"]);
data.REMARK = Convert.ToString(reader["REMARK"]);
data.OTREMARK = Convert.ToString(reader["OTREMARK"]);
data.INPUTBY = Convert.ToString(reader["INPUTBY"]);
if (reader["INPUTDATE"] != DBNull.Value)
data.INPUTDATE = Convert.ToDateTime(reader["INPUTDATE"]).ToString("yyyy-MM-dd hh:mm:ss");
data.FEEDATE = Convert.ToString(reader["FEEDATE"]);
decimal ttldr = 0;
if (reader["TTLDR"] != DBNull.Value)
ttldr = Convert.ToDecimal(reader["TTLDR"]);
decimal ttlinvdr = 0;
if (reader["TTLDR"] != DBNull.Value)
ttlinvdr = Convert.ToDecimal(reader["TTLINVDR"]);
if (ttlinvdr == 0) data.DRINVSTATUS = "未开票";
else if (ttlinvdr == ttldr) data.DRINVSTATUS = "已开票";
else if (ttlinvdr != ttldr) data.DRINVSTATUS = "部分开票";
if (reader["TOSALE"] != DBNull.Value)
data.TOSALE = Convert.ToBoolean(reader["TOSALE"]);
if (reader["AMOUNT"] != DBNull.Value)
data.AMOUNT = Convert.ToDecimal(reader["AMOUNT"]);
data.MODIFIEDUSER = Convert.ToString(reader["MODIFIEDUSER"]);
if (reader["MODIFIEDTIME"] != DBNull.Value)
data.MODIFIEDTIME = Convert.ToDateTime(reader["MODIFIEDTIME"]).ToString("yyyy-MM-dd hh:mm:ss");
#endregion
headList.Add(data);
}
reader.Close();
}
return headList;
}
public static string getfeestatus(string feestatusint)
{
var result = "";
if (feestatusint == "0:")
{
return "审核通过";
}
else if (feestatusint == "1:")
{
return "录入状态";
}
else if (feestatusint == "2:")
{
return "提交审核";
}
else if (feestatusint == "8:")
{
return "部分结算";
}
else if (feestatusint == "9:")
{
return "结算完毕";
}
else if (feestatusint == "")
{
return "未录入";
}
else if (feestatusint == "3:")
{
return "申请修改";
}
else if (feestatusint == "4:")
{
return "申请删除";
}
else if (feestatusint == "6:")
{
return "驳回提交";
}
else if (feestatusint == "7:")
{
return "驳回申请";
}
else if (feestatusint.IndexOf("9:") > -1)
{
return "部分结算";
}
else if (feestatusint.IndexOf("8:") > -1)
{
return "部分结算";
}
else if (feestatusint.IndexOf("0:") > -1)
{
return "部分审核";
}
else if (feestatusint.IndexOf("2:") > -1)
{
return "部分提交";
}
else if (feestatusint.IndexOf("6:") > -1)
{
return "驳回提交";
}
else if (feestatusint.IndexOf("7:") > -1)
{
return "驳回申请";
}
return result;
}
#endregion
#region 明细表
public static DBResult DeleteDetail(MsOpPlan headData)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
var cmdDelete = db.GetSqlStringCommand("delete from op_plan_detail where BSNO='" + headData.BSNO + "'");
db.ExecuteNonQuery(cmdDelete, tran);
tran.Commit();
}
catch (Exception)
{
tran.Rollback();
result.Success = false;
result.Message = "删除出现错误,请重试或联系系统管理员";
return result;
}
}
result.Success = true;
result.Message = "保存成功";
return result;
}
#endregion
#region 判断编码是否有重复
static public int GetRdCount(string strCondition)
{
var strSql = new StringBuilder();
strSql.Append("SELECT ");
strSql.Append(" Count(BSNO) AS CT ");
strSql.Append(" from op_plan ");
if (strCondition.Trim() != String.Empty)
{
strSql.Append(" where " + strCondition);
}
var ct=0;
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
ct = Convert.ToInt16(reader["CT"]);
}
reader.Close();
}
return ct;
}
#endregion
#region EXCEL导入
public static DBResult ImpOpPlan(DataTable table, string userid, string username, string companyid)
{
var result = new DBResult();
Database db = DatabaseFactory.CreateDatabase();
var cmdInsert =
db.GetSqlStringCommand(
@"insert into op_plan (BSNO,CUSTNO,BSDATE,ACCDATE,BSSOURCE,BSSOURCEDETAIL,CUSTOMERNAME,SALE,AMOUNT,FEEDATE,REMARK,OTREMARK,INPUTBY,INPUTDATE,SFNO,CORPID)
values (@BSNO,@CUSTNO,@BSDATE,@ACCDATE,@BSSOURCE,@BSSOURCEDETAIL,@CUSTOMERNAME,@SALE,@AMOUNT,@FEEDATE,@REMARK,@OTREMARK,@INPUTBY,@INPUTDATE,@SFNO,@CORPID) ");
var _date = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
var FEEDATE = "";
using (var conn = db.CreateConnection())
{
conn.Open();
var tran = conn.BeginTransaction();
try
{
int num = 0;
foreach (DataRow row in table.Rows)
{
if (row[1].ToString() != "")
{
num = num + 1;
FEEDATE = Convert.ToString(row["首次计费时间"]).Replace("/","-");
if (FEEDATE != "")
{
var datelist = FEEDATE.Split('-');
if (datelist.Length> 2)
{
var datemonth = datelist[1];
if (datemonth.Length == 1) datemonth = "0" + datemonth;
var dateday = datelist[2];
if (dateday.Length == 1) dateday = "0" + dateday;
FEEDATE = datelist[0] + "-" + datemonth + "-" + dateday;
if (Convert.ToDateTime(FEEDATE.Substring(0, 10)) > DateTime.Now.AddMonths(1))
FEEDATE = Convert.ToDateTime(FEEDATE.Substring(0, 10)).AddYears(-70).ToString("yyyy-MM-dd");
else FEEDATE = Convert.ToDateTime(FEEDATE.Substring(0, 10)).ToString("yyyy-MM-dd");
}
}
var ACCDATE = "";
var MONTH = Convert.ToString(row["月份"]);
if (MONTH.Length < 7)
{
var YEAR = DateTime.Now.ToString("yyyy");
if (MONTH == "12" || MONTH == "11")
{
var NOWMONTH = DateTime.Now.Month;
if (NOWMONTH < 3)
{
YEAR = DateTime.Now.AddYears(-1).ToString("yyyy");
}
}
if (MONTH.Length == 1) MONTH = "0" + MONTH;
ACCDATE = YEAR + "-" + MONTH;
}
else {
ACCDATE = MONTH;
}
//if (!string.IsNullOrEmpty(CUSTNO))
//{
cmdInsert.Parameters.Clear();
db.AddInParameter(cmdInsert, "@BSNO", DbType.String, Guid.NewGuid().ToString());
db.AddInParameter(cmdInsert, "@CUSTNO", DbType.String, Convert.ToString(row["计划单号"]));
db.AddInParameter(cmdInsert, "@BSDATE", DbType.String, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@ACCDATE", DbType.String, ACCDATE);
db.AddInParameter(cmdInsert, "@BSSOURCE", DbType.String, Convert.ToString(row["业务来源"]));
db.AddInParameter(cmdInsert, "@BSSOURCEDETAIL", DbType.String, Convert.ToString(row["来源明细"]));
db.AddInParameter(cmdInsert, "@CUSTOMERNAME", DbType.String, Convert.ToString(row["客户名称"]));
db.AddInParameter(cmdInsert, "@SALE", DbType.String, Convert.ToString(row["揽货人"]));
db.AddInParameter(cmdInsert, "@AMOUNT", DbType.Decimal, Convert.ToDecimal(row["金额"]));
db.AddInParameter(cmdInsert, "@FEEDATE", DbType.String, FEEDATE);
db.AddInParameter(cmdInsert, "@REMARK", DbType.String, Convert.ToString(row["备注"]));
db.AddInParameter(cmdInsert, "@OTREMARK", DbType.String, Convert.ToString(row["其他备注"]));
db.AddInParameter(cmdInsert, "@INPUTBY", DbType.String, username);
db.AddInParameter(cmdInsert, "@INPUTDATE", DbType.String, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
db.AddInParameter(cmdInsert, "@SFNO", DbType.Int32, num);
db.AddInParameter(cmdInsert, "@CORPID", DbType.String, companyid);
db.ExecuteNonQuery(cmdInsert, tran);
//}
}
}
tran.Commit();
result.Success = true;
result.Message = "导入成功";
}
catch (Exception ex)
{
tran.Rollback();
result.Success = false;
result.Message = "导入中出错:" + ex.Message+ FEEDATE;
}
}
return result;
}
#endregion
public static DBResult SaveToOther(List<MsOpPlan> bodyList, string userid, string username, string companyid)
{
var result = new DBResult();
if (bodyList != null)
{
T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA();
string rq = T_ALL_DA.GetStrSQL("rq", "select getdate() as rq");
foreach (var enumValue in bodyList)
{
var headData = new MsOpOtherEntity();
headData.CORPID = companyid;
headData.BSNO = "topother" + Guid.NewGuid().ToString().Replace("-", "");
headData.ACCDATE = enumValue.ACCDATE;
headData.SALE = enumValue.SALE;
headData.BSSOURCE = enumValue.BSSOURCE;
headData.BSSOURCEDETAIL = enumValue.BSSOURCEDETAIL;
headData.REMARK = enumValue.REMARK;
headData.CUSTOMERNAME = enumValue.CUSTOMERNAME;
headData.DbOperationType = DbOperationType.DbotIns;
headData.BSDATE = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
headData.ETD= DateTime.Now.ToString("yyyy-MM-dd");
headData.OPLB = "op_other";//业务类型
headData.OPLBNAME = "散杂运输";//业务类型名称
headData.BSSTATUS = false;//业务状态
headData.FEESTATUS = false;//费用状态
headData.ISVOU = false;//是否生成凭证
headData.VOUNO = "";//凭证号
headData.CREATEUSER = userid;//创建人
headData.CREATETIME = DateTime.Parse(rq);//创建时间
headData.MODIFIEDUSER = userid;//最后一次操作人
headData.MODIFIEDTIME = DateTime.Parse(rq);//最后一次操作时间
var billnoset = MsSysBillNoSetDAL.GetData("OPLBNAME='综合业务'", companyid);
if (billnoset.BILLTYPE != "")
{
var CUSTOMHEAD = "";
if (billnoset.CUSTOMHEAD != "")
{
var HBLCUSTOMHEAD = billnoset.CUSTOMHEAD;
if ((HBLCUSTOMHEAD.IndexOf("[SALE]") >= 0) && !string.IsNullOrEmpty(headData.SALE))
{
var user = SysUserDAL.GetData("u.SHOWNAME='" + headData.SALE + "'");
if (!string.IsNullOrEmpty(user.NOCODE))
HBLCUSTOMHEAD = HBLCUSTOMHEAD.Replace("[SALE]", user.NOCODE);
}
if ((HBLCUSTOMHEAD.IndexOf("[OP]") >= 0) && !string.IsNullOrEmpty(headData.OP))
{
var user = SysUserDAL.GetData("u.SHOWNAME='" + headData.OP + "'");
if (!string.IsNullOrEmpty(user.NOCODE))
HBLCUSTOMHEAD = HBLCUSTOMHEAD.Replace("[OP]", user.NOCODE);
}
CUSTOMHEAD = HBLCUSTOMHEAD;
var CUST = MsInfoClientDAL.GetData("SHORTNAME='" + headData.CUSTOMERNAME + "'");
CUSTOMHEAD = CUSTOMHEAD.Replace("[CUSTCODE]", CUST.CODENAME);
}
headData.CUSTNO = MsSysBillNoSetDAL.GetBillNo(billnoset, headData.ETD.ToString().Trim(), headData.ACCDATE.ToString().Trim(), "", headData.OP, headData.SALECORPID, CUSTOMHEAD);
}
else {
headData.CUSTNO = MsOpOtherDAL.MsOpOtherDAL.getCodeRule("委托编号", 6, "CUSTNO", headData.BSDATE.ToString().Trim(), headData.ACCDATE.ToString().Trim(), userid, companyid);
}
var modb = new ModelObjectDB();
result = modb.Save(headData);
if (result.Success) {
var newfeelist = new List<MsChFee>();
var enumValueBody = new MsChFee();
enumValueBody.GId = Guid.NewGuid().ToString();
enumValueBody.BsNo = "*";
enumValueBody.FeeType = 1;
enumValueBody.FeeStatus = 0;
if (headData.BSSOURCE=="维护"||headData.BSSOURCE.IndexOf("续费")>0)
enumValueBody.FeeName ="维护费";
else
enumValueBody.FeeName ="软件费";
enumValueBody.CustomerName = enumValue.CUSTOMERNAME;
enumValueBody.EnteroPerator = userid;
enumValueBody.Unit = "票";
enumValueBody.Quantity = 1;
enumValueBody.UnitPrice = enumValue.AMOUNT;
enumValueBody.Amount = enumValue.AMOUNT;
enumValueBody.NoTaxAmount = enumValue.AMOUNT;
enumValueBody.Currency = "RMB";
enumValueBody.ExChangerate = 1;
enumValueBody.IsOpen = "0";
enumValueBody.IsAdvancedpay = "0";
//enumValueBody.FeeStatus = 1;
enumValueBody.TaxRate = 0;
enumValueBody.AccTaxRate = 0;
enumValueBody.IsInvoice = "0";
enumValueBody.LOCALCURR = "RMB";
if (enumValueBody.Amount != 0)
newfeelist.Add(enumValueBody);
if (newfeelist.Count != 0)
MsChFeeDAL.MsChFeeDAL.SaveUpdateFee(newfeelist, headData.BSNO, userid);
enumValue.DbOperationType = DbOperationType.DbotUpd;
enumValue.MASTERNO = headData.BSNO;
enumValue.MODIFIEDUSER = userid;//最后一次操作人
enumValue.MODIFIEDTIME =DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");//最后一次操作时间
modb.Save(enumValue);
}
}
}
result.Success = true;
result.Message = "保存成功" + result.Message;
return result;
}
#region Rang权限范围
public static string GetRangDAStr(string tb, string userid, string username, string companyid)
{
string str = "";
var strSql = new StringBuilder();
strSql.Append("SELECT");
strSql.Append(" VISIBLERANGE,OPERATERANGE,AUTHORITYID,VSSQL");
strSql.Append(" from VW_User_Authority");
strSql.Append(" where [NAME]='modOpPlanList' and USERID='" + userid + "' and ISDELETE=0");
string visiblerange = "4";
string operaterange = "4";
string AUTHORITYID = "";
string VSSQL = "";
Database db = DatabaseFactory.CreateDatabase();
using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
{
while (reader.Read())
{
visiblerange = Convert.ToString(reader["VISIBLERANGE"]);
operaterange = Convert.ToString(reader["OPERATERANGE"]);
AUTHORITYID = Convert.ToString(reader["AUTHORITYID"]);
VSSQL = Convert.ToString(reader["VSSQL"]);
break;
}
reader.Close();
}
if (visiblerange == "4")
{
str = " (INPUTBY='" + username + "' OR SALE='" + username + "')";
}
else if (visiblerange == "3")
{
str = " (INPUTBY='" + username + "' OR SALE='" + username + "')";
}
else if (visiblerange == "2")
{
var rangeDa = new RangeDA();
var deptname = rangeDa.GetDEPTNAME(userid);
str = " (INPUTBY in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "'))"
+ " OR SALE in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "') and GID in (select userid from user_baseinfo where DEPTNAME='" + deptname + "')))";
}
else if (visiblerange == "1")
{
str = " (UPPER(op_plan.Corpid)='" + companyid + "') ";
}
else if (visiblerange == "5")
{
if (tb == "index")
{
var userstr = new StringBuilder();
userstr.Append(" select COMPANYID from user_authority_range_company where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
str = "";
while (reader.Read())
{
if (str == "")
{
str = " (op_plan.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "' ";
}
else
{
str = str + " or op_plan.Corpid='" + Convert.ToString(reader["COMPANYID"]) + "'";
};
}
str = str + ")";
reader.Close();
}
}
else
{
str = " (UPPER(op_plan.Corpid)='" + companyid + "') ";
}
}
else if (visiblerange == "6")
{
if (tb == "index")
{
var opstr = "";
var userstr = new StringBuilder();
userstr.Append(" select OPID,(select SHOWNAME from [user] where GID=user_authority_range_op.OPID) SHOWNAME from user_authority_range_op where userid='" + userid + "' and AUTHORITYID='" + AUTHORITYID + "' and VISIBLERANGE=1");
Database userdb = DatabaseFactory.CreateDatabase();
using (IDataReader reader = userdb.ExecuteReader(CommandType.Text, userstr.ToString()))
{
while (reader.Read())
{
if (opstr == "")
{
opstr = " ('" + Convert.ToString(reader["SHOWNAME"]) + "'";
}
else
{
opstr = opstr + ",'" + Convert.ToString(reader["SHOWNAME"]) + "'";
};
}
if (opstr != "") opstr = opstr + ")";
reader.Close();
}
if (opstr == "") opstr = "('" + username + "')";
str = " (INPUTBY in " + opstr + " or SALE IN " + opstr + " )";
}
else
{
str = " (UPPER(op_plan.Corpid)='" + companyid + "') ";
}
}
else if (visiblerange == "0")
{
str = " 1=1 ";
}
VSSQL = VSSQL.Trim();
if (!string.IsNullOrEmpty(VSSQL))
{
if (!string.IsNullOrEmpty(str))
{
str = str + " and (" + VSSQL + ") ";
}
else
{
str = " (" + VSSQL + ") ";
}
}
return str;
}
#endregion
}
}