Exemplo n.º 1
0
        public static void AddStockDetal(IAMSCMUow uow, DXInfo.Models.tbStockMain tbStockMain, string cnvcInvCode
                                         , string cnvcComUnitCode, decimal cnnQuantity, string cnvcMainComUnitCode, decimal cnnMainQuantity, decimal cnnPrice, decimal cnnAmount)
        {
            DXInfo.Models.tbStockDetail tbStockDetail = new DXInfo.Models.tbStockDetail();
            tbStockDetail.cnnMainId           = tbStockMain.cnnMainId;
            tbStockDetail.cnvcInvCode         = cnvcInvCode;
            tbStockDetail.cnvcComUnitCode     = cnvcComUnitCode;
            tbStockDetail.cnnQuantity         = cnnQuantity;
            tbStockDetail.cnvcMainComUnitCode = cnvcMainComUnitCode;
            tbStockDetail.cnnMainQuantity     = cnnMainQuantity;
            tbStockDetail.cnnPrice            = cnnPrice;
            tbStockDetail.cnnAmount           = cnnAmount;
            tbStockDetail.cndOperDate         = tbStockMain.cndCreateDate;
            tbStockDetail.cnvcOper            = tbStockMain.cnvcCreaterId;
            tbStockDetail.cnvcOperName        = tbStockMain.cnvcCreaterName;

            uow.tbStockDetail.Add(tbStockDetail);
            uow.Commit();

            DXInfo.Models.tbStockDetailLog tbStockDetailLog = new DXInfo.Models.tbStockDetailLog();
            ServiceHelper.SetEntity <DXInfo.Models.tbStockDetail, DXInfo.Models.tbStockDetailLog>(tbStockDetail, tbStockDetailLog);
            uow.tbStockDetailLog.Add(tbStockDetailLog);
        }
Exemplo n.º 2
0
        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, "")));
        }