Esempio n. 1
0
        public void SaveSolution(Sender sender, SaveSolutionArgs args)
        {
            try
            {
                using (ObjectProxy op = new ObjectProxy(true))
                {
                    Solution obj = new Solution();
                    obj.SolutionID = args.Solution.SolutionID;


                    if (op.LoadSolutionBySolutionID(obj) == 0)
                    {
                        args.Solution.Created    = DateTime.Now;
                        args.Solution.CreatedBy  = sender.UserCode + "." + sender.UserName;
                        args.Solution.Modified   = DateTime.Now;
                        args.Solution.ModifiedBy = sender.UserCode + "." + sender.UserName;
                        op.InsertSolution(args.Solution);
                    }
                    else
                    {
                        args.Solution.Modified   = DateTime.Now;
                        args.Solution.ModifiedBy = sender.UserCode + "." + sender.UserName;
                        op.UpdateSolutionBySolutionID(args.Solution);
                    }

                    if (args.Solution2Cabinets != null)
                    {
                        op.DeleteSolutionDetailsBySolutionID(args.Solution.SolutionID);
                        op.DeleteSolution2HardwaresBySolutionID(args.Solution.SolutionID);
                        op.DeleteSolution2CabinetsBySolutionID(args.Solution.SolutionID);
                        foreach (Solution2Cabinet item in args.Solution2Cabinets)
                        {
                            Solution2Cabinet subItem = new Solution2Cabinet();
                            subItem.CabinetID = item.CabinetID;
                            if (op.LoadSolution2CabinetByCabinetID(subItem) == 0)
                            {
                                item.Created    = DateTime.Now;
                                item.CreatedBy  = sender.UserCode + "." + sender.UserName;
                                item.Modified   = DateTime.Now;
                                item.ModifiedBy = sender.UserCode + "." + sender.UserName;
                                op.InsertSolution2Cabinet(item);
                            }
                            else
                            {
                                item.Modified   = DateTime.Now;
                                item.ModifiedBy = sender.UserCode + "." + sender.UserName;
                                op.UpdateSolution2CabinetByCabinetID(item);
                            }
                        }
                    }

                    if (args.Solution2Hardwares != null)
                    {
                        op.DeleteSolution2HardwaresBySolutionID(args.Solution.SolutionID);
                        foreach (Solution2Hardware item in args.Solution2Hardwares)
                        {
                            item.Created    = DateTime.Now;
                            item.CreatedBy  = sender.UserCode + "." + sender.UserName;
                            item.Modified   = DateTime.Now;
                            item.ModifiedBy = sender.UserCode + "." + sender.UserName;
                            op.InsertSolution2Hardware(item);
                        }
                    }

                    if (args.SolutionDetails != null)
                    {
                        op.DeleteSolutionDetailsBySolutionID(args.Solution.SolutionID);
                        foreach (SolutionDetail item in args.SolutionDetails)
                        {
                            if (IsSolutionBarcodeDuplicated(sender, item))
                            {
                                throw new PException("产品条码【{0}】已存在。", item.BarcodeNo);
                            }
                            item.Created    = DateTime.Now;
                            item.CreatedBy  = sender.UserCode + "." + sender.UserName;
                            item.Modified   = DateTime.Now;
                            item.ModifiedBy = sender.UserCode + "." + sender.UserName;
                            op.InsertSolutionDetail(item);
                        }
                    }
                    if (args.SolutionOthers != null)
                    {
                        op.DeleteSolutionOtherssBySolutionID(args.Solution.SolutionID);
                        foreach (SolutionOthers item in args.SolutionOthers)
                        {
                            op.InsertSolutionOthers(item);
                        }
                    }
                    op.CommitTransaction();
                }
            }
            catch (Exception ex)
            {
                PLogger.LogError(ex);
                throw ex;
            }
        }
