using System; using System.Data; using System.Collections.Generic; using System.Text; using DSWeb.MvcShipping.Models.MsOpTask; using Microsoft.Practices.EnterpriseLibrary.Data; using DSWeb.EntityDA; using HcUtility.Comm; using DSWeb.MvcShipping.Models.MsUserAuthority; using DSWeb.MvcShipping.DAL.MsChFeeDAL; using DSWeb.Areas.CommMng.Models; using DSWeb.Areas.CommMng.DAL; namespace DSWeb.Areas.MvcShipping.DAL { public class MsOpTaskDAL { #region Inquery DataList static public List GetDataList(int start, int limit, string strCondition, string userid, string usercode, string companyid, string sort = null) { //var rangestr = BasicDataRefDAL.GetVisableRange("任务管理", userid, "b.CORPID", new string[] { "b.OP", "b.CUSTSERVICE" } , "b.SALEDEPT"); 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)) { sortstring = sortstring.Replace("CREATETIME", "t.CREATETIME"); sortstring = sortstring.Replace("OP", "t.OP"); strSql.Append(" order by " + sortstring); } else { strSql.Append(" order by TASKNO DESC "); } strSql.Append(@") as num , "); strSql.Append("t.GID,t.TASKNO,t.PTASKNO,t.TASKTYPE,t.TASKSOURCE,t.TASKSTATUS,t.TASKTITLE,t.TASKDESCRIP,t.CREATEUSER,t.CORPID,t.CREATETIME,t.TASKBEGINDATE"); strSql.Append(",t.COMPLETETYPE,t.COMPLETETIME,t.KPI,ISNULL(b.MBLNO,t.MBLNO) MBLNO,t.FILENO,t.MAILNO,t.FILEPATH,t.ISPUBLIC,t.OP,t.BSNO,t.ISCOMPLETE,t.REMARK,b.CUSTOMERNAME,b.ETD,b.CARRIER,b.CUSTNO "); strSql.Append(" from op_task t left join v_op_bs b on (b.BSNO=t.BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where t.TASKSTATUS!='待挂单' and " + strCondition); } if (!string.IsNullOrEmpty(rangstr)) { strSql.Append(" and " + rangstr); } 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); } public static int getTotalCount(string strCondition, string userid, string usercode, string companyid) { 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_task t left join v_op_bs b on (b.BSNO=t.BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where t.TASKSTATUS!='待挂单' and " + 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 OpTask GetData(string condition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("t.GID,t.TASKNO,t.PTASKNO,t.TASKTYPE,t.TASKSOURCE,t.TASKSTATUS,t.TASKTITLE,t.TASKDESCRIP,t.CREATEUSER,t.CORPID,t.CREATETIME,t.TASKBEGINDATE"); strSql.Append(",t.COMPLETETYPE,t.COMPLETETIME,t.KPI,ISNULL(b.MBLNO,t.MBLNO) MBLNO,t.FILENO,t.MAILNO,t.FILEPATH,t.ISPUBLIC,t.OP,t.BSNO,t.ISCOMPLETE,t.REMARK,b.CUSTOMERNAME,b.ETD,b.CARRIER,b.CUSTNO "); strSql.Append(" from op_task t left join v_op_bs b on (b.BSNO=t.BSNO) "); if (!string.IsNullOrEmpty(condition)) { strSql.Append(" where " + condition); } var list = SetData(strSql); if (list.Count > 0) return list[0]; return new OpTask(); } private static List SetData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { OpTask data = new OpTask(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.TASKNO = Convert.ToString(reader["TASKNO"]); data.PTASKNO = Convert.ToString(reader["PTASKNO"]); data.TASKTYPE = Convert.ToString(reader["TASKTYPE"]); data.TASKSOURCE = Convert.ToString(reader["TASKSOURCE"]); data.TASKSTATUS = Convert.ToString(reader["TASKSTATUS"]); data.TASKTITLE = Convert.ToString(reader["TASKTITLE"]); data.TASKDESCRIP = Convert.ToString(reader["TASKDESCRIP"]); data.CREATEUSER = Convert.ToString(reader["CREATEUSER"]); data.CORPID = Convert.ToString(reader["CORPID"]); if (reader["CREATETIME"] != DBNull.Value) data.CREATETIME = Convert.ToDateTime(reader["CREATETIME"]).ToString("yyyy-MM-dd HH:mm:ss");//截港日期 if (reader["TASKBEGINDATE"] != DBNull.Value) data.TASKBEGINDATE = Convert.ToDateTime(reader["TASKBEGINDATE"]).ToString("yyyy-MM-dd HH:mm:ss");//截港日期 if (reader["COMPLETETIME"] != DBNull.Value) data.COMPLETETIME = Convert.ToDateTime(reader["COMPLETETIME"]).ToString("yyyy-MM-dd HH:mm:ss");//截港日期 data.COMPLETETYPE = Convert.ToString(reader["COMPLETETYPE"]); data.KPI = Convert.ToString(reader["KPI"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.FILENO = Convert.ToString(reader["FILENO"]); data.MAILNO = Convert.ToString(reader["MAILNO"]); data.FILEPATH = Convert.ToString(reader["FILEPATH"]); data.ISPUBLIC = Convert.ToString(reader["ISPUBLIC"]); data.OP = Convert.ToString(reader["OP"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.ISCOMPLETE = Convert.ToString(reader["ISCOMPLETE"]); data.REMARK = Convert.ToString(reader["REMARK"]); if (reader["ETD"] != DBNull.Value) data.ETD = Convert.ToDateTime(reader["ETD"]).ToString("yyyy-MM-dd");//到港日期 data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.CARRIER= Convert.ToString(reader["CARRIER"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion static public List GetTaskTreeRefList(string PARENTID, string strCondition, string userid, string usercode, string companyid) { 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 "); strSql.Append(" GID,NAME,DESCRIPTION,PARENTID,TYPE,TASTCOUNT from (SELECT GID,NAME,DESCRIPTION,PARENTID,TYPE,sum(TASTCOUNT) TASTCOUNT "); strSql.Append(" from ( select DISTINCT convert(varchar(20),isnull(ISCOMPLETE,0)) GID,(CASE WHEN ISCOMPLETE=1 THEN '已完成' ELSE '未完成' END) NAME,(CASE WHEN ISCOMPLETE=1 THEN '已完成' ELSE '未完成' END) DESCRIPTION ,'-1' PARENTID,'0' TYPE,COUNT(*) TASTCOUNT from op_task t left join v_op_bs b on (b.BSNO=t.BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where TASKSTATUS!='待挂单' and " + strCondition); } strSql.Append(" GROUP BY t.ISCOMPLETE) as z group by GID,NAME,DESCRIPTION,PARENTID,TYPE "); strSql.Append(" union select DISTINCT TASKTYPE+''+convert(varchar(20),isnull(ISCOMPLETE,0)) GID, TASKTYPE NAME, TASKTYPE DESCRIPTION,isnull(ISCOMPLETE,0) PARENTID, '1' TYPE, COUNT(*) TASTCOUNT from op_task t left join v_op_bs b on (b.BSNO=t.BSNO) "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where TASKSTATUS!='待挂单' and " + strCondition); } strSql.Append(" GROUP BY TASKTYPE, ISNULL(ISCOMPLETE,0)) as v "); strSql.Append(" where parentid='" + PARENTID + "' "); return SetUserTreeRefData(strSql); } private static List SetUserTreeRefData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { UserTreeRefModel data = new UserTreeRefModel(); #region Set DB data to Object data.id = Convert.ToString(reader["GID"]); data.NAME = Convert.ToString(reader["NAME"]); data.DESCRIPTION = Convert.ToString(reader["DESCRIPTION"]); data.PARENTID = Convert.ToString(reader["PARENTID"]); data.TYPE = Convert.ToString(reader["TYPE"]); if (reader["TASTCOUNT"] != DBNull.Value) data.TASTCOUNT =Convert.ToInt32(reader["TASTCOUNT"]); data.DESCRIPTION = data.DESCRIPTION + "(" + data.TASTCOUNT + ")"; if (data.TYPE == "1") { data.leaf = true; data.expanded = true; } else { data.leaf = false; data.expanded = true; }; #endregion headList.Add(data); } reader.Close(); } return headList; } #region 保存,删除 public static DBResult DeleteTask(List bodyList) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsert = db.GetSqlStringCommand( @"delete from op_task where GID=@GID "); if (bodyList != null) { foreach (var enumValue in bodyList) { cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@GID", DbType.String, enumValue.GID); db.ExecuteNonQuery(cmdInsert, tran); } } tran.Commit(); } catch (Exception) { tran.Rollback(); result.Success = false; result.Message = "删除出现错误,请重试或联系系统管理员"; return result; } } result.Success = true; result.Message = "删除成功" + result.Message; return result; } #endregion public static DBResult UpTransStatus(List bodyList, string transstatus,string op) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { if (bodyList != null) { var cmdInsertFee = db.GetSqlStringCommand( @"delete from ch_fee where BSNO=@BSNO AND CARGO_GID=@CARGO_GID "); foreach (var enumValue in bodyList) { if (((enumValue.TASKTYPE == "待派车") || (enumValue.TASKTYPE == "待派车(重新提交)") || (enumValue.TASKTYPE == "派车中") || (enumValue.TASKTYPE == "已派车") || (enumValue.TASKTYPE == "派车已发单")) && (transstatus == "取消任务")) { var cmdupdate = db.GetSqlStringCommand("update op_task set TASKTYPE='驳回派车',OP='',ISPUBLIC=1,ISCOMPLETE=0,COMPLETETIME=null where GID=@GID"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.GID); db.ExecuteNonQuery(cmdupdate, tran); var cmdinsertState = db.GetSqlStringCommand("update op_letter_truck set TRUCKSTATUS='待派车',ISFEE='0' where LE_ID=@LE_ID"); cmdinsertState.Parameters.Clear(); db.AddInParameter(cmdinsertState, "@LE_ID", DbType.String, enumValue.TASKNO); db.ExecuteNonQuery(cmdinsertState, tran); cmdInsertFee.Parameters.Clear(); db.AddInParameter(cmdInsertFee, "@BSNO", DbType.String, enumValue.BSNO); db.AddInParameter(cmdInsertFee, "@CARGO_GID", DbType.String, enumValue.TASKNO); db.ExecuteNonQuery(cmdInsertFee, tran); } else { var cmdupdate = db.GetSqlStringCommand("update op_task set TASKSTATUS=@TASKSTATUS where GID=@GID"); if (transstatus == "取消任务") cmdupdate = db.GetSqlStringCommand("update op_task set TASKSTATUS=@TASKSTATUS,ISCOMPLETE=1,COMPLETETYPE='人工',COMPLETETIME=GETDATE(),OP='" + op + "' where GID=@GID"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@GID", DbType.String, enumValue.GID); db.AddInParameter(cmdupdate, "@TASKSTATUS", DbType.String, transstatus); db.ExecuteNonQuery(cmdupdate, tran); var cmdinsertState = db.GetSqlStringCommand("insert into op_task_state (GID,TASKNO,TASKSTATUS,OP,OPTIME) values (newid(),@TASKNO,@TASKSTATUS,@OP,GETDATE())"); cmdinsertState.Parameters.Clear(); db.AddInParameter(cmdinsertState, "@TASKNO", DbType.String, enumValue.TASKNO); db.AddInParameter(cmdinsertState, "@TASKSTATUS", DbType.String, transstatus); db.AddInParameter(cmdinsertState, "@OP", DbType.String, op); db.ExecuteNonQuery(cmdinsertState, tran); } } } tran.Commit(); result.Success = true; result.Message = "更新完成!"; } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员"+e.Message; return result; } } return result; } public static DBResult ImpInvoice(OpTask headData, string op,string userid,string companyid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); var edifeelist = MsChFeeDAL.GetEdiDataList(" reportid='" + headData.TASKNO + "'"); if (edifeelist.Count == 0) { result.Success = false; result.Message = result.Message + " 提单号:" + headData.MBLNO + " 没有需要引入的费用!"; return result; } var BSNO = T_ALL_DA.GetStrSQL("BSNO", "select BSNO from V_OP_BS where FEESTATUS=0 AND BSNO='" + headData.BSNO + "'"); if (BSNO == "") { result.Success = false; result.Message= result.Message+ " 提单号:" + headData.MBLNO+ " 无法导入,请确认提单号正确并未费用封账!"; return result; } var FEECOUNT = T_ALL_DA.GetStrSQL("FEECOUNT", "select COUNT(*) FEECOUNT from CH_FEE where F_NO='" +edifeelist[0].InvoiceNum + "' and isnull(SETTLEMENT,0)<>0 and isnull(INVOICE,0)<>0 and isnull(ORDERAMOUNT,0)<>0 and isnull(ORDERINVOICE,0)<>0 "); if (FEECOUNT != "0") { result.Success = false; result.Message = result.Message + " 提单号:" + headData.MBLNO + " 已经导入,不能重复导入,请手动处理!"; return result; } if (edifeelist[0].INPUTMODE != "更正发票") { var FEECOUNT2 = T_ALL_DA.GetStrSQL("FEECOUNT2", "select COUNT(*) FEECOUNT2 from CH_FEE where F_NO='" + edifeelist[0].InvoiceNum + "' "); if (FEECOUNT2 != "0") { result.Success = false; result.Message = result.Message + " 提单号:" + headData.MBLNO + " 已经导入,不能重复导入,请手动处理!"; return result; } } var feecurrlist = MsChFeeDAL.GetFeeDateCurrList("op_Seae", headData.BSNO, userid, companyid); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmddelete = db.GetSqlStringCommand("delete from ch_fee where F_NO=@F_NO and BSNO=@BSNO"); cmddelete.Parameters.Clear(); db.AddInParameter(cmddelete, "@F_NO", DbType.String, edifeelist[0].InvoiceNum); db.AddInParameter(cmddelete, "@BSNO", DbType.String, headData.BSNO); db.ExecuteNonQuery(cmddelete, tran); var cmdInsert = db.GetSqlStringCommand( @"INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT, TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,INPUTMODE,F_NO) VALUES (@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency, @exchange_rate,@reason,@remark,@comm_rate,@enter_operator,@enter_date,@is_open,@is_advance_pay,@sort,@fee_status,@fee_frt, @taxrate,@notaxamount,@acctaxrate,@LINENUM,@taxunit_price,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@INPUTMODE,@F_NO) "); foreach (var enumValue in edifeelist) { var exchangerate = enumValue.ExChangerate; if (enumValue.Currency != "RMB" && exchangerate == 1) { foreach (var enumcurr in feecurrlist) { if (enumcurr.CURR == enumValue.Currency) exchangerate = enumcurr.CRDEFRATE; } } cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@gid", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@bsno", DbType.String, headData.BSNO); db.AddInParameter(cmdInsert, "@fee_type", DbType.Int16, 2); db.AddInParameter(cmdInsert, "@fee_name", DbType.String, enumValue.FeeName); db.AddInParameter(cmdInsert, "@customer_type", DbType.String,enumValue.CustomerType); db.AddInParameter(cmdInsert, "@customer_name", DbType.String, enumValue.CustomerName); db.AddInParameter(cmdInsert, "@unit", DbType.String, enumValue.Unit); db.AddInParameter(cmdInsert, "@unit_price", DbType.Decimal, enumValue.UnitPrice); db.AddInParameter(cmdInsert, "@fee_description", DbType.String, enumValue.FeeDescription); db.AddInParameter(cmdInsert, "@quantity", DbType.Decimal, 1); db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, enumValue.Amount); db.AddInParameter(cmdInsert, "@currency", DbType.String, enumValue.Currency); db.AddInParameter(cmdInsert, "@exchange_rate", DbType.Decimal, exchangerate); db.AddInParameter(cmdInsert, "@reason", DbType.String, ""); db.AddInParameter(cmdInsert, "@remark", DbType.String, enumValue.Remark); db.AddInParameter(cmdInsert, "@comm_rate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@enter_operator", DbType.String, userid); db.AddInParameter(cmdInsert, "@enter_date", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@is_open", DbType.String, "0"); db.AddInParameter(cmdInsert, "@is_advance_pay", DbType.String, "0"); db.AddInParameter(cmdInsert, "@sort", DbType.Int16, enumValue.Sort); db.AddInParameter(cmdInsert, "@fee_status", DbType.Int16, 1); db.AddInParameter(cmdInsert, "@fee_frt", DbType.String, ""); db.AddInParameter(cmdInsert, "@taxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, enumValue.NoTaxAmount); db.AddInParameter(cmdInsert, "@acctaxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@LINENUM", DbType.Int16, enumValue.Sort); db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, enumValue.Amount); db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@WMSOUTBSNO", DbType.String, ""); db.AddInParameter(cmdInsert, "@PREAMOUNT", DbType.Decimal,0); db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "EDI引入"); db.AddInParameter(cmdInsert, "@F_NO", DbType.String, enumValue.InvoiceNum); db.ExecuteNonQuery(cmdInsert, tran); } var cmdupdate = db.GetSqlStringCommand("update op_task set TASKSTATUS=@TASKSTATUS,ISCOMPLETE=1,COMPLETETYPE='人工',COMPLETETIME=GETDATE(),OP='" + op + "' where GID=@GID"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@GID", DbType.String, headData.GID); db.AddInParameter(cmdupdate, "@TASKSTATUS", DbType.String,"已引入"); db.ExecuteNonQuery(cmdupdate, tran); var cmdinsertState = db.GetSqlStringCommand("insert into op_task_state (GID,TASKNO,TASKSTATUS,OP,OPTIME) values (newid(),@TASKNO,@TASKSTATUS,@OP,GETDATE())"); cmdinsertState.Parameters.Clear(); db.AddInParameter(cmdinsertState, "@TASKNO", DbType.String, headData.TASKNO); db.AddInParameter(cmdinsertState, "@TASKSTATUS", DbType.String,"已引入"); db.AddInParameter(cmdinsertState, "@OP", DbType.String,op); db.ExecuteNonQuery(cmdinsertState, tran); tran.Commit(); result.Success = true; result.Message = "更新完成!"; } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员" + e.Message; return result; } } return result; } static public string GETFEENAME(string FEECODE) { var strSql = new StringBuilder(); strSql.Append("select top 1 [FEENAME] from code_fee_edi where [FEEENAME]='" + FEECODE + "' and isnull(EDINAME,'')=''"); var FEENAME = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { FEENAME = Convert.ToString(reader["FEENAME"]); } reader.Close(); } if (string.IsNullOrEmpty(FEENAME)) { FEENAME = FEECODE; } return FEENAME; } static public string GetCustEDICode(string EDICODE) { string CUST = ""; var strSql = new StringBuilder(); strSql.Append("select CUST from code_cust_edi where EDICODE='" + EDICODE + "'"); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { CUST = Convert.ToString(reader["CUST"]).Trim(); } reader.Close(); } if (CUST.Trim() == "") { var strSql2 = new StringBuilder(); strSql2.Append("select SHORTNAME from info_client WHERE EDICODE='" + EDICODE + "'"); db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql2.ToString())) { while (reader.Read()) { CUST = Convert.ToString(reader["SHORTNAME"]).Trim(); } reader.Close(); } } return CUST; } public static DBResult ImpOrderFee(OpTask headData, string op, string userid, string companyid) { var result = new DBResult(); Database db = DatabaseFactory.CreateDatabase(); T_ALL_DA T_ALL_DA = new EntityDA.T_ALL_DA(); var edifeelist = MsChFeeDAL.GetOrderDataList(" BSNO='" + headData.TASKNO + "'"); if (edifeelist.Count == 0) { result.Success = false; result.Message = result.Message + " 提单号:" + headData.MBLNO + " 没有需要引入的费用!"; return result; } var BSNO = headData.BSNO; if (!String.IsNullOrEmpty(headData.BSNO)) { BSNO = T_ALL_DA.GetStrSQL("BSNO", "select BSNO from V_OP_BS where FEESTATUS=0 AND BSNO='" + headData.BSNO + "'"); if (BSNO == "") { BSNO = T_ALL_DA.GetStrSQL("BSNO", "select BSNO from V_OP_BILL where FEESTATUS=0 AND PARENTID='" + headData.BSNO + "'"); if (BSNO == "") { result.Success = false; result.Message = result.Message + " 提单号:" + headData.MBLNO + " 无法导入,请确认提单号正确并未费用封账!"; return result; } } } else { if (!String.IsNullOrEmpty(headData.MBLNO)) { BSNO = T_ALL_DA.GetStrSQL("BSNO", "select BSNO from V_OP_BS where FEESTATUS=0 AND MBLNO='" + headData.MBLNO + "'"); if (BSNO == "") { BSNO = T_ALL_DA.GetStrSQL("BSNO", "select TOP 1 BSNO from V_OP_BILL where FEESTATUS=0 AND MBLNO='" + headData.MBLNO + "' ORDER BY CREATETIME "); if (BSNO == "") { result.Success = false; result.Message = result.Message + " 提单号:" + headData.MBLNO + " 无法导入,请确认提单号正确并未费用封账!"; return result; } } } } //var FEECOUNT = T_ALL_DA.GetStrSQL("FEECOUNT", "select COUNT(*) FEECOUNT from CH_FEE where F_NO='" + edifeelist[0].InvoiceNum + "' and isnull(SETTLEMENT,0)<>0 and isnull(INVOICE,0)<>0 and isnull(ORDERAMOUNT,0)<>0 and isnull(ORDERINVOICE,0)<>0 "); //if (FEECOUNT != "0") //{ // result.Success = false; // result.Message = result.Message + " 提单号:" + headData.MBLNO + " 已经导入,不能重复导入,请手动处理!"; // return result; //} var feecurrlist = MsChFeeDAL.GetFeeDateCurrList("op_Seae", headData.BSNO, userid, companyid); using (var conn = db.CreateConnection()) { conn.Open(); var tran = conn.BeginTransaction(); try { var cmdInsert = db.GetSqlStringCommand( @"INSERT INTO ch_fee(GID, BSNO, FEETYPE, FEENAME, FEEDESCRIPTION, CUSTOMERTYPE, CUSTOMERNAME, UNIT, UNITPRICE, QUANTITY, AMOUNT, CURRENCY, EXCHANGERATE, REASON, REMARK, COMMISSIONRATE,ENTEROPERATOR, ENTERDATE,ISOPEN, ISADVANCEDPAY, SORT, FEESTATUS, FEEFRT, TAXRATE,NOTAXAMOUNT,ACCTAXRATE,LINENUM,TAXUNITPRICE,MODIFIEDUSER,MODIFIEDTIME,WMSOUTBSNO,PREAMOUNT,INPUTMODE,F_NO) VALUES (@gid,@bsno,@fee_type,@fee_name,@fee_description,@customer_type,@customer_name,@unit,@unit_price,@quantity,@amount,@currency, @exchange_rate,@reason,@remark,@comm_rate,@enter_operator,@enter_date,@is_open,@is_advance_pay,@sort,@fee_status,@fee_frt, @taxrate,@notaxamount,@acctaxrate,@LINENUM,@taxunit_price,@MODIFIEDUSER,@MODIFIEDTIME,@WMSOUTBSNO,@PREAMOUNT,@INPUTMODE,@F_NO) "); foreach (var enumValue in edifeelist) { var exchangerate = enumValue.ExChangerate; if (enumValue.Currency != "RMB" && exchangerate == 1) { foreach (var enumcurr in feecurrlist) { if (enumcurr.CURR == enumValue.Currency) exchangerate = enumcurr.CRDEFRATE; } } cmdInsert.Parameters.Clear(); db.AddInParameter(cmdInsert, "@gid", DbType.String, Guid.NewGuid().ToString()); db.AddInParameter(cmdInsert, "@bsno", DbType.String, BSNO); db.AddInParameter(cmdInsert, "@fee_type", DbType.Int16, 2); db.AddInParameter(cmdInsert, "@fee_name", DbType.String, GETFEENAME(enumValue.FeeDescription)); db.AddInParameter(cmdInsert, "@customer_type", DbType.String, enumValue.CustomerType); db.AddInParameter(cmdInsert, "@customer_name", DbType.String, GetCustEDICode(enumValue.CustomerName)); db.AddInParameter(cmdInsert, "@unit", DbType.String, enumValue.Unit); db.AddInParameter(cmdInsert, "@unit_price", DbType.Decimal, enumValue.UnitPrice); db.AddInParameter(cmdInsert, "@fee_description", DbType.String, enumValue.FeeDescription); db.AddInParameter(cmdInsert, "@quantity", DbType.Decimal, 1); db.AddInParameter(cmdInsert, "@amount", DbType.Decimal, enumValue.Amount); db.AddInParameter(cmdInsert, "@currency", DbType.String, enumValue.Currency); db.AddInParameter(cmdInsert, "@exchange_rate", DbType.Decimal, exchangerate); db.AddInParameter(cmdInsert, "@reason", DbType.String, ""); db.AddInParameter(cmdInsert, "@remark", DbType.String, enumValue.Remark); db.AddInParameter(cmdInsert, "@comm_rate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@enter_operator", DbType.String, userid); db.AddInParameter(cmdInsert, "@enter_date", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@is_open", DbType.String, "0"); db.AddInParameter(cmdInsert, "@is_advance_pay", DbType.String, "0"); db.AddInParameter(cmdInsert, "@sort", DbType.Int16, enumValue.Sort); db.AddInParameter(cmdInsert, "@fee_status", DbType.Int16, 1); db.AddInParameter(cmdInsert, "@fee_frt", DbType.String, ""); db.AddInParameter(cmdInsert, "@taxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@notaxamount", DbType.Decimal, enumValue.NoTaxAmount); db.AddInParameter(cmdInsert, "@acctaxrate", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@LINENUM", DbType.Int16, enumValue.Sort); db.AddInParameter(cmdInsert, "@taxunit_price", DbType.Decimal, enumValue.Amount); db.AddInParameter(cmdInsert, "@MODIFIEDUSER", DbType.String, userid); db.AddInParameter(cmdInsert, "@MODIFIEDTIME", DbType.String, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); db.AddInParameter(cmdInsert, "@WMSOUTBSNO", DbType.String,headData.TASKNO); db.AddInParameter(cmdInsert, "@PREAMOUNT", DbType.Decimal, 0); db.AddInParameter(cmdInsert, "@INPUTMODE", DbType.String, "EDI引入"); db.AddInParameter(cmdInsert, "@F_NO", DbType.String, enumValue.InvoiceNum); db.ExecuteNonQuery(cmdInsert, tran); } var cmdupdate = db.GetSqlStringCommand("update op_task set TASKSTATUS=@TASKSTATUS,ISCOMPLETE=1,COMPLETETYPE='人工',COMPLETETIME=GETDATE(),OP='" + op + "',BSNO='"+BSNO+"' where GID=@GID"); cmdupdate.Parameters.Clear(); db.AddInParameter(cmdupdate, "@GID", DbType.String, headData.GID); db.AddInParameter(cmdupdate, "@TASKSTATUS", DbType.String, "已引入"); db.ExecuteNonQuery(cmdupdate, tran); var cmdinsertState = db.GetSqlStringCommand("insert into op_task_state (GID,TASKNO,TASKSTATUS,OP,OPTIME) values (newid(),@TASKNO,@TASKSTATUS,@OP,GETDATE())"); cmdinsertState.Parameters.Clear(); db.AddInParameter(cmdinsertState, "@TASKNO", DbType.String, headData.TASKNO); db.AddInParameter(cmdinsertState, "@TASKSTATUS", DbType.String, "已引入"); db.AddInParameter(cmdinsertState, "@OP", DbType.String, op); db.ExecuteNonQuery(cmdinsertState, tran); tran.Commit(); result.Success = true; result.Message = "更新完成!"; } catch (Exception e) { tran.Rollback(); result.Success = false; result.Message = "更新出现错误,请重试或联系系统管理员" + e.Message; return result; } } return result; } public static DBResult GetBcRemark(OpTask headData) { var result = new DBResult(); var strSql = new StringBuilder(); strSql.Append("SELECT top 1 m.F_Remark,m.F_HYH,(select top 1 F_EXT_IsMatchBusiRemark from op_seae_edi_rp_iftmbc where F_Base_ReportID='"+headData.FILENO+"' ) F_EXT_IsMatchBusiRemark,"); strSql.Append(" (select top 1 CONTRACTNO from op_seae where BSNO='"+headData.BSNO+ "') CONTRACTNO FROM op_seae_edi_mail_bcinfo m where F_Base_MailID='"+headData.MAILNO+"'"); var yhstr = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { if (Convert.ToString(reader["F_Remark"]).Trim() != "") result.Message = result.Message + Convert.ToString(reader["F_Remark"]); if (Convert.ToString(reader["F_HYH"]).Trim() != Convert.ToString(reader["CONTRACTNO"]).Trim()) yhstr= "约号(合同号)与业务系统运费协议号不一致:" + Convert.ToString(reader["F_HYH"]).Trim() + "--" + Convert.ToString(reader["CONTRACTNO"]).Trim(); if (Convert.ToString(reader["F_EXT_IsMatchBusiRemark"]).Trim() != ""&& Convert.ToString(reader["F_EXT_IsMatchBusiRemark"]) != "匹配BC报文无异常") { if (yhstr != "") result.Message = result.Message + " " + yhstr; result.Message = result.Message + " "+ Convert.ToString(reader["F_EXT_IsMatchBusiRemark"]); } else { if (yhstr != "") result.Message = result.Message + " "+yhstr; result.Message = result.Message ; } } reader.Close(); } result.Success = true; return result; } static public List GetTaskFieldValueDataList(string strCondition) { var strSql = new StringBuilder(); strSql.Append("SELECT "); strSql.Append("*"); strSql.Append(" from op_task_fieldvalue "); if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" where " + strCondition); } strSql.Append(" order by OPDATE "); return SetTaskFieldValueData(strSql); } private static List SetTaskFieldValueData(StringBuilder strSql) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { OpTaskFieldValue data = new OpTaskFieldValue(); #region Set DB data to Object data.GID = Convert.ToString(reader["plfield_id"]); data.TASKNO = Convert.ToString(reader["TASKNO"]); data.FEILDNAME = Convert.ToString(reader["FEILDNAME"]); data.FEILDVALUE = Convert.ToString(reader["FEILDVALUE"]); if (reader["OPDATE"] != DBNull.Value) data.OPDATE = Convert.ToDateTime(reader["OPDATE"]).ToString("yyyy-MM-dd HH:mm:ss"); #endregion headList.Add(data); } reader.Close(); } return headList; } #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"); strSql.Append(" from VW_User_Authority"); strSql.Append(" where [NAME]='modOpTask' and USERID='" + userid + "' and ISDELETE=0"); string visiblerange = "4"; string operaterange = "4"; 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"]); break; } reader.Close(); } if (visiblerange == "4") { str = " (t.OP='" + username + "' or t.ISPUBLIC=1 or t.CREATEUSER='"+username+"') "; } else if (visiblerange == "3") { str = " (t.OP='" + username + "' or t.ISPUBLIC=1 or t.CREATEUSER='" + username + "') "; } else if (visiblerange == "2") { var rangeDa = new RangeDA(); var deptname = rangeDa.GetDEPTNAME(userid); str = " (t.ISPUBLIC=1 or t.OP 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 t.CREATEUSER='" + username + "') "; } else if (visiblerange == "1") { str = " (t.ISPUBLIC=1 or t.OP in (select showname from [user] where GID in (select USERID from user_company where COMPANYID='" + companyid + "')) or t.CREATEUSER='" + username + "') "; } else if (visiblerange == "0") { str = " 1=1 "; } return str; } #endregion #region 参照部分 #endregion } }