using System; using System.Data; using System.Data.Common; using System.Collections.Generic; using System.Text; using DSWeb.Areas.Import.Models.ReceiptIO; using DSWeb.Areas.OA.Models.Baoxiao; using DSWeb.Areas.OA.Models.Comm; using Microsoft.Practices.EnterpriseLibrary.Data; using HcUtility.Comm; using DSWeb.Areas.CommMng.DAL; using DSWeb.EntityDA; namespace DSWeb.Areas.Import.DAL.ReceiptIO { public partial class ReceiptIODAL { #region 快递列表 //报销单列表 static public List GetDataList ( string strCondition,string USERID ) { var strSql = new StringBuilder(); strSql.Append(" select GID,TRANCNO,CORPID,DEPTGID,OP,RecvCompany,RecvName "); strSql.Append(" ,convert(varchar,createtime,20) CREATETIME "); //strSql.Append(" ,dbo.trimdate(createtime) CREATETIME "); strSql.Append(" ,REMARK,IOTYPE,case IOTYPE when 1 then '收' else '发' end IOTYPERef "); strSql.Append(" FROM OP_Receipt_IO RI "); strSql.Append(" where isnull(isdelete,0)<>1 "); if (USERID!=""){ strSql.Append(GetRangStr(USERID)); } if (!string.IsNullOrEmpty(strCondition)) { strSql.Append(" and " + strCondition); } return SetData(strSql); } public static string GetRangStr ( string userid ) { string str = ""; var strSql = new StringBuilder(); strSql.Append("SELECT VISIBLERANGE,OPERATERANGE from VW_User_Authority where [NAME]='modOpReceiptManagement' 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(); } var rangeDa = new RangeDA(); if (visiblerange == "4") { str = " and OP=(select SHOWNAME from [user] where GID='" + userid + "')"; } else if (visiblerange == "3") { var companyid = rangeDa.GetCORPID(userid); var deptname = rangeDa.GetDEPTNAME(userid); str = " and OP in(select SHOWNAME from [vw_user] where DEPTNAME='" + deptname + "' and companyid='" + companyid + "')"; } else if (visiblerange == "2") { var companyid = rangeDa.GetCORPID(userid); //var deptname = rangeDa.GetDEPTNAME(userid); str = " and OP in(select SHOWNAME from [vw_user] where companyid='" + companyid + "')"; } else if (visiblerange == "1") { var companyid = rangeDa.GetCORPID(userid); str = " "; } else { str = " "; } return str; } static public ReceiptIOmb GetData ( string condition ) { var list = GetDataList(condition,""); if (list.Count > 0) return list[0]; return new ReceiptIOmb(); } 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()) { ReceiptIOmb data = new ReceiptIOmb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.TRANCNO = Convert.ToString(reader["TRANCNO"]); data.CORPID = Convert.ToString(reader["CORPID"]); data.DEPTGID = Convert.ToString(reader["DEPTGID"]); data.OP = Convert.ToString(reader["OP"]); data.CREATETIME = Convert.ToString(reader["CREATETIME"]); data.REMARK = Convert.ToString(reader["REMARK"]); data.IOTYPE = Convert.ToString(reader["IOTYPE"]); data.IOTYPERef = Convert.ToString(reader["IOTYPERef"]); data.RecvCompany = Convert.ToString(reader["RecvCompany"]); data.RecvName = Convert.ToString(reader["RecvName"]); //data.Remark = Convert.ToString(reader["Remark"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #endregion #region 查询快递内单据数据 static public List GetBodyList ( string strCondition ) { var strSql = new StringBuilder(); strSql.Append(" SELECT B.SEQUENCE,b.GID,b.IO_GID,b.BSNO,(select Custno from v_op_bs where BSNO=B.bsno) CUSTNO "); strSql.Append(" ,vb.MBLNO,vb.HBLNO,vb.CUSTOMERNAME ,Receipt_GID,ReceiptName,NeedType "); strSql.Append(" ,case (select oplb from v_op_bs where bsno=b.BSNO) when 'import_main' then (select receiptremark from import_main where contractno=b.bsno) else '' end remark "); strSql.Append(" ,(select oplb from v_op_bs where bsno=b.BSNO) OPLB "); strSql.Append(" ,vb.PORTDISCHARGE,vb.HBLNO "); strSql.Append(" ,case (select oplb from v_op_bs where bsno=b.BSNO) when 'import_main' then (select BillType from import_main where contractno=b.bsno) else '' end BillType "); strSql.Append(" ,case (select oplb from v_op_bs where bsno=b.BSNO) when 'import_main' then (select (select EnumValueName from tSysEnumValue where LangId=0 and EnumTypeID=6 and EnumValueID=BillType) from import_main where contractno=b.bsno) else '' end BillTypeREF "); strSql.Append(" ,case (select oplb from v_op_bs where bsno=b.BSNO) when 'import_main' then (select dbo.trimdate(ArrivalDate) from import_main where contractno=b.bsno) else '' end ArrivalDate "); strSql.Append(" ,vb.OP "); strSql.Append(" from op_Receipt_IO_Body B "); strSql.Append(" left join v_op_bs vb on vb.BSNO=b.bsno "); if (strCondition.Trim() != String.Empty) { strSql.Append(" where " + strCondition); } strSql.Append(" order by SEQUENCE "); return SetBodyData(strSql); } private static List SetBodyData ( StringBuilder strSql ) { var bodyList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { ReceiptIOBodymb data = new ReceiptIOBodymb(); #region Set DB data to Object data.GID = Convert.ToString(reader["GID"]); data.SEQUENCE = Convert.ToString(reader["SEQUENCE"]); data.IO_GID = Convert.ToString(reader["IO_GID"]); data.ReceiptName = Convert.ToString(reader["ReceiptName"]); data.NeedType = Convert.ToString(reader["NeedType"]); data.BSNO = Convert.ToString(reader["BSNO"]); data.Receipt_GID = Convert.ToString(reader["Receipt_GID"]); data.CUSTNO = Convert.ToString(reader["CUSTNO"]); data.MBLNO = Convert.ToString(reader["MBLNO"]); data.HBLNO = Convert.ToString(reader["HBLNO"]); data.Remark = Convert.ToString(reader["Remark"]); data.OPLB = Convert.ToString(reader["OPLB"]); data.CUSTOMERNAME = Convert.ToString(reader["CUSTOMERNAME"]); data.PORTDISCHARGE = Convert.ToString(reader["PORTDISCHARGE"]); //data.HBLNO = Convert.ToString(reader["HBLNO"]); data.BillType = Convert.ToString(reader["BillType"]); data.BillTypeREF = Convert.ToString(reader["BillTypeREF"]); data.ArrivalDate = Convert.ToString(reader["ArrivalDate"]); data.OP = Convert.ToString(reader["OP"]); #endregion bodyList.Add(data); } reader.Close(); } return bodyList; } #endregion #region 删除快递单下的明细 static public int DELBody ( string GID ) { var strSql = new StringBuilder(); strSql.Append(" delete from OP_Receipt_IO_Body where IO_GID =( '" + GID + "')"); var _count = 0; Database db = DatabaseFactory.CreateDatabase(); _count = db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); return _count; } #endregion #region 查询快递单明细看是否有重复 static public int SearchBody(ReceiptIOBodymb Body) { var strSql = new StringBuilder(); strSql.Append(" select count(*) _count from OP_Receipt_IO_Body where BSNO='" + Body.BSNO + "' and ReceiptName='" + Body.ReceiptName + "' and Needtype='" + Body.NeedType + "'" ); if (Body.GID != "") { strSql.Append(" and GID<>'" + Body.GID + "'"); } var _count = 0; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { _count = Convert.ToInt16(reader["_count"]); } reader.Close(); } return _count; } #endregion #region 处理明细 //增加 修改 static public int WriteBody(List BodyList, string UserID, ReceiptIOmb head) { var strSql = new StringBuilder(); var _count = 0; foreach (var Body in BodyList){ var GID = SearchReceipt(Body); if (GID == "") { GID = Guid.NewGuid().ToString(); strSql.Append(" INSERT INTO [op_receipt] "); strSql.Append(" ([GID],[BSNO],[RECEIPTNO],[RECEIPTTYPE],[RECEIVE_MAN],[RECEIVE_DATE],[SEND_MAN],[SEND_DATE] "); strSql.Append(" ,[TRANCER],[TRANCNO],[ISREPEAT],[REPEAT_MAN],[REPEAT_DATE],[ISRECEIVE] "); strSql.Append(" ,[RETURN_MAN],[RETURN_DATE],[RETURN_TRANCER],[RETURN_TRANCNO] "); strSql.Append(" ,[REMARK],[CORPID],[CREATEUSER],[CREATETIME],[MODIFIEDUSER],[MODIFIEDTIME]) "); strSql.Append(" VALUES "); strSql.Append(" ('" + GID + "','" + Body.BSNO + "','','" + Body.ReceiptName + "','','','','' "); strSql.Append(" ,'','" + head.TRANCNO + "','','','','' "); strSql.Append(" ,'','','','' "); strSql.Append(" ,'',(select companyid from vw_user where userid='" + UserID + "'),'" + UserID + "',getdate(),'" + UserID + "',getdate()) "); } if (Body.NeedType == "接单") { strSql.Append(" Update op_receipt set RECEIVE_TRANCNO='" + head.TRANCNO + "' , RECEIVE_MAN='" + head.OP + "', RECEIVE_DATE='" + head.CREATETIME + "' "); strSql.Append(" ,MODIFIEDUSER='" + UserID + "',MODIFIEDTIME=getdate() where GID='" + GID + "' "); } if (Body.NeedType == "送单") { strSql.Append(" Update op_receipt set Trancno='" + head.TRANCNO + "' , SEND_MAN='" + head.OP + "', SEND_DATE='" + head.CREATETIME + "' "); strSql.Append(" ,MODIFIEDUSER='" + UserID + "',MODIFIEDTIME=getdate() where GID='" + GID + "' "); } if (Body.NeedType == "回单") { strSql.Append(" Update op_receipt set REPEAT_TRANCNO='" + head.TRANCNO + "' , REPEAT_MAN='" + head.OP + "', REPEAT_DATE='" + head.CREATETIME + "' "); strSql.Append(" ,MODIFIEDUSER='" + UserID + "',MODIFIEDTIME=getdate() where GID='" + GID + "' "); } if (Body.NeedType == "还单") { strSql.Append(" Update op_receipt set RETURN_TRANCNO='" + head.TRANCNO + "' , RETURN_MAN='" + head.OP + "', RETURN_DATE='" + head.CREATETIME + "' "); strSql.Append(" ,MODIFIEDUSER='" + UserID + "',MODIFIEDTIME=getdate() where GID='" + GID + "' "); } Database db = DatabaseFactory.CreateDatabase(); _count = _count+db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); strSql.Clear(); } return _count; } //删除 static public int DelBody ( List BodyList, string UserID, ReceiptIOmb head ) { var strSql = new StringBuilder(); var _count = 0; foreach (var Body in BodyList) { var GID = SearchReceipt(Body); if (GID == "") { return 0; } else { if (Body.NeedType == "接单") { strSql.Append(" Update op_receipt set RECEIVE_DATE=null,TRANCNO=replace(TRANCNO,'" + head.TRANCNO + "','') "); strSql.Append(" where BSNO='" + Body.BSNO + "' and ReceiptType='"+Body.ReceiptName+"' "); } if (Body.NeedType == "送单") { strSql.Append(" Update op_receipt set SEND_DATE=null,REMARK=replace(REMARK,' 送单快递号" + head.TRANCNO + "','')"); strSql.Append(" where BSNO='" + Body.BSNO + "' and ReceiptType='" + Body.ReceiptName + "' "); } if (Body.NeedType == "回单") { strSql.Append(" Update op_receipt set REPEAT_DATE=null,REMARK=replace(REMARK,' 回单快递号" + head.TRANCNO + "','') "); strSql.Append(" where BSNO='" + Body.BSNO + "' and ReceiptType='" + Body.ReceiptName + "' "); } if (Body.NeedType == "还单") { strSql.Append(" Update op_receipt set RETURN_DATE=null,RETURN_TRANCNO=replace(RETURN_TRANCNO,'" + head.TRANCNO + "','') "); strSql.Append(" where BSNO='" + Body.BSNO + "' and ReceiptType='" + Body.ReceiptName + "' "); } } Database db = DatabaseFactory.CreateDatabase(); _count = _count + db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); } return _count; } #endregion #region 查找是否有该种单据 static public string SearchReceipt(ReceiptIOBodymb Body) { var strSql = new StringBuilder(); strSql.Append(" select GID from OP_receipt where BSNO='" + Body.BSNO + "' and ReceiptType='" + Body.ReceiptName + "' "); /*if (Body.NeedType == "接单") { strSql.Append(" and isnull(RECEIVE_DATE,'')<>'' "); } if (Body.NeedType == "送单") { strSql.Append(" and isnull(SEND_DATE,'')<>'' "); } if (Body.NeedType == "回单") { strSql.Append(" and isnull(REPEAT_DATE,'')<>'' "); } if (Body.NeedType == "还单") { strSql.Append(" and isnull(RETURN_DATE,'')<>'' "); }*/ var GID = ""; Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { GID = Convert.ToString(reader["GID"]); } reader.Close(); } return GID; } #endregion static public List GetRemark ( string BSNO ) { var strSql = new StringBuilder(); strSql.Append(" select receiptremark Remark from import_main where Contractno='" + BSNO + "' "); //feestatus=0 and //strSql.Append(" union all "); //strSql.Append(" select bsno,CUSTNO+'_'+mblno code,mblno from op_seai "); //strSql.Append(" where feestatus=0 and inputby in (select showname from [user] where gid in(select userid from user_company where companyid='" + COMPANYID + "' )) "); //strSql.Append(" FROM OA_Baoxiao BX "); return SetDataBSNO(strSql); } private static List SetDataBSNO ( StringBuilder strSql ) { var headList = new List(); Database db = DatabaseFactory.CreateDatabase(); using (IDataReader reader = db.ExecuteReader(CommandType.Text, strSql.ToString())) { while (reader.Read()) { BSNOmb data = new BSNOmb(); #region Set DB data to Object data.Remark = Convert.ToString(reader["Remark"]); #endregion headList.Add(data); } reader.Close(); } return headList; } #region 写寄单情况 static public int InsertRemark ( List BodyList, ReceiptIOmb head ) { var strSql = new StringBuilder(); var _count = 0; foreach (var Body in BodyList) { var BSNO = Body.BSNO; var Remark = Body.Remark; var BillType = Body.BillType; if (!string.IsNullOrEmpty(Remark)) { strSql.Append(" update import_main set ReceiptRemark='" + Remark + "',BillType=" + BillType + " "); strSql.Append(" where contractno= '" + BSNO + "'"); Database db = DatabaseFactory.CreateDatabase(); if (Body.OPLB == "import_main") { _count = _count + db.ExecuteNonQuery(CommandType.Text, strSql.ToString()); } } } return _count; } #endregion } }