/// <summary> /// 使用快递单号 /// </summary> /// <param name="expressid"></param> /// <param name="csvtable"></param> /// <returns></returns> public int UseExpressCode(int expressid, System.Data.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(); db.Update <base_expresscode>(new { isuse = true, Usetime = DateTime.Now, packgecode = mypackge }, it => it.Eid == Eid.Eid); bool isok = db.Update <busi_sendorder>(new { exp_code = Eid.Expresscode }, it => it.order_code == mypackge);//如果包裹号不存在系统中也没事 if (isok) { mycount++; } } db.CommitTran();//提交事务 return(mycount); } catch (Exception ex) { db.RollbackTran();//回滚事务 throw ex; } } }
/// <summary> /// 生成单号区间 /// </summary> /// <param name="express"></param> /// <param name="scode"></param> /// <param name="lcode"></param> /// <returns></returns> public ActionResult CreateExpressCode(int express, string scode, string lcode, int pageindex, int insys) { DBModel.Common.ComResult res = new DBModel.Common.ComResult(); try { string[] nexpcode = null; myexpresscode = AUTOgetcode(scode, lcode); if (insys == 1) { List <base_expresscode> listexp = new List <base_expresscode> (); foreach (var item in myexpresscode) { base_expresscode aa = new base_expresscode(); aa.express_id = express; aa.Expresscode = item; aa.importtime = DateTime.Now; aa.isuse = false; aa.packgecode = ""; aa.Usetime = null; listexp.Add(aa); } bool isok = _service.Import(listexp); if (isok) { res.State = 2; res.Msg = "单号进入系统成功"; return(Json(res)); } else { res.State = 0; res.Msg = "单号进入系统失败"; return(Json(res)); } } else { nexpcode = myexpresscode.Skip(20 * (pageindex - 1)).Take(20).ToArray(); res.DataResult = nexpcode; res.State = 1; res.URL = myexpresscode.Count.ToString(); int pages = myexpresscode.Count / 20; if (myexpresscode.Count % 20 > 0) { pages++; } res.Msg = pages.ToString(); return(Json(res)); } } catch (Exception ex) { res.State = 0; res.Msg = ex.ToString(); return(Json(res)); } }