public JsonResult IinvdSave() { bool falg = false; string message ="保存失敗"; try { string row_id = ""; int prod_qty = 0; if (Request.Params["rowid"].Length > 5) { row_id = Request.Params["rowid"].Substring(5); } string changeStore = Request.Params["changeStore"]; int temp1=0; if (int.TryParse(changeStore, out temp1)) { if (temp1 < 0) { falg = false; message = "庫存不能小於1"; } else { _iinvd = new IinvdMgr(mySqlConnectionString); IinvdQuery iinvd = new IinvdQuery(); iinvd.pwy_dte_ctl = Request.Params["pwy_dte_ctl"]; if (!string.IsNullOrEmpty(Request.Params["loc_id"])) { iinvd.plas_loc_id = Request.Params["loc_id"]; } int id = 0; if (int.TryParse(row_id, out id)) { iinvd.row_id = id; } if (int.TryParse(changeStore, out id)) { iinvd.prod_qty = id; } if (!string.IsNullOrEmpty(Request.Params["item_id"])) { if (int.TryParse(Request.Params["item_id"], out id)) { iinvd.item_id = uint.Parse(Request.Params["item_id"]); } } iinvd.create_user = (Session["caller"] as Caller).user_id; iinvd.create_dtim = DateTime.Now; iinvd.change_user = iinvd.create_user; iinvd.change_dtim = iinvd.create_dtim; iinvd.prod_qtys = _iinvd.GetProd_qty(Convert.ToInt32(iinvd.item_id), iinvd.plas_loc_id, "", iinvd.row_id.ToString()); if (iinvd.pwy_dte_ctl == "Y") { List<DateTime> list = new List<DateTime>(); list=_iinvd.GetCde_dt(iinvd.row_id); if(list.Count>0) { iinvd.cde_dt = list[0]; iinvd.made_date = list[1]; } } else { iinvd.made_date = iinvd.create_dtim; iinvd.cde_dt = iinvd.create_dtim; } if (iinvd.row_id != 0) { if (iinvd.pwy_dte_ctl == "Y") { prod_qty = _iinvd.GetProd_qty((int)iinvd.item_id, iinvd.plas_loc_id, iinvd.pwy_dte_ctl, iinvd.row_id.ToString()); if (prod_qty == iinvd.prod_qty) { falg = true; return Json(new { success = falg, message = message }); } else if (_iinvd.SaveIinvd(iinvd) == 1) { falg = true; } } if (iinvd.pwy_dte_ctl == "N" || iinvd.pwy_dte_ctl == "") { iinvd.row_id = 0; if (iinvd.prod_qtys < iinvd.prod_qty) { iinvd.ista_id = "A"; iinvd.prod_qty = iinvd.prod_qty - iinvd.prod_qtys; iinvd.cde_dt = DateTime.Now; int result=_iinvd.GetIinvdCount(iinvd); if (result>1) { prod_qty = result - 1; falg = true; } else { if (_iinvd.Insert(iinvd) == 1) { falg = true; } } } else if (iinvd.prod_qtys> iinvd.prod_qty) { if (_iinvd.SaveIinvd(iinvd) == 1) { falg = true; return Json(new { success = falg, message = message }); } } else if (iinvd.prod_qtys == iinvd.prod_qty) { falg = true; return Json(new { success = falg, message = message }); } } IialgQuery iialg = new IialgQuery(); iialg.cde_dt = iinvd.cde_dt; iialg.qty_o = prod_qty;//原始庫存數量 iialg.loc_id = iinvd.plas_loc_id; iialg.item_id = iinvd.item_id; iialg.iarc_id = "循環盤點"; if (iinvd.pwy_dte_ctl == "Y") { iialg.adj_qty = iinvd.prod_qty - prod_qty; } else { iialg.adj_qty = iinvd.prod_qty-prod_qty;//轉移數量 } iialg.create_dtim = DateTime.Now; iialg.create_user = iinvd.create_user; iialg.type = 2; iialg.doc_no = "C" + DateTime.Now.ToString("yyyyMMddHHmmss"); iialg.made_dt = iinvd.made_date; iialg.cde_dt = iinvd.cde_dt; _iialgMgr = new IialgMgr(mySqlConnectionString); _iialgMgr.insertiialg(iialg); IstockChangeQuery istock = new IstockChangeQuery(); istock.sc_trans_id = iialg.doc_no; istock.item_id = iinvd.item_id; istock.sc_istock_why = 2; istock.sc_trans_type = 2; istock.sc_num_old = iinvd.prod_qtys;//原始庫存數量 istock.sc_num_chg = iialg.adj_qty;//轉移數量 istock.sc_num_new = _iinvd.GetProd_qty((int)iinvd.item_id, iinvd.plas_loc_id,"","");//結餘數量 istock.sc_time = iinvd.create_dtim; istock.sc_user = iinvd.create_user; istock.sc_note = "循環盤點"; IstockChangeMgr istockMgr = new IstockChangeMgr(mySqlConnectionString); istockMgr.insert(istock); } else { return Json(new { success = falg }); } } } else { message = "庫存不能小於1"; } } catch (Exception ex) { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message); logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); } return Json(new { success = falg,message=message }); }