private static long GetPackCode() { lock (Locker) //lock 关键字可确保当一个线程位于代码的临界区时,另一个线程不会进入该临界区。 { long lastpack = 0; string date = DateTime.Now.ToString("yyyyMMdd") + "0001"; //得到当天第一个包裹号 using (var db = SugarDao.GetInstance(LoginUser.GetConstr())) { busi_sendorder send = db.SqlQuery <busi_sendorder>("select * from busi_sendorder where order_code=(select MAX(order_code) from busi_sendorder)").FirstOrDefault(); if (send == null) { return(Convert.ToInt64(date)); } if (Convert.ToInt64(send.order_code) >= Convert.ToInt64(date)) { lastpack = Convert.ToInt64(send.order_code) + 1; return(lastpack); } else { return(Convert.ToInt64(date)); } } } }
/// <summary> /// 判断扫描的包裹号在系统中是否存在且未删除 /// </summary> /// <param name="packgecode"></param> /// <returns></returns> public static int CheckPackge(string packgecode) { using (var db = SugarDao.GetInstance(Getconnstring.Getmyconnstring())) { try { busi_sendorder packge = db.Queryable <busi_sendorder>().Where(s => s.order_code == packgecode).FirstOrDefault(); if (null == packge) { return(1);//代表包裹不存在系统中 } else { busi_sendorder packge2 = db.Queryable <busi_sendorder>().Where(s => s.order_code == packgecode).Where(s => s.del_flag == true).FirstOrDefault(); if (null == packge2) { return(2); //代表包裹被删除 } else { return(3); //包裹存在,正常 } } } catch (Exception ex) { throw ex; } } }
/// <summary> /// 装箱 /// </summary> /// <param name="zhuanyuncode"></param> /// <param name="packgecode"></param> /// <returns></returns> public bool ConfirmPutInBox(string zhuanyuncode, string packgecode) { using (var db = SugarDao.GetInstance(conn)) { try { busi_transfer tran = db.Queryable <busi_transfer>().Where(s => s.tran_code == zhuanyuncode).FirstOrDefault(); if (null == tran) { throw new Exception("转运单号不存在!"); } else { //1.判断包裹是否配货完毕 busi_sendorder send = db.Queryable <busi_sendorder>().Where(s => s.order_code == packgecode).FirstOrDefault(); if (null == send) { throw new Exception("不存在此包裹"); } busi_sendorder send2 = db.Queryable <busi_sendorder>().Where(s => s.order_tatus >= 40).Where(s => s.order_code == packgecode).FirstOrDefault(); if (null == send2) { throw new Exception("包裹未配货完毕不能装箱"); } busi_sendorder send3 = db.Queryable <busi_sendorder>().Where(s => s.express_id > 0).Where(s => s.order_code == packgecode).FirstOrDefault(); if (null == send3) { throw new Exception("请先选择快递再装箱!"); } busi_sendorder send4 = db.Queryable <busi_sendorder>().Where(s => s.tran_id == 0).Where(s => s.order_code == packgecode).FirstOrDefault(); if (null == send4) { throw new Exception("包裹已装箱,请先出箱!"); } db.Update <busi_sendorder>(new { tran_id = tran.tran_id, order_tatus = 80 }, it => it.order_code == packgecode);//更新已转运状态 db.Update <busi_custorder>(new { order_status = 80 }, it => it.order_id == send.custorder_id); tran.tran_count++; bool isok2 = db.Update <busi_transfer>(tran);//更新转运单中包裹数量 return(isok2); } } catch (Exception ex) { throw ex; } } }
public int AssociateExpressCode(int expressid, DataTable csvtable) { using (var db = SugarDao.GetInstance(LoginUser.GetConstr())) { int mycount = 0; db.CommandTimeOut = 3000; //设置超时时间 try { db.BeginTran();//开启事务 //string sql = string.Format(@"", expressid); foreach (DataRow item in csvtable.Rows) { //base_expresscode Eid = db.SqlQuery<base_expresscode>("select top 1 * from base_expresscode where isuse=0 and express_id=@expressid order by Eid", new { expressid = expressid }).FirstOrDefault(); string mypackge = item["包裹号"].ToString(); string expresscode = item["快递单号"].ToString(); busi_sendorder aa = db.Queryable <busi_sendorder>().Where(s => s.order_code == mypackge).FirstOrDefault(); if (null == aa) { throw new Exception(mypackge + "此包裹号在系统中不存在,请确认"); } else if (expressid != aa.express_id) { throw new Exception("导入的快递类型和原先选择的不一致,请确认"); } else { bool isok = db.Update <busi_sendorder>(new { exp_code = expresscode }, it => it.order_code == mypackge);//如果包裹号不存在系统中也没事 if (isok) { mycount++; } } } db.CommitTran();//提交事务 return(mycount); } catch (Exception ex) { db.RollbackTran();//回滚事务 throw ex; } } }
public bool ConfirmOutofBox(string zhuanyuncode, string packgecode) { using (var db = SugarDao.GetInstance(conn)) { try { busi_transfer tran = db.Queryable <busi_transfer>().Where(s => s.tran_code == zhuanyuncode).FirstOrDefault(); if (null == tran) { throw new Exception("转运单号不存在!"); } else { //1.判断包裹是否配货完毕 busi_sendorder send = db.Queryable <busi_sendorder>().Where(s => s.order_code == packgecode).FirstOrDefault(); if (null == send) { throw new Exception("不存在此包裹"); } busi_sendorder send2 = db.Queryable <busi_sendorder>().Where(s => s.order_tatus >= 40).Where(s => s.order_code == packgecode).FirstOrDefault(); if (null == send2) { throw new Exception("包裹未配货完毕不能出箱"); } busi_sendorder send3 = db.Queryable <busi_sendorder>().Where(s => s.tran_id > 0).Where(s => s.order_code == packgecode).FirstOrDefault(); if (null == send3) { throw new Exception("包裹未装箱,请先装箱!"); } db.Update <busi_sendorder>(new { tran_id = 0 }, it => it.order_code == packgecode); tran.tran_count--; bool isok2 = db.Update <busi_transfer>(tran);//更新转运单中包裹数量 return(isok2); } } catch (Exception ex) { throw ex; } } }
/// <summary> /// 判断包裹号在系统中是否存在 /// </summary> /// <param name="packgecode"></param> /// <returns></returns> public bool IsPackgeInSys(string packgecode) { using (var db = SugarDao.GetInstance(LoginUser.GetConstr())) { try { busi_sendorder isok = db.Queryable <busi_sendorder>().Where(s => s.order_code == packgecode).FirstOrDefault(); if (null == isok) { return(false); } else { return(true); } } catch (Exception ex) { throw ex; } } }
/// <summary> /// 拆分包裹确认配货 /// </summary> /// <param name="peihuoinfo"></param> /// <param name="Userinfo"></param> /// <returns></returns> public bool DispartConfirmDistruit(RFTDistrView peihuoinfo, base_users Userinfo) { using (var db = SugarDao.GetInstance(conn)) { db.CommandTimeOut = 3000;//设置超时时间 try { db.BeginTran(); //1.先设置work_info中已配货的状态 bool isok = db.Update <busi_workinfo>(new { is_work = 1, work_type = 2, work_time = DateTime.Now, edit_user_id = Userinfo.user_id, islock = 0 }, it => it.work_id == peihuoinfo.workid); if (isok) { if (peihuoinfo.info == "可包装")//单件的,需要打印 { //1.先拆分包裹,先得到原先的包裹号 busi_sendorder oldpack = db.Queryable <busi_sendorder>().Where(s => s.order_id == peihuoinfo.packid).FirstOrDefault(); if (peihuoinfo.packgecode != GetPackCode().ToString())//再次取新的包裹号,如果不相等说明刚才的包裹号被其他地方占用了 { throw new Exception("拆分后的包裹号被占用请重新拆分"); } long oldpackid = oldpack.order_id; oldpack.prod_num--; //减少原先包裹SKU数量 db.Update <busi_sendorder>(oldpack); //先更新原先包裹SKU数量信息 oldpack.order_code = peihuoinfo.packgecode; oldpack.order_id = 0; oldpack.prod_num = 1; oldpack.order_tatus = 40; //包裹配货完成 int npackid = db.Insert <busi_sendorder>(oldpack).ObjToInt(); //插入新包裹 //判断这个包裹中是否买了多个相同的SKU long codeid = db.Queryable <base_prod_code>().Where(s => s.sku_code == peihuoinfo.skucode).FirstOrDefault().code_id;//得到skuid busi_sendorder_detail oldsenddetail = db.Queryable <busi_sendorder_detail>().Where(s1 => s1.order_id == peihuoinfo.packid).Where(s1 => s1.code_id == codeid).FirstOrDefault(); long senddetailid = 0; if (Convert.ToInt32(oldsenddetail.prod_num) > 1) //原包裹相同SKU购买多件 { oldsenddetail.prod_num--; db.Update <busi_sendorder_detail>(new { prod_num = oldsenddetail.prod_num }, it => it.detail_id == oldsenddetail.detail_id); oldsenddetail.detail_id = 0; oldsenddetail.order_id = npackid; oldsenddetail.prod_num = 1; senddetailid = db.Insert <busi_sendorder_detail>(oldsenddetail).ObjToInt(); } else if (Convert.ToInt32(oldsenddetail.prod_num) == 1)//只买了一个,直接更新这条数据 { senddetailid = oldsenddetail.detail_id; db.Update <busi_sendorder_detail>(new { order_id = npackid }, it => it.detail_id == oldsenddetail.detail_id); } db.Update <busi_workinfo>(new { packid = npackid, sendorder_detail_id = senddetailid, islock = 0 }, it => it.work_id == peihuoinfo.workid); //==================20171023添加,如果上架过,最后一个拆分包裹,检查原包裹的状态并做相应的更新=================== //1.判断已上架的数量和包裹SKU数量是否相等 int skunum = db.Queryable <busi_sendorder>().Where(s => s.order_id == oldpackid).FirstOrDefault().prod_num; var worklist = db.Queryable <busi_workinfo>().Where(s => s.packid == oldpackid && s.is_work == true && s.del_flag == true).ToList(); if (skunum == worklist.Count) { db.Update <busi_sendorder>(new { order_tatus = 40 }, it => it.order_id == peihuoinfo.packid);//原先包裹更新状态,全部配货 } else { db.Update <busi_sendorder>(new { order_tatus = 30 }, it => it.order_id == peihuoinfo.packid);//原先包裹更新状态,部分配货 } //================================================================================================ //插入打印数据 //插入打印数据,只是包裹号 busi_printwork insertinfo = new busi_printwork(); insertinfo.p_WorkType = 30; insertinfo.data_1 = peihuoinfo.packgecode; insertinfo.data_4 = DateTime.Now.ToString(); insertinfo.p_idPoint = 1; //测试 insertinfo.p_Status = 1; insertinfo.data_2 = peihuoinfo.packgecode.Substring(8, 4); insertinfo.data_3 = peihuoinfo.packnum.ToString(); db.Insert <busi_printwork>(insertinfo); //-------------------20170720减库存-------------------------------------- var depotID = db.Queryable <base_wh_warehouse>().Where(s => s.wh_name == "金华仓").FirstOrDefault(); if (null == depotID) { throw new Exception("金华仓不存在"); } var locationID = db.Queryable <base_location>().Where(s => s.wh_id == depotID.wh_id && s.locat_code == "zz-zz-zz").FirstOrDefault(); if (null == locationID) { throw new Exception("金华仓库位zz-zz-zz不存在"); } var skuid = db.Queryable <base_prod_code>().Where(s => s.sku_code == peihuoinfo.skucode).FirstOrDefault(); var stock = db.Queryable <base_wh_stock>().Where(s => s.location_id == locationID.locat_id && s.code_id == skuid.code_id).FirstOrDefault(); if (0 >= stock.stock_qty) { throw new Exception("金华仓临时库库存为零"); } stock.stock_qty--; db.Update <base_wh_stock>(stock); //--------------------------------------------------------------------------- //3.得到这个订单的所有包裹数目 int packges = db.Queryable <busi_sendorder>().Where(s => s.custorder_id == peihuoinfo.orderid).Where(s => s.del_flag == true).ToList().Count; //已配货数量 int ispackingnum = db.Queryable <busi_sendorder>().Where(s => s.custorder_id == peihuoinfo.orderid).Where(s => s.del_flag == true).Where(s => s.order_tatus >= 40).ToList().Count; if (packges == ispackingnum) { db.Update <busi_custorder>(new { order_status = 40 }, it => it.order_id == peihuoinfo.orderid); } } db.CommitTran(); return(true); } else { db.RollbackTran(); return(false); } } catch (Exception ex) { db.RollbackTran(); throw ex; } } }