public bool DeleteNo(string ErpVoucherno, string flag, ref string strError) { List <string> list = new List <string>(); try { string tablename = ""; string tabeldetail = ""; string status = ""; switch (flag) { case "入库": tablename = "T_INSTOCK"; tabeldetail = "t_instockdetail"; status = "status"; break; case "出库": tablename = "T_TASK"; tabeldetail = "T_TASKDETAILS"; status = "status"; break; case "生产": tablename = "t_product"; tabeldetail = "t_productdetail"; status = "POSTQTY"; break; } T_InStock_Func tfunc = new T_InStock_Func(); string sql = string.Format(@"select [{0}] from {1} where erpvoucherno='{2}'", status, tablename, ErpVoucherno); string istrue = GetScalarBySql(sql).ToString();//是否status等于新建 if (istrue == "1" || (flag == "生产" && Convert.ToDecimal(istrue) == 0)) { list.Add(string.Format("delete {0} where erpvoucherno='{1}'", tablename, ErpVoucherno)); list.Add(string.Format("delete {0} where erpvoucherno='{1}'", tabeldetail, ErpVoucherno)); return(base.SaveModelListBySqlToDB(list, ref strError)); } else { strError = "该订单状态不是新建,请确认"; return(false); // Json(new { state = false, obj = strError }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { return(false); } }
protected override List <string> GetSaveModelListSql(UserModel user, List <T_InStockDetailInfo> modelList) { string strSql1 = string.Empty; string strSql2 = string.Empty; string strSql3 = string.Empty; string strSql4 = string.Empty; string strSql5 = string.Empty; string strSql6 = string.Empty; string strSql7 = string.Empty; string strSql8 = string.Empty; string strSql9 = string.Empty; string strSql10 = string.Empty; string TaskNo = string.Empty; int TaskTransID = 0; if (modelList == null || modelList.Count == 0) { return(null); } if (modelList[0].VoucherType == 35) { return(null); } int taskid = base.GetTableIDBySqlServer("t_task");//GetTableID("seq_task_id"); List <string> lstSql = new List <string>(); if (modelList.Count() > 0) { //string TaskNoID = base.GetTableID("seq_task_no").ToString(); //TaskNo = "T" + System.DateTime.Now.ToString("yyyyMMdd") + TaskNoID.PadLeft(4, '0'); //string TaskNoID = base.GetTableIDBySqlServer("t_task").ToString(); TaskNo = base.GetNewOrderNo("D", "t_task", ""); modelList.ForEach(t => t.TaskNo = TaskNo); } else { modelList.ForEach(t => t.TaskNo = ""); } foreach (var item in modelList) { strSql1 = "update t_Instockdetail set Receiveqty = (isnull( Receiveqty,0) + '" + item.ScanQty + "') ," + " OPERATORUSERNO = '" + user.UserNo + "', Operatordatetime = getdate() , materialnoid = '" + item.MaterialNoID + "' where id ='" + item.ID + "'"; lstSql.Add(strSql1);// remainqty = (case when (isnull( remainqty,0) - '" + item.ScanQty + "') <= 0 then 0 else isnull( remainqty,0) - '" + item.ScanQty + "' end), strSql2 = "update t_Instockdetail set Linestatus = (case when isnull( Receiveqty,0)< isnull( Instockqty,0) and isnull( Receiveqty,0)<>0 then 2" + "when isnull( Receiveqty,0) >= isnull( Instockqty,0) then 3 end ) where id = '" + item.ID + "'"; lstSql.Add(strSql2); foreach (var itemBarCode in item.lstBarCode) { item.IsQuality = 3;//库存状态改为合格 strSql8 = "insert into t_stock(serialno,Materialno,materialdesc,qty,status,isdel,Creater,Createtime,batchno,unit,unitname,Palletno," + "islimitstock,materialnoid,warehouseid,houseid,areaid,Receivestatus,barcode,STRONGHOLDCODE,STRONGHOLDNAME,COMPANYCODE,EDATE,SUPCODE,SUPNAME," + "SUPPRDBATCH,Isquality,Stocktype,ean,BARCODETYPE,projectNo,TracNo)" + "values ('" + itemBarCode.SerialNo + "','" + itemBarCode.MaterialNo + "','" + itemBarCode.MaterialDesc + "','" + itemBarCode.Qty + "','" + item.IsQuality + "','1'" + ",'" + user.UserNo + "',getdate(),'" + itemBarCode.BatchNo + "','" + item.Unit + "','" + item.UnitName + "'" + ",(select palletno from t_Palletdetail where serialno = '" + itemBarCode.SerialNo + "'),'1','" + itemBarCode.MaterialNoID + "'" + ", '" + user.WarehouseID + "','" + user.ReceiveHouseID + "','" + user.ReceiveAreaID + "','1','" + itemBarCode.BarCode + "','" + item.StrongHoldCode + "', " + " '" + itemBarCode.StrongHoldName + "','" + itemBarCode.CompanyCode + "','" + itemBarCode.EDate + "','" + item.SupplierNo + "','" + item.SupplierName + "'," + "'" + itemBarCode.SupPrdBatch + "','3' ,'1','" + itemBarCode.EAN + "','" + itemBarCode.BarcodeType + "','" + (itemBarCode.ProjectNo == null?"": itemBarCode.ProjectNo) + "','" + (itemBarCode.TracNo == null?"": itemBarCode.TracNo) + "' )"; lstSql.Add(strSql8); TaskTransID = base.GetTableIDBySqlServerTaskTrans("t_tasktrans"); strSql10 = "SET IDENTITY_INSERT t_tasktrans on ;insert into t_tasktrans(id, Serialno,towarehouseid,Tohouseid, Toareaid, Materialno, Materialdesc, Supcuscode, " + "Supcusname, Qty, Tasktype, Vouchertype, Creater, Createtime,TaskdetailsId, Unit, Unitname,materialnoid," + "erpvoucherno,voucherno,barcode,STRONGHOLDCODE,STRONGHOLDNAME,COMPANYCODE,SUPPRDBATCH,EDATE,TASKNO,batchno,ToWarehouseNo,ToHouseNo,ToAreaNo,ToWarehouseName)" + " values ('" + TaskTransID + "','" + itemBarCode.SerialNo + "','" + user.WarehouseID + "','" + user.ReceiveHouseID + "'," + "'" + user.ReceiveAreaID + "','" + itemBarCode.MaterialNo + "','" + itemBarCode.MaterialDesc + "','" + item.SupplierNo + "','" + item.SupplierName + "'," + " '" + itemBarCode.Qty + "','4',(select vouchertype from t_Instock where voucherno = '" + item.VoucherNo + "') ,'" + user.UserName + "',getdate(),'" + item.ID + "'," + "'" + item.Unit + "','" + item.UnitName + "','" + itemBarCode.MaterialNoID + "','" + item.ErpVoucherNo + "','" + item.VoucherNo + "','" + itemBarCode.BarCode + "'," + "'" + item.StrongHoldCode + "','" + item.StrongHoldName + "','" + item.CompanyCode + "','" + itemBarCode.SupPrdBatch + "'" + " ,'" + itemBarCode.EDate + "','" + TaskNo + "','" + itemBarCode.BatchNo + "','" + user.ReceiveWareHouseNo + "','" + user.ReceiveHouseNo + "','" + user.ReceiveAreaNo + "','" + user.ReceiveWareHouseName + "') SET IDENTITY_INSERT t_tasktrans off"; lstSql.Add(strSql10); } } strSql3 = "update t_Instock set Status = 2 where id = '" + modelList[0].HeaderID + "'"; lstSql.Add(strSql3); strSql4 = " update t_Instock set Status = 3 where " + " id in(select b.Headerid from t_Instockdetail b group by b.Headerid having(max(isnull(linestatus,1)) = 3 and min(isnull(linestatus,1))=3) and b.Headerid = '" + modelList[0].HeaderID + "')" + "and id = '" + modelList[0].HeaderID + "'"; lstSql.Add(strSql4); List <T_InStockDetailInfo> NewModelList = GroupInstockDetailList(modelList); //ymh 查询单据类型 T_InStock_Func func = new T_InStock_Func(); T_InStockInfo InStockInfoModel = new T_InStockInfo() { ID = modelList[0].HeaderID }; string strmsg = ""; func.GetModelByID(ref InStockInfoModel, ref strmsg); //是否生成上架任务的配置 if (!(user.ISVWAREHOUSE == 0 && InStockInfoModel.VoucherType != 39)) { //汇总生成上架任务不汇总收货数据 foreach (var item in NewModelList) { //taskqty》QualityQty strSql6 = "insert into t_Taskdetails (headerid,Materialno,materialdesc,QualityQty,Remainqty,LineStatus,Creater,Createtime,Unit,Unitname,erpvoucherno,materialnoid,toareano,voucherno," + "STRONGHOLDCODE,STRONGHOLDNAME,COMPANYCODE,batchno,Productbatch,Supprdbatch,Frombatchno,Fromerpareano,Fromerpwarehouse,isdel,iarrsid)" + "values('" + taskid + "','" + item.MaterialNo + "','" + item.MaterialDesc + "','" + item.ScanQty + "','" + item.ScanQty + "'," + "'1','" + user.UserNo + "',getdate(),'" + item.Unit + "','" + item.UnitName + "','" + item.ErpVoucherNo + "','" + item.MaterialNoID + "','" + user.ReceiveAreaID + "','" + item.VoucherNo + "'," + "'" + item.StrongHoldCode + "','" + item.StrongHoldName + "','" + item.CompanyCode + "','" + item.BatchNo + "'," + "'" + item.ProductBatch + "','" + item.SupPrdBatch + "'," + "'" + item.BatchNo + "','" + user.ReceiveAreaNo + "','" + user.ReceiveWareHouseNo + "','1','" + modelList[0].iarrsid + "')"; lstSql.Add(strSql6); } if (NewModelList != null && NewModelList.Count() > 0) { //ymh到货单特殊处理,其他单据不过帐:Vouchertype strSql5 = "set IDENTITY_INSERT t_task on;insert into t_task (id,Vouchertype,tasktype,Taskno,Supcusname,status,Taskissued,Receiveuserno,Createtime,supcuscode,Creater,InStockID," + "erpvoucherno,plant,plantname,movetype,Taskissueduser,voucherno,STRONGHOLDCODE,STRONGHOLDNAME,COMPANYCODE,ERPCREATER,VOUDATE,VOUUSER,ERPSTATUS,ERPNOTE,erpinvoucherno,WAREHOUSEID,erpvouchertype,isdel)" + "select '" + taskid + "', case Vouchertype when 39 then 39 else 888 end as Vouchertype,'1','" + TaskNo + "', Suppliername , '1',getdate(),'" + user.UserNo + "',getdate(), Supplierno,'" + user.UserNo + "', Id," + " Erpvoucherno, Plant, Plantname, Movetype,'" + user.UserNo + "',voucherno,STRONGHOLDCODE,STRONGHOLDNAME,COMPANYCODE,ERPCREATER,VOUDATE,VOUUSER,ERPSTATUS,ERPNOTE,'" + NewModelList[0].MaterialDoc + "'" + " ,'" + user.WarehouseID + "','" + modelList[0].ERPVoucherType + "','1' from t_Instock a where id = '" + modelList[0].HeaderID + "' set IDENTITY_INSERT t_task off;"; lstSql.Add(strSql5); } } return(lstSql); }