/// <summary> /// 拣选单打印 /// </summary> /// <param name="Sender"></param> /// <param name="e"></param> private void Timerselect_Tick(object Sender, EventArgs e) { int worktype = 20; int p_id = GetprintID(); //得到打印插件ID busi_printwork list = CommPrint.GetOneprintInfo(p_id, worktype); if (null != list) //说明有数据 { List <busi_printwork> allselect = CommPrint.GetSelectPackgeList(p_id, worktype, list.data_1); //取出这个包裹号所有SKU信息 List <Myselect> myselectlist = new List <Myselect>(); foreach (var item in allselect) { Myselect p = new Myselect(); p.ID1 = item.p_Workid.ObjToInt(); p.Packgecode = item.data_1; p.Position = item.data_4; p.Number = item.data_3; p.Skus = item.data_2; p.Remarks1 = item.data_5; myselectlist.Add(p); } JXpackge pack = new JXpackge(); pack.selectlist = myselectlist; pack.packgecode = list.data_1; //将此包裹设为中间状态,防止多次取值 int a = SQLHelper.ExecuteSql("update busi_printwork set p_Status=10 where p_WorkType=20 and data_1=" + "'" + list.data_1 + "'"); if (a < 0) { Log("打印拣选设置中间状态出错!包裹号:" + list.data_1); } if (!QueueSelect.Contains(pack)) { QueueSelect.Enqueue(pack); } label9.Text = QueueSelect.Count.ToString(); //队列显示未打印数量 #region 满足打印个数条件打印,不然等待队列满足条件,或者人为手动清空队列打印 try { if (QueueSelect.Count == 14) //队列中数据大于14个包裹,直接打印 { for (int m = 0; m < 14; m++) { //List<JXpackge> ss=QueueSelect.Take<JXpackge>(14); JXpackge s = QueueSelect.Dequeue(); //出队列 Printselect.mylist = Printselect.mylist.Union(s.selectlist).ToList <Myselect>(); //放入打印list中 CommPrint.FinshSelectPrint(p_id, s.packgecode); } Printselect.Print(false); //打印 Printselect.mylist.Clear(); //移除所有元素 } label9.Text = QueueSelect.Count.ToString(); //队列显示未打印数量 } catch (Exception ex) { Log(ex.ToString()); } #endregion } }
/// <summary> /// 得到打印包裹信息(面单上) /// </summary> /// <param name="packge"></param> /// <returns></returns> public static packgeInfoViewModel GetPrintpackge(busi_printwork packge) { using (var db = SugarDao.GetInstance(Getconnstring.Getmyconnstring())) { try { packgeInfoViewModel aa=db.Queryable<busi_custorder>().JoinTable<busi_sendorder>((s1, s2) => s1.order_id == s2.custorder_id) .JoinTable<base_shop>((s1, s3) => s1.shop_id == s3.shop_id) .JoinTable<busi_printwork>((s2, s4) => s2.order_code == s4.data_1) .Where<busi_sendorder>((s1, s2) => s2.order_code == packge.data_1) .Select<busi_sendorder, base_shop, busi_printwork,packgeInfoViewModel>((s1, s2, s3,s4) => new packgeInfoViewModel() { LastTime=s1.latest_date.ObjToString(), Number=s2.prod_num.ObjToString(), Packgecode=s2.order_code, ShopName=s3.shop_name, workID=s4.p_Workid.ObjToInt() }).FirstOrDefault(); return aa; } catch (Exception ex) { throw ex; } } }
public static Myamato GetPrintyamato(busi_printwork packge) { using (var db = SugarDao.GetInstance(Getconnstring.Getmyconnstring())) { try { yamatoShopname aa = db.Queryable<busi_sendorder>().JoinTable<busi_custorder>((s1, s2) => s1.custorder_id == s2.order_id) .JoinTable<busi_custorder,base_shop>((s1,s2, s3) => s2.shop_id == s3.shop_id) .JoinTable<base_shop,base_platform>((s1,s3, s4) => s3.platform_id == s4.platform_id) .Where<busi_sendorder>(s1=> s1.order_code == packge.data_10) .Select<base_shop, base_platform, yamatoShopname>((s1,s3, s4) => new yamatoShopname() { shopname=s3.shop_name, platfromname=s4.platform_name, Shopaddress=s3.shop_address, Shopphone=s3.shop_telephone, Shopzip=s3.shop_zipcode, Companyname = "" }).FirstOrDefault(); if(null==aa) { throw new Exception("无法得到发货定订单信息"); } Myamato pyamato = new Myamato(); pyamato.Shopname = aa.shopname; pyamato.Platform = aa.platfromname; pyamato.Shopzip = aa.Shopzip; pyamato.Shopphone = aa.Shopphone; pyamato.Shopaddress = aa.Shopaddress; pyamato.Companyname = "株式会社ジャパンドレス"; //-------------------------------------------------- pyamato.data_1 = packge.data_1; pyamato.data_2 = packge.data_2; pyamato.data_3 = packge.data_3; pyamato.data_4 = packge.data_4; pyamato.data_5 = packge.data_5; pyamato.data_6 = packge.data_6; pyamato.data_7 = packge.data_7; pyamato.data_8 = packge.data_8; pyamato.data_9 = packge.data_9; pyamato.data_10 = packge.data_10; pyamato.create_DateTime = packge.create_DateTime; pyamato.create_UserID = packge.create_UserID; pyamato.edit_DateTime = packge.edit_DateTime; pyamato.p_idPoint = packge.p_idPoint; pyamato.p_Status = packge.p_Status; pyamato.p_Workid = packge.p_Workid; pyamato.p_WorkRemarks = packge.p_WorkRemarks; pyamato.p_WorkType = packge.p_WorkType; pyamato.Print_DateTime = packge.Print_DateTime; return pyamato; } catch (Exception ex) { throw ex; } } }
/// <summary> /// yamato打印, /// </summary> /// <param name="Sender"></param> /// <param name="e"></param> private void Timeryamato_Tick(object Sender, EventArgs e) { int worktype = 50; int p_id = GetprintID(); //得到打印插件ID //1.得到需要打印的包裹号 List <busi_printwork> list = CommPrint.GetprintInfo(p_id, worktype); //worktype =50 if (list.Count > 0) //有数据要打印 { foreach (var item in list) { if (!Queueyamato.Contains(item.p_Workid)) //data_10存的是包裹号 { Queueyamato.Enqueue(item.p_Workid); PrintListYamato.Add(item.p_Workid, item); } } } if (PrintListYamato.Count > 0)//字典中有数据 { try { long workid = Queueyamato.Peek(); busi_printwork mypackge = PrintListYamato[workid]; //取出队列中对象 //打印yamato Myamato pyamato = CommPrint.GetPrintyamato(mypackge); if (null == pyamato) { throw new Exception("系统中不存在此店铺名或者此包裹" + mypackge.data_10); } PrintYamato printer = new PrintYamato(pyamato); printer.Print(true); bool isok = CommPrint.FinshPrint(p_id, mypackge); //设置已打印的状态 if (!isok) { Log(mypackge.data_1 + "打印失败!"); } else { //打印完成清除出队列 Queueyamato.Dequeue(); PrintListYamato.Remove(workid); Hasprintcount++; label7.Text = Hasprintcount.ToString(); Log(mypackge.data_1 + "包裹号已打印。Yamato" + DateTime.Now.ToString()); } } catch (Exception ex) { Log(ex.ToString()); } } }
/// <summary> /// 包裹打印 /// </summary> /// <param name="Sender"></param> /// <param name="e"></param> private void Timerpackge_Tick(object Sender, EventArgs e) { int worktype = 30; int p_id = GetprintID(); //得到打印插件ID //1.得到需要打印的包裹号 List <busi_printwork> list = CommPrint.GetprintInfo(p_id, worktype); if (list.Count > 0)//有数据要打印 { foreach (var item in list) { if (!Queuepackge.Contains(item.p_Workid)) { Queuepackge.Enqueue(item.p_Workid); PrintListpackge.Add(item.p_Workid, item); } } } if (PrintListpackge.Count > 0)//队列中有数据 { try { long workid = Queuepackge.Peek(); busi_printwork mypackge = PrintListpackge[workid]; //取出队列中对象 //打印包裹 packgeInfoViewModel mymodel = CommPrint.GetPrintpackge(mypackge); if (null == mymodel) { throw new Exception("系统中不存在此店铺名或者此包裹" + mypackge.data_1); } PrintPackge printer = new PrintPackge(mymodel); printer.Print(true); bool isok = CommPrint.FinshPrint(p_id, mypackge); if (!isok) { Log(mypackge.data_1 + "打印失败!"); } else { //打印完成清除出队列 Queuepackge.Dequeue(); PrintListpackge.Remove(workid); Hasprintcount++; label7.Text = Hasprintcount.ToString(); Log(mypackge.data_1 + "包裹号已打印。" + DateTime.Now.ToString()); } } catch (Exception ex) { Log(ex.ToString()); } } }
/// <summary> /// 转运单打印 /// </summary> /// <param name="Sender"></param> /// <param name="e"></param> private void Timerzhuanyun_Tick(object Sender, EventArgs e) { int worktype = 40; int p_id = GetprintID(); //得到打印插件ID //1.得到需要打印的包裹号 List <busi_printwork> list = CommPrint.GetprintInfo(p_id, worktype); if (list.Count > 0)//有数据要打印 { foreach (var item in list) { if (!Queuezhuanyun.Contains(item.p_Workid)) { Queuezhuanyun.Enqueue(item.p_Workid); PrintListzhuanyun.Add(item.p_Workid, item); } } } if (PrintListzhuanyun.Count > 0)//队列中有数据 { try { long workid = Queuezhuanyun.Peek(); busi_printwork mypackge = PrintListzhuanyun[workid]; //取出队列中对象 zhuanyunInfo zhuanyun = new zhuanyunInfo(); zhuanyun.workid = mypackge.p_Workid.ObjToInt(); zhuanyun.zhuanyuncode = mypackge.data_1; //打印转运单 Printzhuanyun printer = new Printzhuanyun(zhuanyun); printer.Print(true); bool isok = CommPrint.FinshPrint(p_id, mypackge); if (!isok) { Log(mypackge.data_1 + "打印失败!"); } else { //打印完成清除出队列 Queuezhuanyun.Dequeue(); PrintListzhuanyun.Remove(workid); Hasprintcount++; label7.Text = Hasprintcount.ToString(); Log(mypackge.data_1 + "转运单已打印。" + DateTime.Now.ToString()); } } catch (Exception ex) { Log(ex.ToString()); } } }
/// <summary> /// Upacket打印 /// </summary> /// <param name="Sender"></param> /// <param name="e"></param> private void TimerUpacket_Tick(object Sender, EventArgs e) { int worktype = 70; int p_id = GetprintID(); //得到打印插件ID //1.得到需要打印的包裹号 List <busi_printwork> list = CommPrint.GetprintInfo(p_id, worktype); if (list.Count > 0)//有数据要打印 { foreach (var item in list) { if (!Queueupacket.Contains(item)) { Queueupacket.Enqueue(item); } } } if (Queueupacket.Count > 0)//队列中有数据 { try { busi_printwork mypackge = Queueupacket.Peek(); //取出队列中对象 //打印yamato MyUpacket pupacket = CommPrint.GetPrintUpacket(mypackge); if (null == pupacket) { throw new Exception("系统中不存在此店铺名或者此包裹" + mypackge.data_10); } PrintUpacket printer = new PrintUpacket(pupacket); printer.Print(true); //打印完成清除出队列 Queueupacket.Dequeue(); bool isok = CommPrint.FinshPrint(p_id, mypackge); if (!isok) { Log(mypackge.data_1 + "打印失败!"); } else { Hasprintcount++; label7.Text = Hasprintcount.ToString(); Log(mypackge.data_1 + "包裹号已打印。Upacket" + DateTime.Now.ToString()); } } catch (Exception ex) { Log(ex.ToString()); } } }
/// <summary> /// 只取一条 /// </summary> /// <param name="printID"></param> /// <param name="Pworktype"></param> /// <returns></returns> public static busi_printwork GetOneprintInfo(int printID, int Pworktype) { using (var db = SugarDao.GetInstance(Getconnstring.Getmyconnstring())) { try { busi_printwork list = db.SqlQuery<busi_printwork>("select top 1 * from busi_printwork where p_WorkType=@worktype and p_Status=1 and p_idPoint=@id order by p_Workid asc", new { id = printID, worktype = Pworktype }).FirstOrDefault(); return list; } catch (Exception ex) { throw ex; } } }
public static bool FinshPrint(int printID, busi_printwork pack) { using (var db = SugarDao.GetInstance(Getconnstring.Getmyconnstring())) { try { DateTime ptime = DateTime.Now; pack.p_idActual = printID; pack.Print_DateTime = ptime; pack.p_Status = 0; bool isok = db.Update<busi_printwork>(pack); return isok; } catch (Exception ex) { throw ex; } } }
public static bool InsertPrintMiandan(busi_printwork pwork) { using (var db = SugarDao.GetInstance(Getconnstring.Getmyconnstring())) { try { var isok = db.Insert <busi_printwork>(pwork); if (isok.ObjToInt() > 0) { return(true); } else { return(false); } } catch (Exception ex) { throw ex; } } }
/// <summary> /// 打印转运单 /// </summary> /// <param name="zhuanyuncode"></param> /// <returns></returns> public bool PrintzhuanyunCode(string zhuanyuncode) { using (var db = SugarDao.GetInstance(conn)) { try { busi_transfer inserttran = new busi_transfer(); inserttran.tran_status = 1; inserttran.create_time = DateTime.Now; inserttran.create_user_id = 1; inserttran.del_flag = true; inserttran.remark = ""; inserttran.edit_time = DateTime.Now; inserttran.tran_code = zhuanyuncode; inserttran.tran_count = 0; db.Insert <busi_transfer>(inserttran); busi_printwork insertinfo = new busi_printwork(); insertinfo.p_WorkType = 40; insertinfo.data_1 = zhuanyuncode; insertinfo.data_4 = DateTime.Now.ToString(); insertinfo.p_idPoint = 1; //测试 insertinfo.p_Status = 1; var isok = db.Insert <busi_printwork>(insertinfo).ObjToInt(); if (isok > 0) { return(true); } else { return(false); } } catch (Exception ex) { throw ex; } } }
/// <summary> /// 插入打印数据到打印表中 /// </summary> /// <param name="pwork"></param> /// <returns></returns> public static bool InsertPrintMiandan(busi_printwork pwork) { using (var db = SugarDao.GetInstance(Getconnstring.Getmyconnstring())) { try { var isok = db.Insert <busi_printwork>(pwork); db.Update <busi_sendorder>(new { is_print = 1, print_time = DateTime.Now }, s => s.order_code == pwork.data_10); if (isok.ObjToInt() > 0) { return(true); } else { return(false); } } catch (Exception ex) { throw ex; } } }
/// <summary> /// 包裹号扫描 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void textBox1_KeyDown(object sender, KeyEventArgs e) { if (Keys.Enter == e.KeyCode)//按下回车键 { string packgecode = textBox1.Text.Trim(); if (string.IsNullOrEmpty(packgecode)) { MessageBox.Show("请扫描包裹号或者输入正确的包裹号!"); textBox1.Focus(); return; } else //包裹号不为空 { //1.先判断包裹号是否在系统中存在,且没有取消 int isok = CheckSysInfo.CheckPackge(packgecode); if (1 == isok) { Log(packgecode + "包裹在系统中不存在!" + DateTime.Now.ToString()); MessageBox.Show("包裹在系统中不存在!"); textBox1.Text = ""; textBox1.Focus(); return; } else if (2 == isok) { Log(packgecode + "包裹已取消,请取出!" + DateTime.Now.ToString()); MessageBox.Show("包裹已取消,请取出!"); textBox1.Text = ""; textBox1.Focus(); return; } //2.如果包裹存在系统中,正常,取出包裹的信息 List <PackgePrintInfo> packinfolist = CheckSysInfo.GetPckgePrintInfo(packgecode); busi_printwork printinsert = new busi_printwork(); StringBuilder skus = new StringBuilder(); foreach (var item in packinfolist) { skus = skus.Append(item.skucode + "*" + item.skunum + ","); } if (null == packinfolist) { Log("无法获取到包裹信息" + DateTime.Now.ToString()); MessageBox.Show("无法获取到包裹信息,打印失败"); textBox1.Text = ""; textBox1.Focus(); return; } if (packinfolist[0].expressid == 0 || string.IsNullOrEmpty(packinfolist[0].ExpCode)) { Log("包裹信息不完整,该包裹还未选择发货方式或没单号,无法打印" + DateTime.Now.ToString()); MessageBox.Show("包裹信息不完整,该包裹还未选择发货方式或没单号,无法打印"); textBox1.Text = ""; textBox1.Focus(); return; } if (string.IsNullOrEmpty(packinfolist[0].name) || string.IsNullOrEmpty(packinfolist[0].mobile + packinfolist[0].phone)) { Log("包裹信息不完整,没有客户名或者电话信息,无法打印" + DateTime.Now.ToString()); MessageBox.Show("包裹信息不完整,没有客户名或者电话信息,无法打印"); textBox1.Text = ""; textBox1.Focus(); return; } if (string.IsNullOrEmpty(packinfolist[0].address) || string.IsNullOrEmpty(packinfolist[0].zipcode)) { Log("包裹信息不完整,没有客户地址或者邮编信息,无法打印" + DateTime.Now.ToString()); MessageBox.Show("包裹信息不完整,没有客户地址或者邮编信息,无法打印"); textBox1.Text = ""; textBox1.Focus(); return; } printinsert.data_10 = packgecode; printinsert.data_1 = "Scan:" + packgecode; printinsert.data_2 = packinfolist[0].name;//客户名 printinsert.data_3 = packinfolist[0].mobile + "," + packinfolist[0].phone; printinsert.data_4 = packinfolist[0].zipcode; printinsert.data_5 = packinfolist[0].address; printinsert.data_6 = packinfolist[0].count.ToString(); printinsert.data_7 = skus.ToString(); printinsert.data_9 = packinfolist[0].ExpCode; printinsert.p_idPoint = GetprintID(); //得到打印插件ID printinsert.p_Status = 1; printinsert.p_WorkRemarks = ""; printinsert.create_DateTime = DateTime.Now; switch (packinfolist[0].expressid) { case 1: //yamato printinsert.data_8 = "yamato"; printinsert.p_WorkType = 50; break; case 2: //Upacket printinsert.data_8 = "Upacket"; printinsert.p_WorkType = 70; break; default: Log(packgecode + "包裹号,暂时不支持这种快递类型的打印!" + DateTime.Now.ToString()); MessageBox.Show("包裹号,暂时不支持这种快递类型的打印!"); textBox1.Text = ""; textBox1.Focus(); break; } bool isprintok = CheckSysInfo.InsertPrintMiandan(printinsert); if (isprintok) { Log("包裹号:" + packgecode + " " + printinsert.data_8 + "面单打印成功!打印时间:" + DateTime.Now.ToString()); textBox1.Text = ""; textBox1.Focus(); } else { MessageBox.Show("包裹号打印失败,请确认!"); textBox1.Text = ""; textBox1.Focus(); } } } }
/// <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; } } }
/// <summary> /// 确认配货 /// </summary> /// <param name="peihuoinfo"></param> /// <param name="Userinfo"></param> /// <returns></returns> public bool ConfirmDistruit(RFTDistrView peihuoinfo, base_users Userinfo) { using (var db = SugarDao.GetInstance(conn)) { try { //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 == "可包装")//单件的,需要打印 { db.Update <busi_sendorder>(new { order_tatus = 40 }, 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 (stock == null || 0 >= stock.stock_qty) { throw new Exception("金华仓临时库库存为零"); } stock.stock_qty--; db.Update <base_wh_stock>(stock); //--------------------------------------------------------------------- } else if (peihuoinfo.info == "可拆包")//多件的在拣选中打印(上架) { //2.再判断此包裹是否已配齐,如果配齐,设置状态,如果不配齐,设置对应状态(如果是单件的,直接打印,多件的不打印) int Ispackpacknum = db.SqlQuery <int>(@"select count(*) as num from busi_workinfo where is_work=1 and packid=@packid", new { packid = peihuoinfo.packid }).SingleOrDefault(); if (peihuoinfo.packnum == Ispackpacknum) //此处判断包裹是否已配齐 { 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); //如果小于,设置包裹部分配货 } } //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); } return(true); } else { return(false); } } catch (Exception ex) { throw ex; } } }
/// <summary> /// 确认打印 /// </summary> /// <returns></returns> public bool ComfirmPrint() { using (var db = SugarDao.GetInstance(LoginUser.GetConstr())) { try { List <PrintworkViewModel> comresult = db.Queryable <busi_sendorder>().JoinTable <busi_sendorder_detail>((s1, s2) => s1.order_id == s2.order_id) .JoinTable <busi_sendorder_detail, base_prod_code>((s1, s2, s3) => s2.code_id == s3.code_id) .Where(s1 => s1.del_flag == true).Where(s1 => s1.prod_num >= 2).Where(s1 => s1.order_tatus == 40)//40代表配货已完成 .Where(s1 => s1.is_print == false) .Select <busi_sendorder_detail, base_prod_code, PrintworkViewModel>((s1, s2, s3) => new PrintworkViewModel() { packID = s1.order_id, packgecode = s1.order_code, Skucode = s3.sku_code, skunum = s2.prod_num.ObjToInt(), count = s1.prod_num }).ToList(); //2.往print_work中放数据 List <busi_printwork> mylist = new List <busi_printwork>(); List <string> packcode = new List <string>(); foreach (var item in comresult) { busi_printwork nn = new busi_printwork(); nn.p_WorkType = 20; nn.p_Status = 1; nn.p_idPoint = 1;//测试 nn.data_1 = item.packgecode; nn.data_2 = item.Skucode; nn.data_3 = item.skunum.ToString(); nn.data_4 = "ZZ-ZZ-ZZ"; nn.create_DateTime = DateTime.Now; nn.create_UserID = LoginUser.Current.user_id.ObjToInt(); mylist.Add(nn); } foreach (var item in comresult) //插入包裹号打印 { if (!packcode.Contains(item.packgecode)) { busi_printwork insertinfo = new busi_printwork(); insertinfo.p_WorkType = 30; insertinfo.data_1 = item.packgecode; insertinfo.data_4 = DateTime.Now.ToString(); insertinfo.p_idPoint = 1; //测试 insertinfo.p_Status = 1; insertinfo.data_2 = item.packgecode.Substring(8, 4); insertinfo.data_3 = item.count.ToString(); mylist.Add(insertinfo); packcode.Add(item.packgecode); } } bool isok = db.SqlBulkCopy(mylist);//批量插入数据 if (isok) { //3.打印成功之后设置已打印 List <long> mm = new List <long>(); foreach (var item in comresult) { mm.Add(item.packID); } var array = mm.ToArray(); db.Update <busi_sendorder>(new { is_print = true, print_time = DateTime.Now }, it => array.Contains(it.order_id)); return(true); } else { return(false); } } catch (Exception ex) { throw ex; } } }