/// <summary>
        /// 保存暂支申请信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    if (this.AdvanceId > 0)
                    {
                        string ddTheAdvanceType = this.ddTheAdvanceType.SelectedValue.Trim();

                        //查询暂支单预计归还日期
                        var setting = base.SettingManager.GetSettingByName("AdvanceApplication.ForecastReturnTime");

                        if (setting != null)
                        {
                            //刷单暂支
                            if (ddTheAdvanceType == "343")
                            {
                                #region 根据店铺Id查询 所对应的项目,并查询出该项目所对应的所有店铺

                                int ProjectId = 0;
                                var NickId    = Convert.ToInt32(this.hfNickId.Value);
                                var XMNick    = base.XMNickService.GetXMNickByID(NickId);
                                if (XMNick != null)
                                {
                                    if (XMNick.ProjectId != null)
                                    {
                                        ProjectId = XMNick.ProjectId.Value;
                                    }
                                }

                                XMProject xMProject = new XMProject();

                                List <int> ProjectIdList = new List <int>(); //项目Id

                                List <int> NickIdList = new List <int>();    //项目下所有的 店铺Id
                                if (ProjectId > 0)
                                {
                                    ProjectIdList.Add(ProjectId);
                                    //所有店铺
                                    var XMNickProjectIdList = base.XMNickService.GetXMNickListByProjectId(ProjectIdList);
                                    //所有店铺Id
                                    NickIdList = XMNickProjectIdList.Select(p => p.nick_id).ToList();

                                    xMProject = base.XMProjectService.GetXMProjectById(ProjectId);
                                }
                                #endregion

                                List <AdvanceApplication> AdvanceApplicationList = new List <AdvanceApplication>();
                                if (NickIdList.Count > 0)
                                {
                                    var AdvanceApplicationListByNickId = base.AdvanceApplicationService.GetAdvanceApplicationListByNickId(NickIdList);

                                    if (AdvanceApplicationListByNickId.Count > 0)
                                    {
                                        AdvanceApplicationList = AdvanceApplicationListByNickId.Where(p => p.ForecastReturnTime < DateTime.Now.AddDays(1) && p.AdvanceState == (int)AdvanceStateEnum.TheAdvanceUse).ToList();
                                    }
                                }

                                if (AdvanceApplicationList.Count > 0)
                                {
                                    string ProjectName = "";

                                    if (xMProject != null)
                                    {
                                        ProjectName = xMProject.ProjectName;
                                    }
                                    base.ShowMessage(ProjectName + "项目有其它店铺未在归还日期内还款,请先还款!");
                                    return;
                                }
                                else
                                {
                                    #region 修改
                                    string ddApplicationDepartment = this.ddApplicationDepartment.SelectedValue.Trim();
                                    string txtApplicationPayee     = this.txtApplicationPayee.Text;
                                    string txtTheAdvanceSubject    = this.txtTheAdvanceSubject.Text;
                                    string txtTheAdvanceMoney      = this.txtTheAdvanceMoney.Text;
                                    //string lblForecastReturnTime = this.lblForecastReturnTime.Text.Trim();
                                    string txtSubject    = this.txtSubject.Text;
                                    int    txtApplicants = this.txtApplicants.SelectSingleCustomer.CustomerID;// this.txtApplicants.Text;

                                    //判断刷单单号否有效
                                    this.lblMag.Visible = false;
                                    int scalpingId = 0;
                                    int.TryParse(this.hfScalpingId.Value, out scalpingId);
                                    if (ddTheAdvanceType == "343")
                                    {
                                        var scalping = base.XMScalpingApplicationService.GetXMScalpingApplicationByScalpingId(scalpingId);
                                        if (scalping == null)
                                        {
                                            this.lblMag.Visible         = true;
                                            this.lblMag.Text            = "刷单单号有误";
                                            this.hfScalpingId.Value     = "";
                                            this.txtScalpingCode.Value  = "";
                                            this.hfNickId.Value         = "";
                                            this.txtNickName.Text       = "";
                                            this.hfPlatformTypeId.Value = "";
                                            this.txtPlatformType.Text   = "";
                                            ScriptManager.RegisterStartupScript(this.txtScalpingCode, this.Page.GetType(), "advanceApplicationDetailManage", "autoCompleteBindScalpingCodeManag()", true);
                                            return;
                                        }
                                    }

                                    //暂支申请主表信息
                                    AdvanceApplication advanceApplication = base.AdvanceApplicationService.GetAdvanceApplicationById(this.AdvanceId);

                                    if (advanceApplication != null)
                                    {
                                        //判断是否重复
                                        var AdvanceApplicationListByScalpingId = base.AdvanceApplicationService.GetAdvanceApplicationByScalpingId(scalpingId);
                                        if (AdvanceApplicationListByScalpingId.Count > 0)
                                        {
                                            if (AdvanceApplicationListByScalpingId[0].ScalpingId != advanceApplication.ScalpingId)
                                            {
                                                this.lblMag.Visible         = true;
                                                this.lblMag.Text            = "刷单单号已存在";
                                                this.hfScalpingId.Value     = "";
                                                this.txtScalpingCode.Value  = "";
                                                this.hfNickId.Value         = "";
                                                this.txtNickName.Text       = "";
                                                this.hfPlatformTypeId.Value = "";
                                                this.txtPlatformType.Text   = "";
                                                ScriptManager.RegisterStartupScript(this.txtScalpingCode, this.Page.GetType(), "advanceApplicationDetailManage", "autoCompleteBindScalpingCodeManag()", true);
                                                return;
                                            }
                                        }
                                        if (ddTheAdvanceType == "343")
                                        {
                                            advanceApplication.PlatformTypeId = Convert.ToInt32(this.hfPlatformTypeId.Value);
                                            advanceApplication.NickId         = Convert.ToInt32(this.hfNickId.Value);
                                            advanceApplication.ScalpingId     = Convert.ToInt32(scalpingId);
                                        }
                                        advanceApplication.TheAdvanceType        = Convert.ToInt32(ddTheAdvanceType);
                                        advanceApplication.ApplicationDepartment = Convert.ToInt32(ddApplicationDepartment);
                                        advanceApplication.ApplicationPayee      = txtApplicationPayee;
                                        advanceApplication.TheAdvanceSubject     = txtTheAdvanceSubject;
                                        advanceApplication.TheAdvanceMoney       = Convert.ToDecimal(txtTheAdvanceMoney);
                                        //if (lblForecastReturnTime != "")
                                        //{
                                        //    advanceApplication.ForecastReturnTime = Convert.ToDateTime(lblForecastReturnTime);
                                        //}
                                        advanceApplication.Subject    = txtSubject;
                                        advanceApplication.Applicants = txtApplicants;
                                        advanceApplication.UpdatorID  = HozestERPContext.Current.User.CustomerID;
                                        advanceApplication.UpdateTime = DateTime.Now;

                                        base.AdvanceApplicationService.UpdateAdvanceApplication(advanceApplication);
                                        base.ShowMessage("保存成功");
                                        loadDate();
                                        ScriptManager.RegisterStartupScript(this.txtScalpingCode, this.Page.GetType(), "advanceApplicationDetailManage", "autoCompleteBindScalpingCodeManag()", true);
                                    }

                                    #endregion
                                }
                            }
                            else
                            {
                                #region 修改
                                string ddApplicationDepartment = this.ddApplicationDepartment.SelectedValue.Trim();
                                string txtApplicationPayee     = this.txtApplicationPayee.Text;
                                string txtTheAdvanceSubject    = this.txtTheAdvanceSubject.Text;
                                string txtTheAdvanceMoney      = this.txtTheAdvanceMoney.Text;
                                //string lblForecastReturnTime = this.lblForecastReturnTime.Text.Trim();
                                string txtSubject    = this.txtSubject.Text;
                                int    txtApplicants = this.txtApplicants.SelectSingleCustomer.CustomerID;// this.txtApplicants.Text;

                                //暂支申请主表信息
                                AdvanceApplication advanceApplication = base.AdvanceApplicationService.GetAdvanceApplicationById(this.AdvanceId);

                                if (advanceApplication != null)
                                {
                                    advanceApplication.PlatformTypeId        = null;
                                    advanceApplication.NickId                = null;
                                    advanceApplication.ScalpingId            = null;
                                    advanceApplication.TheAdvanceType        = Convert.ToInt32(ddTheAdvanceType);
                                    advanceApplication.ApplicationDepartment = Convert.ToInt32(ddApplicationDepartment);
                                    advanceApplication.ApplicationPayee      = txtApplicationPayee;
                                    advanceApplication.TheAdvanceSubject     = txtTheAdvanceSubject;
                                    advanceApplication.TheAdvanceMoney       = Convert.ToDecimal(txtTheAdvanceMoney);
                                    //if (lblForecastReturnTime != "")
                                    //{
                                    //    advanceApplication.ForecastReturnTime = Convert.ToDateTime(lblForecastReturnTime);
                                    //}
                                    advanceApplication.Subject    = txtSubject;
                                    advanceApplication.Applicants = txtApplicants;
                                    advanceApplication.UpdatorID  = HozestERPContext.Current.User.CustomerID;
                                    advanceApplication.UpdateTime = DateTime.Now;
                                    base.AdvanceApplicationService.UpdateAdvanceApplication(advanceApplication);
                                    base.ShowMessage("保存成功");
                                    loadDate();
                                    ScriptManager.RegisterStartupScript(this.txtScalpingCode, this.Page.GetType(), "advanceApplicationDetailManage", "autoCompleteBindScalpingCodeManag()", true);
                                }
                                #endregion
                            }
                        }
                        else
                        {
                            base.ShowMessage("请联系管理员设置暂支预计归还天数!");
                            return;
                        }
                    }
                }
                catch (Exception err)
                {
                    this.ProcessException(err);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 记录行 操作
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvXMProjectList_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int Id = 0;

            if (int.TryParse(this.gvXMProjectList.DataKeys[e.RowIndex].Value.ToString(), out Id))
            {
                var row = this.gvXMProjectList.Rows[e.RowIndex];

                #region 字符验证
                //产品名称
                var     txtProjectName                = row.FindControl("txtProjectName") as TextBox;
                var     lblMsgProjectNameVaule        = row.FindControl("lblMsgProjectNameVaule") as Label;
                var     lblProjectName                = row.FindControl("lblProjectName") as Label;
                var     lblMsgShipmentProportionVaule = row.FindControl("lblMsgShipmentProportionVaule") as Label;
                var     ccProjectTypeId               = row.FindControl("ccProjectTypeId") as CodeControl;
                var     chkIsEnable        = row.FindControl("chkIsEnable") as CheckBox;
                var     ddlDepartment      = row.FindControl("ddlDepartment") as DropDownList;
                var     ShipmentProportion = row.FindControl("txtShipmentProportion") as TextBox;
                decimal paramparse2        = 0;
                lblMsgProjectNameVaule.Text = "";
                if (txtProjectName.Text.Trim() == "")
                {
                    lblMsgProjectNameVaule.Text = "不允许为空";
                }

                //负责人
                SelectSingleCustomerControl txtcustomerId = (SelectSingleCustomerControl)row.FindControl("txtcustomerId");
                //客户
                SelectSingleCustomerControl txtClientId = (SelectSingleCustomerControl)row.FindControl("txtClientId");

                //备注
                var txtRemark = row.FindControl("txtRemark") as TextBox;

                if (lblMsgProjectNameVaule.Text != "")
                {
                    return;
                }

                #endregion


                var xMProject = base.XMProjectService.GetXMProjectById(Id);

                var xMProjectList = base.XMProjectService.GetXMProjectList(txtProjectName.Text.Trim(), -1, -1);


                if (xMProject != null)
                {
                    if ((!txtProjectName.Text.Trim().Equals(lblProjectName.Text.Trim())) && xMProjectList.Count > 0)
                    {
                        base.ShowMessage("该项目名称已存在");
                        return;
                    }
                    xMProject.ProjectName   = txtProjectName.Text.Trim();
                    xMProject.ProjectTypeId = ccProjectTypeId.SelectedValue;
                    xMProject.customerId    = txtcustomerId.SelectSingleCustomer.CustomerID;
                    if (decimal.TryParse(ShipmentProportion.Text.Trim(), out paramparse2))
                    {
                        xMProject.ShipmentProportion = decimal.Parse(ShipmentProportion.Text.Trim());
                    }
                    else
                    {
                        xMProject.ShipmentProportion = 0;
                    }
                    if (txtClientId != null)
                    {
                        if (txtClientId.SelectSingleCustomer != null)
                        {
                            xMProject.ClientId = txtClientId.SelectSingleCustomer.CustomerID;
                        }
                    }
                    if (txtRemark.Text.Trim() != "")
                    {
                        xMProject.Remark = txtRemark.Text.Trim();
                    }
                    else
                    {
                        xMProject.Remark = "";
                    }
                    xMProject.DepartmentID = int.Parse(ddlDepartment.SelectedValue.Trim());
                    if (!chkIsEnable.Checked && (bool)xMProject.IsEnable)
                    {
                        var NickList = base.XMNickService.GetXMNickListByProjectId(xMProject.Id);
                        if (NickList != null && NickList.Count > 0)
                        {
                            foreach (XMNick info in NickList)
                            {
                                info.isEnable     = false;
                                info.updatePerson = HozestERPContext.Current.User.CustomerID.ToString();
                                info.updateTime   = DateTime.Now;
                                base.XMNickService.UpdateXMNick(info);
                            }
                        }
                    }

                    xMProject.IsEnable   = chkIsEnable.Checked;//是否在运营
                    xMProject.UpdateID   = HozestERPContext.Current.User.CustomerID;
                    xMProject.UpdateDate = DateTime.Now;
                    base.XMProjectService.UpdateXMProject(xMProject);
                }
                else
                {
                    if (xMProjectList.Count > 0)
                    {
                        base.ShowMessage("该项目名称已存在");
                        return;
                    }
                    xMProject = new XMProject();

                    xMProject.ProjectName   = txtProjectName.Text.Trim();
                    xMProject.ProjectTypeId = ccProjectTypeId.SelectedValue;
                    xMProject.customerId    = txtcustomerId.SelectSingleCustomer.CustomerID;
                    if (txtClientId != null)
                    {
                        if (txtClientId.SelectSingleCustomer != null)
                        {
                            xMProject.ClientId = txtClientId.SelectSingleCustomer.CustomerID;
                        }
                    }
                    if (txtRemark.Text.Trim() != "")
                    {
                        xMProject.Remark = txtRemark.Text.Trim();
                    }
                    else
                    {
                        xMProject.Remark = "";
                    }
                    xMProject.DepartmentID = int.Parse(ddlDepartment.SelectedValue.Trim());
                    xMProject.IsEnable     = chkIsEnable.Checked;//是否在运营
                    xMProject.CreateID     = HozestERPContext.Current.User.CustomerID;
                    xMProject.CreateDate   = DateTime.Now;
                    xMProject.UpdateID     = HozestERPContext.Current.User.CustomerID;
                    xMProject.UpdateDate   = DateTime.Now;
                    base.XMProjectService.InsertXMProject(xMProject);
                }
                // SelectSingleCustomer //this.SelectSingleCustomer = null;

                Session["OperationCustomerCustomerStatus"] = null;

                Session["OperationClientCustomerStatus"] = null;

                this.RowEditIndex = -1;
                this.BindGrid(this.Master.PageIndex, this.Master.PageSize);
            }
        }
        protected void btnCalculate_Click(object sender, DirectEventArgs e)
        {
            string OrderID = CommonHelper.QueryString("ID");

            XMOrderInfo entity_Order = XMOrderInfoService.GetXMOrderInfoByID(int.Parse(OrderID));

            if (entity_Order == null)
            {
                ExtNet.Msg.Alert("提示", "订单信息不存在").Show();
                return;
            }

            XMProject entity_Project = XMProjectService.GetXMProjectById(entity_Order.ProjectId);

            if (entity_Project == null)
            {
                ExtNet.Msg.Alert("提示", "项目信息不存在").Show();
                return;
            }

            if (entity_Project.ProjectName == "曲美")
            {
                //干线费用
                decimal mainMoney = 0;
                //支线费用
                decimal  branchMoney = 0;
                string   province    = entity_Order.Province;
                string   city        = entity_Order.City;
                string   region      = entity_Order.County;
                string[] mes         = entity_Order.CustomerServiceRemark.Split(new string[] { "///" }, StringSplitOptions.RemoveEmptyEntries);
                if (mes.Count() <= 0)
                {
                    ExtNet.Msg.Alert("提示", "解析错误").Show();
                    return;
                }
                string[] mes1 = mes[0].Split(new string[] { "+" }, StringSplitOptions.RemoveEmptyEntries);
                if (mes1.Count() <= 0)
                {
                    ExtNet.Msg.Alert("提示", "解析错误").Show();
                    return;
                }
                //查询干线物流公司信息
                List <CodeList> codeList = CodeService.GetCodeListInfoByCodeTypeIDAndCodeName(243, mes1[0]);
                if (codeList.Count <= 0)
                {
                    ExtNet.Msg.Alert("提示", "找不到干线物流公司信息").Show();
                    return;
                }

                int logisticsMainID = codeList[0].CodeID;
                //查询干线物流单价费率
                BusinessLogic.ManageProject.XMLogisticsFeeMain entityMain = XMLogisticsFeeMainService.
                                                                            getSingle(a => a.ProjectID == entity_Project.Id && a.WareHouseID == 758 && province.StartsWith(a.Province) && city.StartsWith(a.City) && region.StartsWith(a.Area) && a.LogisticsID == logisticsMainID);
                if (entityMain == null)
                {
                    ExtNet.Msg.Alert("提示", "找不到对应干线单价费率").Show();
                    return;
                }

                //只计算干线费用
                if (mes1.Count() == 1)
                {
                    //对应干线单价费率
                    decimal main = (decimal)entityMain.Fee;

                    List <XMOrderInfoProductDetails> list_OrderProductDetails = XMOrderInfoProductDetailsService.GetXMOrderInfoProductDetailsList(entity_Order.ID);
                    foreach (var item in list_OrderProductDetails)
                    {
                        string ProductVolume = string.IsNullOrEmpty(item.ProductVolume) ? "0" : item.ProductVolume;
                        mainMoney = mainMoney + main * decimal.Parse(ProductVolume) * (int)item.ProductNum;
                    }
                }
                //计算干线和支线费用
                else if (mes1.Count() == 2)
                {
                    //对应干线单价费率
                    decimal main = (decimal)entityMain.Fee;
                    //查询支线物流公司信息
                    List <CodeList> codeList1 = CodeService.GetCodeListInfoByCodeTypeIDAndCodeName(244, mes1[1]);
                    if (codeList.Count <= 0)
                    {
                        ExtNet.Msg.Alert("提示", "找不到支线物流公司信息").Show();
                        return;
                    }

                    List <XMOrderInfoProductDetails> list_OrderProductDetails = XMOrderInfoProductDetailsService.GetXMOrderInfoProductDetailsList(entity_Order.ID);
                    foreach (var item in list_OrderProductDetails)
                    {
                        //对应支线单价费率
                        decimal          Branch               = 0;
                        XMProduct        entityProduct        = XMProductService.getXMProductByManufacturersCode(item.TManufacturersCode);
                        XMProductDetails entityProductDetails = XMProductDetailsService.GetXMProductDetailsListByProductId(entityProduct.Id)[0];
                        //查询支线物流单价费率
                        int logisticsBranchID = codeList1[0].CodeID;
                        BusinessLogic.ManageProject.XMLogisticsFeeBranch entityBranch = XMLogisticsFeeBranchService.
                                                                                        getSingle(a => a.ProjectID == entity_Project.Id && a.LogisticsID == logisticsBranchID && a.ProductCategoryID == entityProductDetails.ProductTypeId);
                        if (entityBranch == null)
                        {
                            ExtNet.Msg.Alert("提示", "找不到对应支线单价费率").Show();
                            return;
                        }

                        Branch = (decimal)entityBranch.Fee;
                        //商品体积
                        string ProductVolume = string.IsNullOrEmpty(entityProduct.ProductVolume) ? "0" : entityProduct.ProductVolume;
                        mainMoney   = mainMoney + main * decimal.Parse(ProductVolume) * (int)item.ProductNum;
                        branchMoney = branchMoney + Branch * (int)item.ProductNum;
                    }
                }
                //事务
                using (TransactionScope scope = new TransactionScope())
                {
                    List <BusinessLogic.ManageProject.XMLogisticsFeeDetail> list = XMLogisticsFeeDetailService.getList(a => a.Type != 3);
                    foreach (var item in list)
                    {
                        XMLogisticsFeeDetailService.delete(item);
                    }

                    if (mainMoney >= 0)
                    {
                        XMLogisticsFeeDetailService.InsertXMLogisticsFeeDetail(new BusinessLogic.ManageProject.XMLogisticsFeeDetail()
                        {
                            OrderID    = entity_Order.ID,
                            Type       = 1,
                            Fee        = mainMoney,
                            CreateID   = HozestERPContext.Current.User.CustomerID,
                            CreateDate = DateTime.Now,
                        });
                    }
                    if (branchMoney >= 0)
                    {
                        XMLogisticsFeeDetailService.InsertXMLogisticsFeeDetail(new BusinessLogic.ManageProject.XMLogisticsFeeDetail()
                        {
                            OrderID    = entity_Order.ID,
                            Type       = 2,
                            Fee        = branchMoney,
                            CreateID   = HozestERPContext.Current.User.CustomerID,
                            CreateDate = DateTime.Now,
                        });
                    }

                    scope.Complete();
                }
            }
            else
            {
                ExtNet.Msg.Alert("提示", "不在计算范围内").Show();
                return;
            }
        }