private string newtbMonthlyBalance(HttpContext context) { try { //using (DXInfo.Models.AMSCM amscm = new DXInfo.Models.AMSCM()) //{ DXInfo.Models.tbMonthlyBalance tbMonthlyBalance = new DXInfo.Models.tbMonthlyBalance(); tbMonthlyBalance.cnnYear = Convert.ToInt32(context.Request.Form["cnnYear"]); tbMonthlyBalance.cnnMonth = Convert.ToInt32(context.Request.Form["cnnMonth"]); tbMonthlyBalance.cnbIsBalance = false; tbMonthlyBalance.cndCreateDate = DateTime.Now; tbMonthlyBalance.cnvcCreater = context.User.Identity.Name; CMSMStruct.LoginStruct ls1 = (CMSMStruct.LoginStruct)context.Session["Login"]; tbMonthlyBalance.cnvcCreaterName = ls1.strOperName; Uow.tbMonthlyBalance.Add(tbMonthlyBalance); DXInfo.Models.tbMonthlyBalanceLog tbMonthlyBalanceLog = new DXInfo.Models.tbMonthlyBalanceLog(); ServiceHelper.SetEntity <DXInfo.Models.tbMonthlyBalance, DXInfo.Models.tbMonthlyBalanceLog>(tbMonthlyBalance, tbMonthlyBalanceLog); Uow.tbMonthlyBalanceLog.Add(tbMonthlyBalanceLog); Uow.Commit(); //} } catch (DbUpdateException dex) { ExceptionPolicy.HandleException(dex, ServiceHelper.ExceptionPolicy); return(ServiceHelper.JsonSerializer <JEasyUIResult>(new JEasyUIResult(false, dex.Message))); } return(ServiceHelper.JsonSerializer <JEasyUIResult>(new JEasyUIResult(true, ""))); }
private string balance(HttpContext context) { try { //using (DXInfo.Models.AMSCM amscm = new DXInfo.Models.AMSCM()) //{ using (TransactionScope transaction = new TransactionScope()) { //更新月结表 int icnnYear = Convert.ToInt32(context.Request.Form["cnnYear"]); int icnnMonth = Convert.ToInt32(context.Request.Form["cnnMonth"]); int icount = (from d in Uow.tbMonthlyBalance.GetAll() where d.cnnYear <= icnnYear && d.cnnMonth < icnnMonth && !d.cnbIsBalance select d).Count(); if (icount > 0) { return(ServiceHelper.JsonSerializer <JEasyUIResult>(new JEasyUIResult(false, "请先月结以前月份!"))); } DXInfo.Models.tbMonthlyBalance tbMonthlyBalance = Uow.tbMonthlyBalance.GetById(g => g.cnnYear == icnnYear && g.cnnMonth == icnnMonth); if (tbMonthlyBalance.cnbIsBalance) { return(ServiceHelper.JsonSerializer <JEasyUIResult>(new JEasyUIResult(false, "已月结!"))); } tbMonthlyBalance.cnbIsBalance = true; string strOperId = context.User.Identity.Name; CMSMStruct.LoginStruct ls1 = (CMSMStruct.LoginStruct)context.Session["Login"]; string strOperName = ls1.strOperName; tbMonthlyBalance.cndBalanceDate = DateTime.Now; tbMonthlyBalance.cnvcBalancer = strOperId; tbMonthlyBalance.cnvcBalancerName = strOperName; DXInfo.Models.tbMonthlyBalanceLog tbMonthlyBalanceLog = new DXInfo.Models.tbMonthlyBalanceLog(); ServiceHelper.SetEntity <DXInfo.Models.tbMonthlyBalance, DXInfo.Models.tbMonthlyBalanceLog>(tbMonthlyBalance, tbMonthlyBalanceLog); Uow.tbMonthlyBalanceLog.Add(tbMonthlyBalanceLog); //更新盘点和领料单的成本 Compute(tbMonthlyBalance, strOperId, strOperName); Uow.Commit(); transaction.Complete(); } //} } catch (DbUpdateException dex) { ExceptionPolicy.HandleException(dex, ServiceHelper.ExceptionPolicy); return(ServiceHelper.JsonSerializer <JEasyUIResult>(new JEasyUIResult(false, dex.Message))); } return(ServiceHelper.JsonSerializer <JEasyUIResult>(new JEasyUIResult(true, ""))); }
private string cancelBalance(HttpContext context) { try { //using (DXInfo.Models.AMSCM amscm = new DXInfo.Models.AMSCM()) //{ using (TransactionScope transaction = new TransactionScope()) { int icnnYear = Convert.ToInt32(context.Request.Form["cnnYear"]); int icnnMonth = Convert.ToInt32(context.Request.Form["cnnMonth"]); int icount = (from d in Uow.tbMonthlyBalance.GetAll() where d.cnnYear >= icnnYear && d.cnnMonth > icnnMonth && d.cnbIsBalance select d).Count(); if (icount > 0) { return(ServiceHelper.JsonSerializer <JEasyUIResult>(new JEasyUIResult(false, "请先取消以前月份月结!"))); } DXInfo.Models.tbMonthlyBalance tbMonthlyBalance = Uow.tbMonthlyBalance.GetById(g => g.cnnYear == icnnYear && g.cnnMonth == icnnMonth); if (!tbMonthlyBalance.cnbIsBalance) { return(ServiceHelper.JsonSerializer <JEasyUIResult>(new JEasyUIResult(false, "未月结!"))); } tbMonthlyBalance.cnbIsBalance = false; tbMonthlyBalance.cndModifyDate = DateTime.Now; tbMonthlyBalance.cnvcModifier = context.User.Identity.Name; CMSMStruct.LoginStruct ls1 = (CMSMStruct.LoginStruct)context.Session["Login"]; tbMonthlyBalance.cnvcModifierName = ls1.strOperName; tbMonthlyBalance.cndBalanceDate = null; tbMonthlyBalance.cnvcBalancer = string.Empty; tbMonthlyBalance.cnvcBalancerName = string.Empty; Uow.Commit(); DXInfo.Models.tbMonthlyBalanceLog tbMonthlyBalanceLog = new DXInfo.Models.tbMonthlyBalanceLog(); ServiceHelper.SetEntity <DXInfo.Models.tbMonthlyBalance, DXInfo.Models.tbMonthlyBalanceLog>(tbMonthlyBalance, tbMonthlyBalanceLog); Uow.tbMonthlyBalanceLog.Add(tbMonthlyBalanceLog); int icnnCheckStatus = (int)StockStatus.Check; List <long> lcnnDetailId = (from main in Uow.tbStockMain.GetAll() join d in Uow.tbStockDetail.GetAll() on main.cnnMainId equals d.cnnMainId into md from detail in md.DefaultIfEmpty() where main.cnnYear == tbMonthlyBalance.cnnYear && main.cnnMonth == tbMonthlyBalance.cnnMonth && main.cnnStatus == icnnCheckStatus && main.cnnOperType != 0 && main.cnnOperType != 1 orderby main.cnnMainId select detail.cnnDetailId).Distinct().ToList(); foreach (long cnnDetailId in lcnnDetailId) { DXInfo.Models.tbStockDetail tbStockDetail = Uow.tbStockDetail.GetById(g => g.cnnDetailId == cnnDetailId); tbStockDetail.cnnPrice = 0; tbStockDetail.cnnAmount = 0; DXInfo.Models.tbStockDetailLog tbStockDetailLog = new DXInfo.Models.tbStockDetailLog(); ServiceHelper.SetEntity <DXInfo.Models.tbStockDetail, DXInfo.Models.tbStockDetailLog>(tbStockDetail, tbStockDetailLog); Uow.tbStockDetailLog.Add(tbStockDetailLog); } int inextcnnYear = icnnYear; int inextcnnMonth = icnnMonth + 1; if (icnnMonth == 12) { inextcnnYear += 1; inextcnnMonth = 1; } var q = (from main in Uow.tbStockMain.GetAll() join d in Uow.tbStockDetail.GetAll() on main.cnnMainId equals d.cnnMainId into md from detail in md.DefaultIfEmpty() where main.cnnYear == inextcnnYear && main.cnnMonth == inextcnnMonth && main.cnnStatus == icnnCheckStatus && main.cnnSource == 1 orderby main.cnnMainId select new { detail.cnnMainId, detail.cnnDetailId }).Distinct().ToList(); var q1 = (from d in q select d.cnnMainId).Distinct().ToList(); var q2 = (from d in q select d.cnnDetailId).Distinct().ToList(); if (q1.Count > 0) { foreach (long cnnMainId in q1) { DXInfo.Models.tbStockMain tbStockMain = Uow.tbStockMain.GetById(g => g.cnnMainId == cnnMainId); tbStockMain.cnnStatus = (int)StockStatus.Delete; Uow.tbStockMain.Delete(tbStockMain); DXInfo.Models.tbStockMainLog tbStockMainLog = new DXInfo.Models.tbStockMainLog(); ServiceHelper.SetEntity <DXInfo.Models.tbStockMain, DXInfo.Models.tbStockMainLog>(tbStockMain, tbStockMainLog); Uow.tbStockMainLog.Add(tbStockMainLog); } } if (q2.Count > 0) { foreach (long cnnDetailId in q2) { DXInfo.Models.tbStockDetail tbStockDetail = Uow.tbStockDetail.GetById(g => g.cnnDetailId == cnnDetailId); Uow.tbStockDetail.Delete(tbStockDetail); DXInfo.Models.tbStockDetailLog tbStockDetailLog = new DXInfo.Models.tbStockDetailLog(); ServiceHelper.SetEntity <DXInfo.Models.tbStockDetail, DXInfo.Models.tbStockDetailLog>(tbStockDetail, tbStockDetailLog); Uow.tbStockDetailLog.Add(tbStockDetailLog); } } Uow.Commit(); transaction.Complete(); } //} } catch (DbUpdateException dex) { ExceptionPolicy.HandleException(dex, ServiceHelper.ExceptionPolicy); return(ServiceHelper.JsonSerializer <JEasyUIResult>(new JEasyUIResult(false, dex.Message))); } return(ServiceHelper.JsonSerializer <JEasyUIResult>(new JEasyUIResult(true, ""))); }