コード例 #1
0
        protected void lbtnSave_Click(object sender, EventArgs e)
        {
            string tourCode = Utils.InputText(this.txtTourCode.Value.Trim()); //团号

            #region 判断团号是否重复 by 田想兵 2011.8.30
            //将团号加入数组
            string[] tourCodes = new string[] { tourCode };
            //获得重复的数据集合
            IList <string> count = new EyouSoft.BLL.TourStructure.Tour().ExistsTourCodes(SiteUserInfo.CompanyID, EditId, tourCodes);
            if (count != null && count.Count > 0)
            {
                //如果该团号存在返回false
                Response.Write("<script>alert('该团号已存在!');location.href=location.href;</script>");
                return;
            }
            #endregion

            #region 成员变量
            decimal totalOutlay = 0.0M;
            decimal totalIncome = 0.0M;
            #endregion

            #region 获取参数
            int    VisitorNum        = Convert.ToInt32(Utils.InputText(txtPersonNum.Value.Trim().ToString()));
            string CustomerCompany   = Utils.InputText(txtCustomerCompany.Value.Trim());  //客户单位
            string CustomerCompanyId = Utils.InputText(hfSelectCustId.Value.Trim());      //客户单位编号
            string OrderNo           = Utils.InputText(txtOrderNo.Value.Trim());          //订单号
            string SalsId            = Utils.InputText(this.hfSaler.Value.Trim());        //销售员Id
            string ContactTel        = Utils.InputText(txtTel.Value.Trim());              //联系电话
            string VisitorAttachment = "";                                                //游客附件
            string ContactName       = Utils.InputText(this.txtContactName.Value.Trim()); //联系人
            string StartTime         = Utils.InputText(this.TxtStartTime.Value.Trim());   //委托出团日期
            if (Utils.GetFormValue(txtTotalOutlay.ClientID).Trim() != "")
            {
                totalOutlay = Utils.GetDecimal(Utils.GetFormValue(txtTotalOutlay.ClientID).Trim());
            }
            if (txtTotalIncome.Value.Trim().ToString() != "")
            {
                totalIncome = Utils.GetDecimal(txtTotalIncome.Value.Trim().ToString());
            }
            decimal GrossProfit = Utils.GetDecimal(txtGrossProfit.Value.Trim().ToString());//毛利
            #endregion

            #region   附件
            //确定是否有附件
            if (fuiLoadAttachment.PostedFile.ContentLength > 0)
            {
                string FileName = DateTime.Now.ToString("yyyy_MM_dd HH_mm_ss_") + Guid.NewGuid().ToString() + Path.GetExtension(fuiLoadAttachment.PostedFile.FileName);
                if (!Directory.Exists(Server.MapPath("/uploadFiles/SingleServe")))
                {
                    Directory.CreateDirectory(Server.MapPath("/uploadFiles/SingleServe"));
                }
                VisitorAttachment = "/uploadFiles/SingleServe/" + FileName;
                fuiLoadAttachment.PostedFile.SaveAs(Server.MapPath(VisitorAttachment));
            }
            else
            {
                VisitorAttachment = hFileInfo.Value;
            }
            #endregion

            #region 客户要求
            string[] CustomerItemArr        = Request.Form.GetValues("ddlGuestList");    //服务类别
            string[] CustomerServeDetailArr = Request.Form.GetValues("txtGuestRequest"); //具体要求
            string[] CustomerPriceItemArr   = Request.Form.GetValues("txtGPrice");       //价格
            string[] CusRemarks             = Request.Form.GetValues("txtGuestRemark");  //备注
            IList <TourSingleServiceInfo> CustomerServeList = null;                      //客户要求集合
            if (CustomerItemArr != null)
            {
                CustomerServeList = new List <TourSingleServiceInfo>();
                for (int i = 0; i < CustomerItemArr.Length; i++)
                {
                    if (!string.IsNullOrEmpty(CustomerItemArr[i].Trim()) || !string.IsNullOrEmpty(CustomerServeDetailArr[i].Trim()) || !string.IsNullOrEmpty(CustomerPriceItemArr[i].Trim()) || !string.IsNullOrEmpty(CusRemarks[i].Trim()))
                    {
                        TourSingleServiceInfo cModel = new TourSingleServiceInfo();
                        if (!string.IsNullOrEmpty(CustomerItemArr[i]))
                        {
                            cModel.ServiceType = (EyouSoft.Model.EnumType.TourStructure.ServiceType) int.Parse(CustomerItemArr[i].Trim());
                        }
                        if (!string.IsNullOrEmpty(CusRemarks[i]))
                        {
                            cModel.Remark = Utils.InputText(CusRemarks[i].Trim(), 450);
                        }
                        if (!string.IsNullOrEmpty(CustomerServeDetailArr[i]))
                        {
                            cModel.Requirement = Utils.InputText(CustomerServeDetailArr[i].Trim(), 450);
                        }
                        if (!string.IsNullOrEmpty(CustomerPriceItemArr[i]))
                        {
                            cModel.SelfPrice = Utils.GetDecimal(CustomerPriceItemArr[i].Trim(), 0);
                        }
                        CustomerServeList.Add(cModel);
                    }
                }
            }
            #endregion

            #region 供应商安排
            string[] SupplierItemArr        = Request.Form.GetValues("ddlSupperlierList");  //服务类别
            string[] SupplierServeDetailArr = Request.Form.GetValues("txtSupplierRequest"); //具体安排
            string[] SupplierPriceItemArr   = Request.Form.GetValues("txtAccountCost");     //结算费用
            string[] SupName                  = Request.Form.GetValues("txtSupperName");    //供应商名称
            string[] SupRemark                = Request.Form.GetValues("txtSupRemark");     //备注
            string[] SupPlanIdArr             = Request.Form.GetValues("hPlanID");          //供应商安排主键编号
            string[] SupperIdArr              = Request.Form.GetValues("hSupperID");        //供应商编号
            IList <PlanSingleInfo> SupperList = null;                                       //供应商集合
            if (SupplierItemArr != null)
            {
                SupperList = new List <PlanSingleInfo>();
                for (int i = 0; i < SupplierItemArr.Length; i++)
                {
                    if (!string.IsNullOrEmpty(SupplierItemArr[i].Trim()) || !string.IsNullOrEmpty(SupplierServeDetailArr[i].Trim()) || !string.IsNullOrEmpty(SupplierPriceItemArr[i].Trim()) || !string.IsNullOrEmpty(SupRemark[i].Trim()))
                    {
                        PlanSingleInfo pModel = new PlanSingleInfo();
                        if (SupPlanIdArr[i] != "0")
                        {
                            pModel.PlanId = SupPlanIdArr[i];
                        }
                        if (SupperIdArr[i] != "0")
                        {
                            pModel.SupplierId = int.Parse(SupperIdArr[i]);
                        }
                        if (!string.IsNullOrEmpty(SupplierItemArr[i]))
                        {
                            pModel.ServiceType = (EyouSoft.Model.EnumType.TourStructure.ServiceType) int.Parse(SupplierItemArr[i].Trim());
                        }
                        if (!string.IsNullOrEmpty(SupRemark[i]))
                        {
                            pModel.Remark = Utils.InputText(SupRemark[i].Trim(), 450);
                        }
                        if (!string.IsNullOrEmpty(SupplierServeDetailArr[i]))
                        {
                            pModel.Arrange = Utils.InputText(SupplierServeDetailArr[i].Trim(), 450);
                        }
                        if (!string.IsNullOrEmpty(SupName[i]))
                        {
                            pModel.SupplierName = Utils.InputText(SupName[i].Trim(), 100);
                        }
                        if (!string.IsNullOrEmpty(SupplierPriceItemArr[i]))
                        {
                            pModel.Amount = Utils.GetDecimal(SupplierPriceItemArr[i].Trim(), 0);//结算费用
                        }
                        pModel.CreateTime = DateTime.Now;
                        SupperList.Add(pModel);
                    }
                }
            }
            #endregion

            #region 游客信息
            string[] VisitorNameArr = Request.Form.GetValues("txtVisitorName");                                                               //游客姓名
            string[] VisitorTypeArr = Request.Form.GetValues("ddlVisitorType");                                                               //旅客类型
            string[] CardTypeArr    = Request.Form.GetValues("ddlCardType");                                                                  //证件类型
            string[] CardNoArr      = Request.Form.GetValues("txtCardNo");                                                                    //证件号
            string[] ContactTelArr  = Request.Form.GetValues("txtContactTel");                                                                //联系电话
            string[] SexArr         = Request.Form.GetValues("ddlSex");                                                                       //性别
            string[] ServeItemsArr  = Request.Form.GetValues("tefu");                                                                         //特服
            string[] VisitorIDArr   = Request.Form.GetValues("hidVisitorID");                                                                 //游客主键
            IList <EyouSoft.Model.TourStructure.TourOrderCustomer> VisitorList = new List <EyouSoft.Model.TourStructure.TourOrderCustomer>(); //游客信息集合
            if (VisitorNameArr != null)
            {
                for (int j = 0; j < VisitorNameArr.Length; j++)
                {
                    TourOrderCustomer tModel = new TourOrderCustomer();

                    if (EditId != "")//修改
                    {
                        if (string.IsNullOrEmpty(VisitorNameArr[j]))
                        {
                            continue;
                        }
                        tModel.IsDelete = false;//修改时 如果姓名为空  就忽略这条信息
                    }
                    else
                    {                                                 //新增
                        if (!string.IsNullOrEmpty(VisitorNameArr[j])) //游客姓名不为空
                        {
                            tModel.IsDelete = false;
                        }
                        else
                        {
                            tModel.IsDelete = true;//新增 如果游客姓名为空,就不存入数据库
                        }
                    }
                    #region 游客基本信息
                    if (!string.IsNullOrEmpty(VisitorIDArr[j]))
                    {
                        tModel.ID = VisitorIDArr[j];
                    }
                    else
                    {
                        tModel.ID = Guid.NewGuid().ToString();
                    }
                    //tModel.TicketStatus = EyouSoft.Model.EnumType.TourStructure.CustomerTicketStatus.正常;
                    tModel.CompanyID = SiteUserInfo.CompanyID;
                    if (!string.IsNullOrEmpty(VisitorNameArr[j]))
                    {
                        tModel.VisitorName = Utils.InputText(VisitorNameArr[j], 50);
                    }
                    if (!string.IsNullOrEmpty(ContactTelArr[j]))
                    {
                        tModel.ContactTel = Utils.InputText(ContactTelArr[j].Trim(), 12);
                    }
                    if (!string.IsNullOrEmpty(CardNoArr[j]))
                    {
                        tModel.CradNumber = Utils.InputText(CardNoArr[j].Trim(), 30);
                    }
                    tModel.CompanyID = this.SiteUserInfo.CompanyID;
                    if (!string.IsNullOrEmpty(CardTypeArr[j]))
                    {
                        tModel.CradType = (EyouSoft.Model.EnumType.TourStructure.CradType) int.Parse(CardTypeArr[j].Trim());
                    }
                    tModel.IssueTime = DateTime.Now;
                    if (!string.IsNullOrEmpty(SexArr[j]))
                    {
                        tModel.Sex = (EyouSoft.Model.EnumType.CompanyStructure.Sex) int.Parse(SexArr[j].Trim());
                    }
                    if (!string.IsNullOrEmpty(VisitorTypeArr[j]))
                    {
                        tModel.VisitorType = (EyouSoft.Model.EnumType.TourStructure.VisitorType) int.Parse(VisitorTypeArr[j].Trim());
                    }
                    #endregion

                    #region 游客特服信息
                    if (ServeItemsArr != null && !string.IsNullOrEmpty(ServeItemsArr[j]))
                    {
                        CustomerSpecialService SpecialServiceInfo = new CustomerSpecialService();
                        string[] ServiceItem = ServeItemsArr[j].Split('$');
                        SpecialServiceInfo.CustormerId = tModel.ID;
                        SpecialServiceInfo.IssueTime   = DateTime.Now;
                        int index = 0;
                        foreach (var item in ServiceItem)
                        {
                            if (!string.IsNullOrEmpty(item))
                            {
                                switch (index)
                                {
                                case 0:
                                    SpecialServiceInfo.ProjectName = Utils.InputText(item, 450);
                                    break;

                                case 1:
                                    SpecialServiceInfo.ServiceDetail = Utils.InputText(item, 450);
                                    break;

                                case 2:
                                    SpecialServiceInfo.Fee = Utils.GetDecimal(item);
                                    break;

                                case 3:
                                    SpecialServiceInfo.IsAdd = item == "0" ? true : false;
                                    break;
                                }
                            }
                            index++;
                        }
                        tModel.SpecialServiceInfo = SpecialServiceInfo;
                    }
                    #endregion

                    VisitorList.Add(tModel);
                    tModel = null;
                }
            }
            #endregion

            #region 成员变量
            EyouSoft.Model.TourStructure.TourSingleInfo model   = new EyouSoft.Model.TourStructure.TourSingleInfo();
            EyouSoft.BLL.TourStructure.Tour             tourBll = new EyouSoft.BLL.TourStructure.Tour(this.SiteUserInfo);
            #endregion

            //实体赋值
            if (model != null)
            {
                model.CreateTime          = DateTime.Now;                                        //发布时间
                model.BuyerCName          = CustomerCompany;                                     //客户单位名称
                model.TourCode            = tourCode;                                            //团号
                model.LDate               = DateTime.Parse(StartTime);                           //出团日期
                model.BuyerCId            = int.Parse(CustomerCompanyId);                        //客户单位编号
                model.CompanyId           = this.SiteUserInfo.CompanyID;                         //公司ID
                model.Plans               = SupperList;                                          //供应商安排集合
                model.Services            = CustomerServeList;                                   //客户要求集合
                model.Customers           = VisitorList;                                         //游客信息集合
                model.TotalAmount         = totalIncome;                                         //收入
                model.TotalOutAmount      = totalOutlay;                                         //支出
                model.TourType            = EyouSoft.Model.EnumType.TourStructure.TourType.单项服务; //团队类型
                model.VirtualPeopleNumber = 0;                                                   //虚拟实收

                model.ContacterMobile    = this.SiteUserInfo.ContactInfo.ContactMobile;
                model.ContacterTelephone = this.SiteUserInfo.ContactInfo.ContactTel;
                if (!string.IsNullOrEmpty(VisitorAttachment))
                {
                    model.CustomerDisplayType = EyouSoft.Model.EnumType.TourStructure.CustomerDisplayType.附件方式;
                }
                else
                {
                    model.CustomerDisplayType = EyouSoft.Model.EnumType.TourStructure.CustomerDisplayType.输入方式;
                }

                if (!string.IsNullOrEmpty(SalsId))
                {
                    if (SalsId.Split(',').Length > 0)
                    {
                        model.SellerId   = Utils.GetInt(SalsId.Split(',')[0]);
                        model.SellerName = this.selectOperator1.OperName.Split(',')[0];
                    }
                    else
                    {
                        model.SellerId   = Utils.GetInt(SalsId);
                        model.SellerName = this.selectOperator1.OperName;
                    }
                }
                model.PlanPeopleNumber   = VisitorNum;                        //游客人数
                model.GrossProfit        = GrossProfit;                       //毛利
                model.CustomerFilePath   = VisitorAttachment;                 //游客信息附件
                model.ContacterTelephone = ContactTel;                        //联系电话
                model.ContacterName      = ContactName;                       //联系人
                model.TourDays           = 0;
                model.OrderCode          = OrderNo;                           //订单号
                //model.LDate = DateTime.Now;
                model.OperatorId = this.SiteUserInfo.ID;                      //操作员
                if (EditId != "")
                {                                                             //修改操作
                    model.TourId    = EditId;                                 //团队编号
                    model.OBuyerCId = int.Parse(hfOBuyerId.Value.ToString()); //客户单位编号
                    if (tourBll.UpdateSingleTourInfo(model) > 0)
                    {
                        EyouSoft.Common.Function.MessageBox.ResponseScript(this, string.Format("alert('修改成功!');window.parent.Boxy.getIframeDialog('{0}').hide();window.parent.location='/SingleServe/SingleServeList.aspx';", Request.QueryString["iframeId"]));
                    }
                    else
                    {
                        EyouSoft.Common.Function.MessageBox.ResponseScript(this, string.Format("alert('修改失败!');window.parent.Boxy.getIframeDialog('{0}').hide();window.parent.location='/SingleServe/SingleServeList.aspx';", Request.QueryString["iframeId"]));
                    }
                }
                else
                {//新增操作
                    if (tourBll.InsertSingleTourInfo(model) > 0)
                    {
                        EyouSoft.Common.Function.MessageBox.ResponseScript(this, string.Format("alert('新增成功!');window.parent.Boxy.getIframeDialog('{0}').hide();window.parent.location='/SingleServe/SingleServeList.aspx';", Request.QueryString["iframeId"]));
                    }
                    else
                    {
                        EyouSoft.Common.Function.MessageBox.ResponseScript(this, string.Format("alert('修改失败!');window.parent.Boxy.getIframeDialog('{0}').hide();window.parent.location='/SingleServe/SingleServeList.aspx';", Request.QueryString["iframeId"]));
                    }
                }
            }
            //释放资源
            model   = null;
            tourBll = null;
        }