Esempio n. 2
0
        public void SaveQuote()
        {
            try
            {
                using (ProxyBE p = new ProxyBE())
                {
                    #region  报价单

                    if (string.IsNullOrEmpty(Request["ReferenceID"]))
                    {
                        throw new Exception("ReferenceID:参数无效!");
                    }
                    Solution solution = p.Client.GetSolutionByDesignerID(SenderUser, Guid.Parse(Request["ReferenceID"]));
                    if (solution == null)
                    {
                        throw new Exception("对象无效!");
                    }
                    if (string.IsNullOrEmpty(Request["TaskID"]))
                    {
                        throw new Exception("TaskID:参数无效!");
                    }
                    QuoteMain quotemain = p.Client.GetQuoteMain(SenderUser, parm.QuoteID);
                    if (quotemain == null)
                    {
                        quotemain            = new QuoteMain();
                        quotemain.QuoteID    = Guid.NewGuid();
                        quotemain.SolutionID = solution.SolutionID;
                        quotemain.Status     = "N"; //报价单状态,N:确认中,F:已确认,C:已取消
                    }
                    quotemain.PartnerID       = CurrentUser.PartnerID;
                    quotemain.CustomerID      = solution.CustomerID;
                    quotemain.QuoteNo         = GetNumber("YS");
                    quotemain.DiscountPercent = parm.DiscountPercent;
                    quotemain.ExpiryDate      = parm.ExpiryDate;
                    quotemain.Status          = "N";
                    quotemain.Remark          = parm.Remark;
                    SaveQuoteMainArgs args = new SaveQuoteMainArgs();

                    #endregion

                    #region 报价单详情
                    List <QuoteDetail> QuoteDetails    = new List <QuoteDetail>();
                    string             details         = Request["QuoteDetails"];
                    decimal            DiscountPercent = 1;
                    JsonData           sj          = JsonMapper.ToObject(details);
                    decimal            totalamount = 0;
                    if (sj.Count > 0)
                    {
                        //遍历对象元素,保存
                        int i = 1;
                        foreach (JsonData item in sj)
                        {
                            try
                            {
                                QuoteDetail detail = new QuoteDetail();
                                detail.DetailID = Guid.NewGuid();
                                detail.QuoteID  = quotemain.QuoteID;

                                detail.ItemGroup = item["ItemGroup"].ToString();
                                detail.ItemName  = item["ItemName"].ToString();
                                detail.ItemStyle = item["ItemStyle"].ToString();
                                try
                                {
                                    detail.Qty = Decimal.Parse(item["Qty"].ToString());
                                }
                                catch
                                {
                                    throw new PException("第{0}行的数量有误。", i);
                                }
                                try
                                {
                                    detail.Price = Decimal.Parse(item["Price"].ToString());
                                }
                                catch
                                {
                                    throw new PException("第{0}行的价格有误。", i);
                                }
                                detail.ItemRemark = item["ItemRemark"].ToString();
                                QuoteDetails.Add(detail);
                                totalamount += detail.Price * detail.Qty;
                                i++;
                            }
                            catch
                            {
                                throw new PException("第{0}行的数据有误。", i);
                            }
                        }
                    }
                    quotemain.TotalAmount    = totalamount;
                    quotemain.DiscountAmount = (DiscountPercent - quotemain.DiscountPercent) * quotemain.TotalAmount;
                    args.QuoteMain           = quotemain;
                    args.QuoteDetails        = QuoteDetails;
                    p.Client.SaveQuote(SenderUser, args);
                    #endregion

                    #region 修改方案状态
                    solution.Status = "F";//方案状态:N,待上传方案文件;P,待生成报价明细;Q,已报价;F,方案成交;C,已取消;

                    SaveSolutionArgs arg = new SaveSolutionArgs();
                    arg.Solution = solution;

                    p.Client.SaveSolution(SenderUser, arg);
                    #endregion

                    #region 任务流程
                    Database dbCheck = new Database("BE_PartnerTask_Proc", "UPSTEPNO4", 5, 0, Request["TaskID"], "待提交订单", "P");
                    int      rst     = dbCheck.ExecuteNoQuery();
                    if (rst == 0)
                    {
                        WriteError("失败!");
                    }

                    //PartnerTask task = p.Client.GetPartnerTask(SenderUser, Guid.Parse(Request["TaskID"]));
                    //if (task != null)
                    //{
                    //    SavePartnerTaskArgs taskArgs = new SavePartnerTaskArgs();
                    //    taskArgs.PartnerTask = task;
                    //    taskArgs.NextStep = "待提交订单";
                    //    taskArgs.Resource = "报价确认组";//当前处理组
                    //    taskArgs.NextResource = "报价确认组";//下一个组
                    //    taskArgs.ActionRemarksType = "";
                    //    taskArgs.ActionRemarks = "";
                    //    taskArgs.Action = "已出报价合同,待确认";
                    //    p.Client.SavePartnerTask(SenderUser, taskArgs);
                    //}
                    #endregion
                }
                WriteSuccess();
            }
            catch (Exception ex)
            {
                WriteError(ex.Message, ex);
            }
        }