Ejemplo n.º 1
0
 /// <summary>
 /// 批量插入邮件
 /// </summary>
 /// <param name="custId"></param>
 /// <param name="tels"></param>
 public void Insert(string custId, string emails)
 {
     string[] emailArry = emails.Split(',');
     foreach (string email in emailArry)
     {
         Entities.CustEmail model = new Entities.CustEmail();
         model.CreateTime   = DateTime.Now;
         model.CreateUserID = BLL.Util.GetLoginUserID();
         model.CustID       = custId;
         model.Email        = email;
         BLL.CustEmail.Instance.Insert(model);
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        ///  更新一条数据
        /// </summary>
        public int Update(Entities.CustEmail model)
        {
            SqlParameter[] parameters =
            {
                new SqlParameter("@CustID",       SqlDbType.VarChar,   20),
                new SqlParameter("@Email",        SqlDbType.VarChar,   50),
                new SqlParameter("@CreateTime",   SqlDbType.DateTime),
                new SqlParameter("@CreateUserID", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.CustID;
            parameters[1].Value = model.Email;
            parameters[2].Value = model.CreateTime;
            parameters[3].Value = model.CreateUserID;

            return(SqlHelper.ExecuteNonQuery(CONNECTIONSTRINGS, CommandType.StoredProcedure, P_CUSTEMAIL_UPDATE, parameters));
        }
Ejemplo n.º 3
0
        public void Insert(SqlTransaction sqltran, Entities.CustEmail model)
        {
            SqlParameter[] parameters =
            {
                new SqlParameter("@CustID",       SqlDbType.VarChar,   20),
                new SqlParameter("@Email",        SqlDbType.VarChar,   50),
                new SqlParameter("@CreateTime",   SqlDbType.DateTime),
                new SqlParameter("@CreateUserID", SqlDbType.Int, 4)
            };
            parameters[0].Value = model.CustID;
            parameters[1].Value = model.Email;
            parameters[2].Value = model.CreateTime;
            parameters[3].Value = model.CreateUserID;

            SqlHelper.ExecuteNonQuery(sqltran, CommandType.StoredProcedure, P_CUSTEMAIL_INSERT, parameters);
        }
Ejemplo n.º 4
0
        private Entities.CustEmail LoadSingleCustEmail(DataRow row)
        {
            Entities.CustEmail model = new Entities.CustEmail();

            model.CustID = row["CustID"].ToString();
            model.Email  = row["Email"].ToString();
            if (row["CreateTime"].ToString() != "")
            {
                model.CreateTime = DateTime.Parse(row["CreateTime"].ToString());
            }
            if (row["CreateUserID"].ToString() != "")
            {
                model.CreateUserID = int.Parse(row["CreateUserID"].ToString());
            }
            return(model);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public int Update(Entities.CustEmail model)
 {
     return(Dal.CustEmail.Instance.Update(model));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public void Insert(SqlTransaction sqltran, Entities.CustEmail model)
 {
     Dal.CustEmail.Instance.Insert(sqltran, model);
 }
Ejemplo n.º 7
0
/// <summary>
        /// 增加一条数据
        /// </summary>
        public void Insert(Entities.CustEmail model)
        {
            Dal.CustEmail.Instance.Insert(model);
        }
        /// <summary>
        /// 校验
        /// </summary>
        private bool Valid(int rowNum, IDataReader reader, out StringBuilder ex, int userid, out StringBuilder exportstr)
        {
            ex        = new StringBuilder();
            exportstr = new StringBuilder();

            string UserName = string.Empty;

            UserName = reader[0].ToString().Trim();

            string Sex = string.Empty;

            Sex = reader[1].ToString().Trim();

            string Tel1 = string.Empty;

            Tel1 = reader[2].ToString().Trim();

            string CustCategory = string.Empty;

            CustCategory = reader[3].ToString().Trim();

            string Tel2 = string.Empty;

            Tel2 = reader[4].ToString().Trim();

            string Email = string.Empty;

            Email = reader[5].ToString().Trim();

            string Province = string.Empty;

            Province = reader[6].ToString().Trim();

            string City = string.Empty;

            City = reader[7].ToString().Trim();

            string County = string.Empty;

            County = reader[8].ToString().Trim();

            string Address = string.Empty;

            Address = reader[9].ToString().Trim();

            string DataSource = string.Empty;

            DataSource = reader[10].ToString().Trim();
            //咨询类型
            string EnquiryType = string.Empty;

            EnquiryType = reader[11].ToString().Trim();


            string Brand = string.Empty;

            Brand = reader[12].ToString().Trim();

            string Models = string.Empty;

            Models = reader[13].ToString().Trim();

            //推荐经销商名称
            string DealerName = string.Empty;

            DealerName = reader[14].ToString().Trim();

            //来电记录
            string PhoneRecord = string.Empty;

            PhoneRecord = reader[15].ToString().Trim();

            bool insertflag = true;



            //会员ID号验证
            if (string.IsNullOrEmpty(UserName) || UserName.Length == 0)
            {
                ex.Append("[姓名]不可为空。");
                insertflag = false;
            }
            else
            {
                if (BLL.Util.GetLength(UserName) > 50)
                {
                    ex.Append("[姓名]超长。");
                    insertflag = false;
                }
            }
            if (string.IsNullOrEmpty(Sex) || Sex.Length == 0)
            {
                ex.Append("[性别]不可为空。");
                insertflag = false;
            }
            else
            {
                if (Sex != "男" && Sex != "女")
                {
                    ex.Append("[性别]输入错误。");
                    insertflag = false;
                }
            }
            if (string.IsNullOrEmpty(Tel1) || Tel1.Length == 0)
            {
                ex.Append("[电话1]不可为空。");
                insertflag = false;
            }
            else
            {
                if (BLL.Util.IsTelephone(Tel1) == false && BLL.Util.IsHandset(Tel1) == false)
                {
                    ex.Append("[电话]输入错误。");
                    insertflag = false;
                }
            }

            if (string.IsNullOrEmpty(CustCategory) || CustCategory.Length == 0)
            {
                ex.Append("[客户分类]不可为空。");
                insertflag = false;
            }
            else
            {
                if (CustCategory != "已购车" && CustCategory != "未购车" && CustCategory != "经销商")
                {
                    ex.Append("[客户分类]输入错误。");
                    insertflag = false;
                }
            }
            if (!string.IsNullOrEmpty(Tel2))
            {
                if (BLL.Util.IsTelephone(Tel2) == false && BLL.Util.IsHandset(Tel2) == false)
                {
                    ex.Append("[电话2]输入错误。");
                    insertflag = false;
                }
            }
            if (!string.IsNullOrEmpty(Email))
            {
                if (BLL.Util.IsEmail(Email) == false)
                {
                    ex.Append("[邮箱]输入错误。");
                    insertflag = false;
                }
            }
            if (!string.IsNullOrEmpty(Address))
            {
                if (BLL.Util.GetLength(Address) > 200)
                {
                    ex.Append("[地址]超长。");
                    insertflag = false;
                }
            }

            if (!string.IsNullOrEmpty(DataSource))
            {
                if (DataSource != "呼叫中心" && DataSource != "在线" && DataSource != "汽车通" && DataSource != "车易通")
                {
                    ex.Append("[数据来源]输入错误。");
                    insertflag = false;
                }
            }

            if (!string.IsNullOrEmpty(EnquiryType))
            {
                if (EnquiryType != "新车" && EnquiryType != "二手车" && EnquiryType != "个人反馈" && EnquiryType != "活动" && EnquiryType != "个人用车" && EnquiryType != "个人其他" && EnquiryType != "经销商合作" && EnquiryType != "经销商反馈" && EnquiryType != "经销商其他")
                {
                    ex.Append("[咨询类型]输入错误。");
                    insertflag = false;
                }
            }
            if (!string.IsNullOrEmpty(DealerName))
            {
                if (BLL.Util.GetLength(DealerName) > 200)
                {
                    ex.Append("[推荐经销商]超长。");
                    insertflag = false;
                }
            }
            if (!string.IsNullOrEmpty(PhoneRecord))
            {
                if (BLL.Util.GetLength(PhoneRecord) > 2000)
                {
                    ex.Append("[来电记录]超长。");
                    insertflag = false;
                }
            }
            string provinceID = "0";

            //验证省份城市
            if (!string.IsNullOrEmpty(Province))
            {
                provinceID = BitAuto.YanFa.Crm2009.BLL.AreaInfo.Instance.GetAreaIdByName(Province, 1);
                if (provinceID == "0")
                {
                    ex.Append("[地区(省)]输入错误。");
                    insertflag = false;
                }
            }
            string CityID = "0";

            //验证省份城市
            if (!string.IsNullOrEmpty(City))
            {
                CityID = BitAuto.YanFa.Crm2009.BLL.AreaInfo.Instance.GetAreaIdByName(City, 2);
                if (CityID == "0")
                {
                    ex.Append("[地区(市)]输入错误。");
                    insertflag = false;
                }
            }
            string CountryID = "0";

            //验证区县
            if (!string.IsNullOrEmpty(County))
            {
                CountryID = BitAuto.YanFa.Crm2009.BLL.AreaInfo.Instance.GetAreaIdByName(County, 3);
                if (CountryID == "0")
                {
                    ex.Append("[地区(区县)]输入错误。");
                    insertflag = false;
                }
            }
            //验证车型
            string BrandID = "0";

            if (!string.IsNullOrEmpty(Brand))
            {
                DataTable dt = BLL.BuyCarInfo.Instance.GetCarBrandByName(Brand);
                if (dt != null && dt.Rows.Count > 0)
                {
                    BrandID = dt.Rows[0]["Brandid"].ToString();
                }
                else
                {
                    ex.Append("[品牌]输入错误。");
                    insertflag = false;
                }
            }

            //验证车系
            string CarModelsID = "0";

            if (!string.IsNullOrEmpty(Models))
            {
                DataTable dt = BLL.BuyCarInfo.Instance.GetCarSerialByName(Models);
                if (dt != null && dt.Rows.Count > 0)
                {
                    CarModelsID = dt.Rows[0]["serialid"].ToString();
                }
                else
                {
                    ex.Append("[车系]输入错误。");
                    insertflag = false;
                }
            }

            //如果验证通过,插入
            if (insertflag)
            {
                bool flag = false;
                flag = BLL.CustBasicInfo.Instance.IsExistsByCustNameAndTel(UserName, Tel1);

                if (flag)
                {
                    ex.Append("记录[姓名],[电话1]已存在。");
                    insertflag = false;
                }
                else
                {
                    Entities.CustBasicInfo CustBasicInfoModel = new Entities.CustBasicInfo();
                    CustBasicInfoModel.Status       = 0;
                    CustBasicInfoModel.CustName     = UserName;
                    CustBasicInfoModel.Sex          = (Sex == "男" ? 1 : 2);
                    CustBasicInfoModel.CreateTime   = System.DateTime.Now;
                    CustBasicInfoModel.CreateUserID = userid;
                    if (CustCategory == "已购车")
                    {
                        CustBasicInfoModel.CustCategoryID = 1;
                    }
                    else if (CustCategory == "未购车")
                    {
                        CustBasicInfoModel.CustCategoryID = 2;
                    }
                    else
                    {
                        CustBasicInfoModel.CustCategoryID = 3;
                    }
                    if (provinceID != "0")
                    {
                        CustBasicInfoModel.ProvinceID = Convert.ToInt32(provinceID);
                    }
                    if (CityID != "0")
                    {
                        CustBasicInfoModel.CityID = Convert.ToInt32(CityID);
                    }
                    if (CountryID != "0")
                    {
                        CustBasicInfoModel.CountyID = Convert.ToInt32(CountryID);
                    }

                    if (!string.IsNullOrEmpty(Address))
                    {
                        CustBasicInfoModel.Address = Address;
                    }

                    if (!string.IsNullOrEmpty(DataSource))
                    {
                        if (DataSource == "呼叫中心")
                        {
                            CustBasicInfoModel.DataSource = 180001;
                        }
                        else if (DataSource == "在线")
                        {
                            CustBasicInfoModel.DataSource = 180002;
                        }
                        else if (DataSource == "汽车通")
                        {
                            CustBasicInfoModel.DataSource = 180003;
                        }
                        else if (DataSource == "车易通")
                        {
                            CustBasicInfoModel.DataSource = 180004;
                        }
                    }
                    string CustID = string.Empty;
                    int    rerVal = 0;
                    //客户历史记录信息主键
                    int custhistoryVal = 0;
                    try
                    {
                        //功能废弃
                        CustID = null;// BLL.CustBasicInfo.Instance.Insert(CustBasicInfoModel);
                        Entities.CustTel custTel1 = new Entities.CustTel();
                        //电话去掉‘-’

                        if (Tel1.IndexOf('-') > 0)
                        {
                            custTel1.Tel = Tel1.Remove(Tel1.IndexOf('-'), 1);
                        }
                        else
                        {
                            custTel1.Tel = Tel1;
                        }


                        custTel1.CustID       = CustID;
                        custTel1.CreateTime   = System.DateTime.Now;
                        custTel1.CreateUserID = userid;
                        BLL.CustTel.Instance.Insert(custTel1);
                        Entities.CustTel custTel2 = null;
                        if (!string.IsNullOrEmpty(Tel2))
                        {
                            custTel2 = new Entities.CustTel();
                            if (Tel2.IndexOf('-') > 0)
                            {
                                custTel2.Tel = Tel2.Remove(Tel2.IndexOf('-'), 1);
                            }
                            else
                            {
                                custTel2.Tel = Tel2;
                            }
                            custTel2.CustID       = CustID;
                            custTel2.CreateTime   = System.DateTime.Now;
                            custTel2.CreateUserID = userid;
                            BLL.CustTel.Instance.Insert(custTel2);
                        }
                        Entities.CustEmail custemail = null;
                        if (!string.IsNullOrEmpty(Email))
                        {
                            custemail              = new Entities.CustEmail();
                            custemail.Email        = Email;
                            custemail.CustID       = CustID;
                            custemail.CreateTime   = System.DateTime.Now;
                            custemail.CreateUserID = userid;
                            BLL.CustEmail.Instance.Insert(custemail);
                        }

                        //if (EnquiryType != "新车" && EnquiryType != "二手车" && EnquiryType != "个人反馈" && EnquiryType != "活动" && EnquiryType != "个人用车" && EnquiryType != "个人其他" && EnquiryType != "经销商合作" && EnquiryType != "经销商反馈" && EnquiryType != "经销商其他")

                        Entities.CustHistoryInfo CustHistoryInfoModel = null;

                        if (EnquiryType == "新车")
                        {
                            Entities.ConsultNewCar ConsultNewCarModel = new Entities.ConsultNewCar();
                            ConsultNewCarModel.CustID = CustID;
                            if (BrandID != "0")
                            {
                                ConsultNewCarModel.CarBrandId = Convert.ToInt32(BrandID);
                            }
                            if (CarModelsID != "0")
                            {
                                ConsultNewCarModel.CarSerialId = Convert.ToInt32(CarModelsID);
                            }
                            if (!string.IsNullOrEmpty(DealerName))
                            {
                                ConsultNewCarModel.DealerName = DealerName;
                            }
                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultNewCarModel.CallRecord = PhoneRecord;
                            }
                            ConsultNewCarModel.CreateTime   = System.DateTime.Now;
                            ConsultNewCarModel.CreateUserID = userid;
                            rerVal = BLL.ConsultNewCar.Instance.Insert(ConsultNewCarModel);

                            CustHistoryInfoModel = new CustHistoryInfo();

                            GetCustHistoryInfoModel(CustHistoryInfoModel, CustID, (int)ConsultType.NewCar, rerVal, userid);
                        }
                        else if (EnquiryType == "二手车")
                        {
                            Entities.ConsultSecondCar ConsultSecondCarModel = new Entities.ConsultSecondCar();
                            ConsultSecondCarModel.CustID = CustID;
                            if (BrandID != "0")
                            {
                                ConsultSecondCarModel.CarBrandId = Convert.ToInt32(BrandID);
                            }
                            if (CarModelsID != "0")
                            {
                                ConsultSecondCarModel.CarSerialId = Convert.ToInt32(CarModelsID);
                            }

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultSecondCarModel.CallRecord = PhoneRecord;
                            }
                            ConsultSecondCarModel.CreateTime   = System.DateTime.Now;
                            ConsultSecondCarModel.CreateUserID = userid;
                            rerVal = BLL.ConsultSecondCar.Instance.Insert(ConsultSecondCarModel);

                            CustHistoryInfoModel = new CustHistoryInfo();

                            GetCustHistoryInfoModel(CustHistoryInfoModel, CustID, (int)ConsultType.SecondCar, rerVal, userid);
                        }
                        else if (EnquiryType == "个人反馈")
                        {
                            Entities.ConsultPFeedback ConsultPFeedbackModel = new Entities.ConsultPFeedback();
                            ConsultPFeedbackModel.CustID = CustID;


                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultPFeedbackModel.CallRecord = PhoneRecord;
                            }
                            ConsultPFeedbackModel.CreateTime   = System.DateTime.Now;
                            ConsultPFeedbackModel.CreateUserID = userid;
                            rerVal = BLL.ConsultPFeedback.Instance.Insert(ConsultPFeedbackModel);

                            CustHistoryInfoModel = new CustHistoryInfo();

                            GetCustHistoryInfoModel(CustHistoryInfoModel, CustID, (int)ConsultType.PFeedback, rerVal, userid);
                        }
                        //else if (EnquiryType == "活动")
                        //{
                        //    Entities.ConsultActivity ConsultActivityModel = new Entities.ConsultActivity();
                        //    ConsultActivityModel.CustID = CustID;

                        //    if (!string.IsNullOrEmpty(Brand))
                        //    {
                        //        ConsultActivityModel.BrandName = Brand;
                        //    }

                        //    if (!string.IsNullOrEmpty(PhoneRecord))
                        //    {
                        //        ConsultActivityModel.CallRecord = PhoneRecord;
                        //    }
                        //    ConsultActivityModel.CreateTime = System.DateTime.Now;
                        //    ConsultActivityModel.CreateUserID = userid;
                        //    rerVal = BLL.ConsultActivity.Instance.Insert(ConsultActivityModel);

                        //    CustHistoryInfoModel = new CustHistoryInfo();

                        //    GetCustHistoryInfoModel(CustHistoryInfoModel, CustID, (int)ConsultType.Activity, rerVal, userid);
                        //}
                        else if (EnquiryType == "个人其他")
                        {
                            Entities.ConsultPOther ConsultPOtherModel = new Entities.ConsultPOther();
                            ConsultPOtherModel.CustID = CustID;

                            ConsultPOtherModel.CreateTime   = System.DateTime.Now;
                            ConsultPOtherModel.CreateUserID = userid;

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultPOtherModel.CallRecord = PhoneRecord;
                            }
                            rerVal = BLL.ConsultPOther.Instance.Insert(ConsultPOtherModel);


                            CustHistoryInfoModel = new CustHistoryInfo();

                            GetCustHistoryInfoModel(CustHistoryInfoModel, CustID, (int)ConsultType.POther, rerVal, userid);
                        }

                        else if (EnquiryType == "个人用车")
                        {
                            Entities.ConsultPUseCar ConsultPUseCarModel = new Entities.ConsultPUseCar();
                            ConsultPUseCarModel.CustID = CustID;

                            ConsultPUseCarModel.CreateTime   = System.DateTime.Now;
                            ConsultPUseCarModel.CreateUserID = userid;

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultPUseCarModel.CallRecord = PhoneRecord;
                            }
                            rerVal = BLL.ConsultPUseCar.Instance.Insert(ConsultPUseCarModel);


                            CustHistoryInfoModel = new CustHistoryInfo();

                            GetCustHistoryInfoModel(CustHistoryInfoModel, CustID, (int)ConsultType.PUseCar, rerVal, userid);
                        }

                        else if (EnquiryType == "经销商合作")
                        {
                            Entities.ConsultDCoop ConsultDCoopCarModel = new Entities.ConsultDCoop();
                            ConsultDCoopCarModel.CustID       = CustID;
                            ConsultDCoopCarModel.Type         = 1;
                            ConsultDCoopCarModel.CreateTime   = System.DateTime.Now;
                            ConsultDCoopCarModel.CreateUserID = userid;

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultDCoopCarModel.CallRecord = PhoneRecord;
                            }
                            rerVal = BLL.ConsultDCoop.Instance.Insert(ConsultDCoopCarModel);

                            CustHistoryInfoModel = new CustHistoryInfo();

                            GetCustHistoryInfoModel(CustHistoryInfoModel, CustID, (int)ConsultType.DCoop, rerVal, userid);
                        }
                        else if (EnquiryType == "经销商反馈")
                        {
                            Entities.ConsultDCoop ConsultDCoopCarModel = new Entities.ConsultDCoop();
                            ConsultDCoopCarModel.CustID       = CustID;
                            ConsultDCoopCarModel.Type         = 2;
                            ConsultDCoopCarModel.CreateTime   = System.DateTime.Now;
                            ConsultDCoopCarModel.CreateUserID = userid;

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultDCoopCarModel.CallRecord = PhoneRecord;
                            }
                            rerVal = BLL.ConsultDCoop.Instance.Insert(ConsultDCoopCarModel);

                            CustHistoryInfoModel = new CustHistoryInfo();

                            GetCustHistoryInfoModel(CustHistoryInfoModel, CustID, (int)ConsultType.DCoopFeedback, rerVal, userid);
                        }
                        else if (EnquiryType == "经销商其他")
                        {
                            Entities.ConsultDCoop ConsultDCoopCarModel = new Entities.ConsultDCoop();
                            ConsultDCoopCarModel.CustID       = CustID;
                            ConsultDCoopCarModel.Type         = 3;
                            ConsultDCoopCarModel.CreateTime   = System.DateTime.Now;
                            ConsultDCoopCarModel.CreateUserID = userid;

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultDCoopCarModel.CallRecord = PhoneRecord;
                            }
                            rerVal = BLL.ConsultDCoop.Instance.Insert(ConsultDCoopCarModel);

                            CustHistoryInfoModel = new CustHistoryInfo();

                            GetCustHistoryInfoModel(CustHistoryInfoModel, CustID, (int)ConsultType.DCoopOther, rerVal, userid);
                        }
                        //插入客户历史记录
                        if (CustHistoryInfoModel != null)
                        {
                            //功能废弃
                            custhistoryVal = BLL.CustHistoryInfo.Instance.Insert(CustHistoryInfoModel);
                        }
                    }
                    catch (Exception ex1)
                    {
                        ex.Append("数据插入报错。");
                        insertflag = false;
                        if (CustID != string.Empty)
                        {
                            //回滚数据
                            BLL.CustBasicInfo.Instance.Delete(CustID);
                            BLL.CustTel.Instance.Delete(CustID);
                            BLL.CustEmail.Instance.Delete(CustID);
                            if (EnquiryType == "新车")
                            {
                                BLL.ConsultNewCar.Instance.Delete(rerVal);
                            }
                            else if (EnquiryType == "二手车")
                            {
                                BLL.ConsultSecondCar.Instance.Delete(rerVal);
                            }
                            else if (EnquiryType == "个人反馈")
                            {
                                BLL.ConsultPFeedback.Instance.Delete(rerVal);
                            }
                            else if (EnquiryType == "活动")
                            {
                                BLL.ConsultActivity.Instance.Delete(rerVal);
                            }
                            else if (EnquiryType == "个人其他")
                            {
                                BLL.ConsultPOther.Instance.Delete(rerVal);
                            }

                            else if (EnquiryType == "个人用车")
                            {
                                BLL.ConsultPUseCar.Instance.Delete(rerVal);
                            }

                            else if (EnquiryType == "经销商合作")
                            {
                                BLL.ConsultDCoop.Instance.Delete(rerVal);
                            }
                            else if (EnquiryType == "经销商反馈")
                            {
                                BLL.ConsultDCoop.Instance.Delete(rerVal);
                            }
                            else if (EnquiryType == "经销商其他")
                            {
                                BLL.ConsultDCoop.Instance.Delete(rerVal);
                            }
                            if (custhistoryVal != 0)
                            {
                                BLL.CustHistoryInfo.Instance.Delete(custhistoryVal);
                            }
                        }
                    }
                }
            }
            if (insertflag == false)
            {
                //导出内容
                exportstr.Append(UserName + "|");
                exportstr.Append(Sex + "|");
                exportstr.Append(Tel1 + "|");
                exportstr.Append(CustCategory + "|");
                exportstr.Append(Tel2 + "|");
                exportstr.Append(Email + "|");

                exportstr.Append(Province + "|");

                exportstr.Append(City + "|");
                exportstr.Append(County + "|");

                exportstr.Append(Address + "|");
                exportstr.Append(DataSource + "|");

                exportstr.Append(EnquiryType + "|");
                exportstr.Append(Brand + "|");

                exportstr.Append(Models + "|");
                exportstr.Append(DealerName + "|");

                exportstr.Append(PhoneRecord + "|");
                exportstr.Append(ex.ToString());
            }
            return(insertflag);
        }
        private void Submit(out string msg, int userID)
        {
            //此方法内的逻辑可参考文档:$/A5信息系统研发/销售业务管理平台/客户关系管理/doc/Call Center/无主订单处理页面保存和提交逻辑.docx  ---- Add By Chybin At 2013-07-19

            msg = "";

            //System.Threading.Thread.Sleep(5000);

            #region 准备数据

            NewCarConsultInfo              newInfo        = null;                       //新车订单信息
            ReplaceCarConsultInfo          replaceInfo    = null;                       //置换订单信息
            Entities.OrderTask             orderTaskModel = null;                       //无主订单任务信息
            Entities.OrderTaskOperationLog orderLog       = null;                       //任务操作日志
            List <StringBuilder>           listLogStr     = new List <StringBuilder>(); //用户操作日志
            StringBuilder sblogstr = new StringBuilder();
            string        logstr   = "";

            #region 取得新车/置换无主订单信息更新后Model(此时不保存到数据库)

            Entities.OrderNewCar     newModel     = null; //新车订单实体类
            Entities.OrderRelpaceCar replaceModel = null; //置换订单实体类

            if (Source == "1" || Source == "3")
            {
                newInfo = (NewCarConsultInfo)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(NewCarConsultInfoStr, typeof(NewCarConsultInfo));

                newModel = OrderNewSave.Save(newInfo, out msg, userID, int.Parse(TaskID));
                if (msg != "")
                {
                    return;
                }
            }
            else if (Source == "2")
            {
                replaceInfo  = (ReplaceCarConsultInfo)Newtonsoft.Json.JavaScriptConvert.DeserializeObject(ReplaceCarConsultInfoStr, typeof(ReplaceCarConsultInfo));
                replaceModel = OrderReplaceSave.Save(replaceInfo, out msg, userID, long.Parse(TaskID));
                if (msg != "")
                {
                    return;
                }
            }

            #endregion

            #region 取得任务的更新后信息

            orderTaskModel = BLL.OrderTask.Instance.GetOrderTask(long.Parse(TaskID));
            if (orderTaskModel == null)
            {
                msg += "没有找到相关的任务信息";
                return;
            }

            if (orderTaskModel.TaskStatus != 2 && orderTaskModel.TaskStatus != 3)
            {
                msg += "当前任务状态不能保存和提交";
                return;
            }

            if (orderTaskModel.AssignUserID != userID)
            {
                msg += "此订单没有分配给你";
                return;
            }


            //修改状态
            if (Action == "save")
            {
                orderTaskModel.TaskStatus = (int)TaskStatus.Processing;
            }
            else if (Action == "sub")
            {
                orderTaskModel.TaskStatus = (int)TaskStatus.Processed;
                orderTaskModel.SubmitTime = DateTime.Now;
            }

            //是否已选择经销商 只有在提交时,才会改动该属性 -是否已选择经销商 lxw
            if (Action == "sub")
            {
                if (((Source == "1" || Source == "3") && newModel.DMSMemberCode != "") || (Source == "2" && replaceModel.DMSMemberCode != ""))
                {
                    orderTaskModel.IsSelectDMSMember = true;
                }
                else
                {
                    orderTaskModel.IsSelectDMSMember = false;
                }
            }

            if (Source == "1" || Source == "3")
            {
                orderTaskModel.UserName = newModel.UserName;
            }
            else if (Source == "2")
            {
                orderTaskModel.UserName = replaceModel.UserName;
            }

            if (NoDealerReasonID != "")
            {
                orderTaskModel.NoDealerReasonID = int.Parse(NoDealerReasonID);
            }
            orderTaskModel.NoDealerReason = NoDealerReason;


            #endregion

            #region 任务操作日志

            orderLog = new OrderTaskOperationLog();

            //modify by qizq 2013-1-4首先判断是否是通话中
            if (IsCalling == "1")
            {
                if (HistoryLogID == "")
                {
                    //通话中提交把本地录音主键付给实体
                    long CallRecordReCID = 0;
                    if (CallRecordID != "")
                    {
                        if (long.TryParse(CallRecordID, out CallRecordReCID))
                        {
                            orderLog.CallRecordID = CallRecordReCID;
                        }
                    }
                }
            }
            //


            orderLog.TaskID = int.Parse(TaskID);

            if (Action == "save")
            {
                orderLog.OperationStatus = (int)OperationStatus.Save;
            }
            else if (Action == "sub")
            {
                orderLog.OperationStatus = (int)OperationStatus.Submit;
            }
            orderLog.TaskStatus   = orderTaskModel.TaskStatus;
            orderLog.CreateTime   = DateTime.Now;
            orderLog.CreateUserID = userID;

            #endregion

            #region 如果是提交操作,更新客户信息、插入咨询类型、添加客户联系记录

            Entities.CustBasicInfo          custmodel     = null;       //客户信息实体类
            Entities.CustTel                telPhoneMode  = null;       //电话实体类
            Entities.CustTel                telMobileMode = null;       //电话实体类
            Entities.CustEmail              emailMode     = null;       //邮件实体类
            Entities.ConsultOrderNewCar     cNewCar       = null;       //新车咨询类型
            Entities.ConsultOrderRelpaceCar cReplaceCar   = null;       //置换车咨询类型
            Entities.CustHistoryInfo        custHistInfo  = null;       //客户联系记录

            Entities.BuyCarInfo buyCarInfo = new Entities.BuyCarInfo(); //已购车或未购车信息 lxw

            if (Action == "sub")
            {
                #region 更新或插入客户信息
                //代码失效,功能废弃,需求重新实现
                #endregion

                #region 插入咨询类型

                if (Source == "1" || Source == "3")
                {
                    cNewCar = new ConsultOrderNewCar();

                    #region 赋值

                    cNewCar.CarBrandId   = newModel.CarMasterID;
                    cNewCar.CarSerialId  = newModel.CarSerialID;
                    cNewCar.CarNameID    = newModel.CarTypeID;
                    cNewCar.CarColor     = newModel.CarColor;
                    cNewCar.DealerCode   = newModel.DMSMemberCode;
                    cNewCar.DealerName   = newModel.DMSMemberName;
                    cNewCar.OrderRemark  = newModel.OrderRemark;
                    cNewCar.CallRecord   = newModel.CallRecord;
                    cNewCar.CreateTime   = DateTime.Now;
                    cNewCar.CreateUserID = userID;

                    #endregion
                }
                else if (Source == "2")
                {
                    cReplaceCar = new ConsultOrderRelpaceCar();

                    #region 赋值

                    cReplaceCar.WantBrandId        = replaceModel.RepCarMasterID;
                    cReplaceCar.WantSerialId       = replaceModel.RepCarSerialID;
                    cReplaceCar.WantNameID         = replaceModel.RepCarTypeId;
                    cReplaceCar.WantCarColor       = replaceModel.ReplacementCarColor;
                    cReplaceCar.WantDealerName     = replaceModel.DMSMemberName;
                    cReplaceCar.WantDealerCode     = replaceModel.DMSMemberCode;
                    cReplaceCar.CallRecord         = replaceModel.CallRecord;
                    cReplaceCar.OldBrandId         = replaceModel.CarMasterID;
                    cReplaceCar.OldSerialId        = replaceModel.CarSerialID;
                    cReplaceCar.OldNameID          = replaceModel.CarTypeID;
                    cReplaceCar.OldCarColor        = replaceModel.CarColor;
                    cReplaceCar.RegisterDateYear   = replaceModel.ReplacementCarBuyYear.ToString();
                    cReplaceCar.RegisterDateMonth  = replaceModel.ReplacementCarBuyMonth.ToString();
                    cReplaceCar.RegisterProvinceID = replaceModel.RepCarProvinceID;
                    cReplaceCar.RegisterCityID     = replaceModel.RepCarCityID;
                    cReplaceCar.RegisterCountyID   = replaceModel.RepCarCountyID;
                    cReplaceCar.Mileage            = (decimal)replaceModel.ReplacementCarUsedMiles;
                    cReplaceCar.PresellPrice       = replaceModel.SalePrice;
                    cReplaceCar.OrderRemark        = replaceModel.OrderRemark;
                    cReplaceCar.CreateTime         = DateTime.Now;
                    cReplaceCar.CreateUserID       = userID;

                    #endregion
                }

                #endregion

                #region 插入客户历史记录

                custHistInfo = new CustHistoryInfo();

                #region 赋值

                custHistInfo.TaskID = TaskID;
                if (Source == "1" || Source == "3")
                {
                    custHistInfo.ConsultID = 60010;//新车咨询类型
                }
                else
                {
                    custHistInfo.ConsultID = 60011;//置换咨询类型
                }
                custHistInfo.RecordType        = 2;
                custHistInfo.QuestionQuality   = (int)QuestionNature.NatureCommon;
                custHistInfo.ProcessStatus     = (int)EnumTaskStatus.TaskStatusOver;
                custHistInfo.CreateTime        = DateTime.Now;
                custHistInfo.CreateUserID      = userID;
                custHistInfo.LastTreatmentTime = DateTime.Now;

                #endregion

                #endregion
            }

            #endregion

            #endregion

            #region 事务提交

            string        connectionstrings = ConfigurationUtil.GetAppSettingValue("ConnectionStrings_CC");
            SqlConnection connection        = new SqlConnection(connectionstrings);
            connection.Open();
            SqlTransaction tran = connection.BeginTransaction(IsolationLevel.ReadUncommitted, "SampleTransaction");

            try
            {
                #region 保存新车/置换无主订单信息

                if (Source == "1" || Source == "3")
                {
                    BLL.OrderNewCar.Instance.Update(tran, newModel);
                }
                else if (Source == "2")
                {
                    BLL.OrderRelpaceCar.Instance.Update(tran, replaceModel);
                }

                #endregion

                #region 修改任务信息

                BLL.OrderTask.Instance.Update(tran, orderTaskModel);

                #endregion

                #region 任务操作日志

                //modify by qizq 2013-1-4不是在通话中,处理记录已存在更新处理记录
                if (IsCalling != "1" && HistoryLogID != "")
                {
                    //通话中提交把本地录音主键付给实体
                    long CallRecordReCID = 0;
                    if (CallRecordID != "")
                    {
                        if (long.TryParse(CallRecordID, out CallRecordReCID))
                        {
                            orderLog.CallRecordID = CallRecordReCID;
                        }
                    }
                    long HistoryLogIDLog = 0;
                    if (long.TryParse(HistoryLogID, out HistoryLogIDLog))
                    {
                        orderLog.RecID = HistoryLogIDLog;
                    }
                    BLL.OrderTaskOperationLog.Instance.Update(tran, orderLog);
                }
                else
                {
                    BLL.OrderTaskOperationLog.Instance.Insert(tran, orderLog);
                }
                //



                #endregion

                if (Action == "sub")
                {
                    string retCustID = "";

                    #region 更新或插入客户信息

                    if (custmodel.RecID == -2)
                    {
                        //新加的客户

                        retCustID = BLL.CustBasicInfo.Instance.Insert(tran, custmodel);

                        #region 记日志

                        sblogstr = new StringBuilder();
                        logstr   = "";
                        logstr  += "新加了客户‘" + custmodel.CustName + "’的信息【ID:" + retCustID + "】";

                        if (logstr != "")
                        {
                            sblogstr.Append(logstr);
                            listLogStr.Add(sblogstr);
                        }

                        #endregion
                    }
                    else
                    {
                        //编辑客户信息
                        BLL.CustBasicInfo.Instance.Update(tran, custmodel);
                        retCustID = custmodel.CustID;
                    }
                    #endregion

                    #region 插入电话

                    if (telPhoneMode != null)
                    {
                        telPhoneMode.CustID = retCustID;
                        BLL.CustTel.Instance.Insert(tran, telPhoneMode);
                    }

                    if (telMobileMode != null)
                    {
                        telMobileMode.CustID = retCustID;
                        BLL.CustTel.Instance.Insert(tran, telMobileMode);
                    }

                    #endregion

                    #region 插入邮箱

                    if (emailMode != null)
                    {
                        emailMode.CustID = retCustID;
                        BLL.CustEmail.Instance.Insert(tran, emailMode);
                    }

                    #endregion

                    #region 插入咨询类型

                    int retDataID = 0;

                    if (cNewCar != null)
                    {
                        cNewCar.CustID = retCustID;
                        retDataID      = BLL.ConsultOrderNewCar.Instance.Insert(tran, cNewCar);

                        #region 记日志

                        sblogstr = new StringBuilder();
                        logstr   = "";
                        logstr  += "新加了无主订单新车联系咨询记录【ID:" + retDataID + "】";

                        if (logstr != "")
                        {
                            sblogstr.Append(logstr);
                            listLogStr.Add(sblogstr);
                        }

                        #endregion
                    }
                    if (cReplaceCar != null)
                    {
                        cReplaceCar.CustID = retCustID;
                        retDataID          = BLL.ConsultOrderRelpaceCar.Instance.Insert(tran, cReplaceCar);

                        #region 记日志

                        sblogstr = new StringBuilder();
                        logstr   = "";
                        logstr  += "新加了无主订单置换联系咨询记录【ID:" + retDataID + "】";

                        if (logstr != "")
                        {
                            sblogstr.Append(logstr);
                            listLogStr.Add(sblogstr);
                        }

                        #endregion
                    }

                    #endregion

                    #region 插入未购车或已购车记录 BuyCarInfo lxw

                    if (buyCarInfo != null && buyCarInfo.RecID == -2)
                    {
                        buyCarInfo.CustID = retCustID;
                        int recID = BLL.BuyCarInfo.Instance.Insert(tran, buyCarInfo);

                        #region 记日志

                        sblogstr = new StringBuilder();
                        logstr   = "";
                        logstr  += "新加了未购车已购车BuyCarInfo表的记录【ID:" + recID + "】";

                        if (logstr != "")
                        {
                            sblogstr.Append(logstr);
                            listLogStr.Add(sblogstr);
                        }

                        #endregion
                    }

                    if (buyCarInfo != null && buyCarInfo.RecID != -2)
                    {
                        BLL.BuyCarInfo.Instance.Update(tran, buyCarInfo);

                        #region 记日志

                        sblogstr = new StringBuilder();
                        logstr   = "";
                        logstr  += "修改了未购车已购车BuyCarInfo表的记录【ID:" + buyCarInfo.RecID + "】";

                        if (logstr != "")
                        {
                            sblogstr.Append(logstr);
                            listLogStr.Add(sblogstr);
                        }

                        #endregion
                    }

                    #endregion

                    #region 插入客户联系记录

                    if (custHistInfo != null)
                    {
                        custHistInfo.CustID        = retCustID;
                        custHistInfo.ConsultDataID = retDataID;
                        BLL.CustHistoryInfo.Instance.Insert(tran, custHistInfo);
                    }

                    #endregion

                    #region 插入已购车或未购车信息

                    #endregion

                    #region 保存用户操作日志

                    foreach (StringBuilder sbStr in listLogStr)
                    {
                        BLL.Util.InsertUserLog(tran, sbStr.ToString());
                    }
                    #endregion
                }

                if (msg == "")
                {
                    tran.Commit();
                    if (Action == "sub")
                    {
                        #region 调用易湃接口,传回数据

                        string errorMsg    = "";
                        int    retService  = 0;
                        short  isSelectDMS = 0;

                        #region 调用接口

                        BitAuto.ISDC.CC2012.WebService.NoDealerOrderHelper OrderHelper = new BitAuto.ISDC.CC2012.WebService.NoDealerOrderHelper();
                        if (Source == "1")                                                    //新车
                        {
                            isSelectDMS = newModel.DMSMemberCode == "" ? (short)2 : (short)1; //1 选择了经销商  2 未选择经销商
                            retService  = OrderHelper.SetNewCarOrder(newModel, isSelectDMS, NoDealerReason, ref errorMsg);
                        }
                        else if (Source == "2")                                                   //置换
                        {
                            isSelectDMS = replaceModel.DMSMemberCode == "" ? (short)2 : (short)1; //1 选择了经销商  2 未选择经销商
                            retService  = OrderHelper.SetReplacementOrder(replaceModel, isSelectDMS, NoDealerReason, ref errorMsg);
                        }
                        else if (Source == "3")
                        {
                            isSelectDMS = newModel.DMSMemberCode == "" ? (short)2 : (short)1; //1 选择了经销商  2 未选择经销商
                            retService  = OrderHelper.SetTestDriveOrder(newModel, isSelectDMS, NoDealerReason, ref errorMsg);
                        }

                        #endregion

                        #region 插入更新无主订单数据日志表

                        Entities.UpdateOrderData updateDateMode = new UpdateOrderData();
                        updateDateMode.TaskID = TaskID;

                        if (Source == "1" || Source == "3")
                        {
                            updateDateMode.YPOrderID = newModel.YPOrderID;
                        }
                        else if (Source == "2")
                        {
                            updateDateMode.YPOrderID = replaceModel.YPOrderID;
                        }

                        updateDateMode.UpdateType = retService;
                        updateDateMode.IsUpdate   = retService; // 1 成功了,不用处理,-1 需要重新处理
                        if (retService == 1)
                        {
                            updateDateMode.UpdateDateTime = DateTime.Now;
                        }
                        updateDateMode.UpdateErrorMsg = errorMsg;
                        updateDateMode.CreateTime     = DateTime.Now;
                        updateDateMode.CreateUserID   = userID;
                        updateDateMode.APIType        = 1;

                        BLL.UpdateOrderData.Instance.Insert(updateDateMode);

                        #endregion

                        if (retService == -1)
                        {
                            msg = "InterfaceErr|" + errorMsg;
                        }

                        #endregion
                    }
                }
                else
                {
                    tran.Rollback();
                }
            }
            catch (Exception ex)
            {
                if (tran.Connection != null)
                {
                    tran.Rollback();
                }
                msg = ex.Message.ToString();
            }
            finally
            {
                connection.Close();
            }



            #endregion
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 校验
        /// </summary>
        private bool Valid(int rowNum, IDataReader reader, out StringBuilder ex, int userid, DataTable dtExport)
        {
            ex = new StringBuilder();

            string UserName = string.Empty;

            UserName = reader[0].ToString().Trim();

            string Sex = string.Empty;

            Sex = reader[1].ToString().Trim();

            string Tel1 = string.Empty;

            Tel1 = reader[2].ToString().Trim();

            string CustCategory = string.Empty;

            CustCategory = reader[3].ToString().Trim();

            string Tel2 = string.Empty;

            Tel2 = reader[4].ToString().Trim();

            string Email = string.Empty;

            Email = reader[5].ToString().Trim();

            string Province = string.Empty;

            Province = reader[6].ToString().Trim();

            string City = string.Empty;

            City = reader[7].ToString().Trim();

            string County = string.Empty;

            County = reader[8].ToString().Trim();

            string Address = string.Empty;

            Address = reader[9].ToString().Trim();

            string DataSource = string.Empty;

            DataSource = reader[10].ToString().Trim();
            //咨询类型
            string EnquiryType = string.Empty;

            EnquiryType = reader[11].ToString().Trim();


            string Brand = string.Empty;

            Brand = reader[12].ToString().Trim();

            string Models = string.Empty;

            Models = reader[13].ToString().Trim();

            //推荐经销商名称
            string DealerName = string.Empty;

            DealerName = reader[14].ToString().Trim();

            //来电记录
            string PhoneRecord = string.Empty;

            PhoneRecord = reader[15].ToString().Trim();

            bool insertflag = true;

            //会员ID号验证
            if (string.IsNullOrEmpty(UserName) || UserName.Length == 0)
            {
                ex.Append("第" + rowNum + "行[姓名]不可为空。");
                insertflag = false;
            }
            else
            {
                if (BLL.Util.GetLength(UserName) > 50)
                {
                    ex.Append("第" + rowNum + "行[姓名]超长。");
                    insertflag = false;
                }
            }
            if (string.IsNullOrEmpty(Sex) || Sex.Length == 0)
            {
                ex.Append("第" + rowNum + "行[性别]不可为空。");
                insertflag = false;
            }
            else
            {
                if (Sex != "男" && Sex != "女")
                {
                    ex.Append("第" + rowNum + "行[性别]输入错误。");
                    insertflag = false;
                }
            }
            if (string.IsNullOrEmpty(Tel1) || Tel1.Length == 0)
            {
                ex.Append("第" + rowNum + "行[电话1]不可为空。");
                insertflag = false;
            }
            else
            {
                if (BLL.Util.IsTelephone(Tel1) == false && BLL.Util.IsHandset(Tel1) == false)
                {
                    ex.Append("第" + rowNum + "行[电话]输入错误。");
                    insertflag = false;
                }
            }

            if (string.IsNullOrEmpty(CustCategory) || CustCategory.Length == 0)
            {
                ex.Append("第" + rowNum + "行[客户分类]不可为空。");
                insertflag = false;
            }
            else
            {
                if (CustCategory != "已购车" && CustCategory != "未购车" && CustCategory != "经销商")
                {
                    ex.Append("第" + rowNum + "行[客户分类]输入错误。");
                    insertflag = false;
                }
            }
            if (!string.IsNullOrEmpty(Tel2))
            {
                if (BLL.Util.IsTelephone(Tel2) == false && BLL.Util.IsHandset(Tel2) == false)
                {
                    ex.Append("第" + rowNum + "行[电话2]输入错误。");
                    insertflag = false;
                }
            }
            if (!string.IsNullOrEmpty(Email))
            {
                if (BLL.Util.IsEmail(Email) == false)
                {
                    ex.Append("第" + rowNum + "行[邮箱]输入错误。");
                    insertflag = false;
                }
            }
            if (!string.IsNullOrEmpty(Address))
            {
                if (BLL.Util.GetLength(Address) > 200)
                {
                    ex.Append("第" + rowNum + "行[地址]超长。");
                    insertflag = false;
                }
            }

            if (!string.IsNullOrEmpty(DataSource))
            {
                if (DataSource != "呼叫中心" && DataSource != "在线" && DataSource != "汽车通" && DataSource != "车易通")
                {
                    ex.Append("第" + rowNum + "行[数据来源]输入错误。");
                    insertflag = false;
                }
            }

            if (!string.IsNullOrEmpty(EnquiryType))
            {
                if (EnquiryType != "新车" && EnquiryType != "二手车" && EnquiryType != "个人反馈" && EnquiryType != "活动" && EnquiryType != "个人用车" && EnquiryType != "个人其他" && EnquiryType != "经销商合作" && EnquiryType != "经销商反馈" && EnquiryType != "经销商其他")
                {
                    ex.Append("第" + rowNum + "行[咨询类型]输入错误。");
                    insertflag = false;
                }
            }
            if (!string.IsNullOrEmpty(DealerName))
            {
                if (BLL.Util.GetLength(DealerName) > 200)
                {
                    ex.Append("第" + rowNum + "行[推荐经销商]超长。");
                    insertflag = false;
                }
            }
            if (!string.IsNullOrEmpty(PhoneRecord))
            {
                if (BLL.Util.GetLength(PhoneRecord) > 2000)
                {
                    ex.Append("第" + rowNum + "行[来电记录]超长。");
                    insertflag = false;
                }
            }
            string provinceID = "0";

            //验证省份城市
            if (!string.IsNullOrEmpty(Province))
            {
                provinceID = BitAuto.YanFa.Crm2009.BLL.AreaInfo.Instance.GetAreaIdByName(Province, 1);
                if (provinceID == "0")
                {
                    ex.Append("第" + rowNum + "行[地区(省)]输入错误。");
                    insertflag = false;
                }
            }
            string CityID = "0";

            //验证省份城市
            if (!string.IsNullOrEmpty(City))
            {
                CityID = BitAuto.YanFa.Crm2009.BLL.AreaInfo.Instance.GetAreaIdByName(City, 2);
                if (CityID == "0")
                {
                    ex.Append("第" + rowNum + "行[地区(市)]输入错误。");
                    insertflag = false;
                }
            }
            string CountryID = "0";

            //验证区县
            if (!string.IsNullOrEmpty(County))
            {
                CountryID = BitAuto.YanFa.Crm2009.BLL.AreaInfo.Instance.GetAreaIdByName(County, 3);
                if (CountryID == "0")
                {
                    ex.Append("第" + rowNum + "行[地区(区县)]输入错误。");
                    insertflag = false;
                }
            }
            //验证车型
            string BrandID = "0";

            if (!string.IsNullOrEmpty(Brand))
            {
                DataTable dt = BLL.BuyCarInfo.Instance.GetCarBrandByName(Brand);
                if (dt != null && dt.Rows.Count > 0)
                {
                    BrandID = dt.Rows[0]["Brandid"].ToString();
                }
                else
                {
                    ex.Append("第" + rowNum + "行[品牌]输入错误。");
                    insertflag = false;
                }
            }

            //验证车系
            string CarModelsID = "0";

            if (!string.IsNullOrEmpty(Models))
            {
                DataTable dt = BLL.BuyCarInfo.Instance.GetCarSerialByName(Models);
                if (dt != null && dt.Rows.Count > 0)
                {
                    CarModelsID = dt.Rows[0]["serialid"].ToString();
                }
                else
                {
                    ex.Append("第" + rowNum + "行[车系]输入错误。");
                    insertflag = false;
                }
            }

            //如果验证通过,插入
            if (insertflag)
            {
                bool flag = false;
                flag = BLL.CustBasicInfo.Instance.IsExistsByCustNameAndTel(UserName, Tel1);

                if (flag)
                {
                    ex.Append("第" + rowNum + "行记录[姓名],[电话1]已存在。");
                    insertflag = false;
                }
                else
                {
                    Entities.CustBasicInfo CustBasicInfoModel = new Entities.CustBasicInfo();
                    CustBasicInfoModel.Status   = 0;
                    CustBasicInfoModel.CustName = UserName;
                    CustBasicInfoModel.Sex      = (Sex == "男" ? 1 : 2);
                    if (CustCategory == "已购车")
                    {
                        CustBasicInfoModel.CustCategoryID = 1;
                    }
                    else if (CustCategory == "未购车")
                    {
                        CustBasicInfoModel.CustCategoryID = 2;
                    }
                    else
                    {
                        CustBasicInfoModel.CustCategoryID = 3;
                    }
                    if (provinceID != "0")
                    {
                        CustBasicInfoModel.ProvinceID = Convert.ToInt32(provinceID);
                    }
                    if (CityID != "0")
                    {
                        CustBasicInfoModel.CityID = Convert.ToInt32(CityID);
                    }
                    if (CountryID != "0")
                    {
                        CustBasicInfoModel.CountyID = Convert.ToInt32(CountryID);
                    }

                    if (!string.IsNullOrEmpty(Address))
                    {
                        CustBasicInfoModel.Address = Address;
                    }

                    if (!string.IsNullOrEmpty(DataSource))
                    {
                        if (DataSource == "呼叫中心")
                        {
                            CustBasicInfoModel.DataSource = 180001;
                        }
                        else if (DataSource == "在线")
                        {
                            CustBasicInfoModel.DataSource = 180002;
                        }
                        else if (DataSource == "汽车通")
                        {
                            CustBasicInfoModel.DataSource = 180003;
                        }
                        else if (DataSource == "车易通")
                        {
                            CustBasicInfoModel.DataSource = 180004;
                        }
                    }
                    string CustID = string.Empty;
                    int    rerVal = 0;
                    try
                    {
                        //功能废弃
                        CustID = null;// BLL.CustBasicInfo.Instance.Insert(CustBasicInfoModel);
                        Entities.CustTel custTel1 = new Entities.CustTel();
                        custTel1.Tel    = Tel1;
                        custTel1.CustID = CustID;
                        BLL.CustTel.Instance.Insert(custTel1);
                        Entities.CustTel custTel2 = null;
                        if (!string.IsNullOrEmpty(Tel2))
                        {
                            custTel2        = new Entities.CustTel();
                            custTel2.Tel    = Tel2;
                            custTel2.CustID = CustID;
                            BLL.CustTel.Instance.Insert(custTel2);
                        }
                        Entities.CustEmail custemail = null;
                        if (!string.IsNullOrEmpty(Email))
                        {
                            custemail        = new Entities.CustEmail();
                            custemail.Email  = Email;
                            custemail.CustID = CustID;
                            BLL.CustEmail.Instance.Insert(custemail);
                        }

                        //if (EnquiryType != "新车" && EnquiryType != "二手车" && EnquiryType != "个人反馈" && EnquiryType != "活动" && EnquiryType != "个人用车" && EnquiryType != "个人其他" && EnquiryType != "经销商合作" && EnquiryType != "经销商反馈" && EnquiryType != "经销商其他")
                        if (EnquiryType == "新车")
                        {
                            Entities.ConsultNewCar ConsultNewCarModel = new Entities.ConsultNewCar();
                            ConsultNewCarModel.CustID = CustID;
                            if (BrandID != "0")
                            {
                                ConsultNewCarModel.CarBrandId = Convert.ToInt32(BrandID);
                            }
                            if (CarModelsID != "0")
                            {
                                ConsultNewCarModel.CarSerialId = Convert.ToInt32(CarModelsID);
                            }
                            if (!string.IsNullOrEmpty(DealerName))
                            {
                                ConsultNewCarModel.DealerName = DealerName;
                            }
                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultNewCarModel.CallRecord = PhoneRecord;
                            }
                            ConsultNewCarModel.CreateTime   = System.DateTime.Now;
                            ConsultNewCarModel.CreateUserID = userid;
                            rerVal = BLL.ConsultNewCar.Instance.Insert(ConsultNewCarModel);
                        }
                        else if (EnquiryType == "二手车")
                        {
                            Entities.ConsultSecondCar ConsultSecondCarModel = new Entities.ConsultSecondCar();
                            ConsultSecondCarModel.CustID = CustID;
                            if (BrandID != "0")
                            {
                                ConsultSecondCarModel.CarBrandId = Convert.ToInt32(BrandID);
                            }
                            if (CarModelsID != "0")
                            {
                                ConsultSecondCarModel.CarSerialId = Convert.ToInt32(CarModelsID);
                            }

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultSecondCarModel.CallRecord = PhoneRecord;
                            }
                            ConsultSecondCarModel.CreateTime   = System.DateTime.Now;
                            ConsultSecondCarModel.CreateUserID = userid;
                            rerVal = BLL.ConsultSecondCar.Instance.Insert(ConsultSecondCarModel);
                        }
                        else if (EnquiryType == "个人反馈")
                        {
                            Entities.ConsultPFeedback ConsultPFeedbackModel = new Entities.ConsultPFeedback();
                            ConsultPFeedbackModel.CustID = CustID;


                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultPFeedbackModel.CallRecord = PhoneRecord;
                            }
                            ConsultPFeedbackModel.CreateTime   = System.DateTime.Now;
                            ConsultPFeedbackModel.CreateUserID = userid;
                            rerVal = BLL.ConsultPFeedback.Instance.Insert(ConsultPFeedbackModel);
                        }
                        else if (EnquiryType == "活动")
                        {
                            Entities.ConsultActivity ConsultActivityModel = new Entities.ConsultActivity();
                            ConsultActivityModel.CustID = CustID;

                            if (!string.IsNullOrEmpty(Brand))
                            {
                                ConsultActivityModel.BrandName = Brand;
                            }

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultActivityModel.CallRecord = PhoneRecord;
                            }
                            ConsultActivityModel.CreateTime   = System.DateTime.Now;
                            ConsultActivityModel.CreateUserID = userid;
                            rerVal = BLL.ConsultActivity.Instance.Insert(ConsultActivityModel);
                        }
                        else if (EnquiryType == "个人其他")
                        {
                            Entities.ConsultPOther ConsultPOtherModel = new Entities.ConsultPOther();
                            ConsultPOtherModel.CustID = CustID;

                            ConsultPOtherModel.CreateTime   = System.DateTime.Now;
                            ConsultPOtherModel.CreateUserID = userid;

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultPOtherModel.CallRecord = PhoneRecord;
                            }
                            rerVal = BLL.ConsultPOther.Instance.Insert(ConsultPOtherModel);
                        }

                        else if (EnquiryType == "个人用车")
                        {
                            Entities.ConsultPUseCar ConsultPUseCarModel = new Entities.ConsultPUseCar();
                            ConsultPUseCarModel.CustID = CustID;

                            ConsultPUseCarModel.CreateTime   = System.DateTime.Now;
                            ConsultPUseCarModel.CreateUserID = userid;

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultPUseCarModel.CallRecord = PhoneRecord;
                            }
                            rerVal = BLL.ConsultPUseCar.Instance.Insert(ConsultPUseCarModel);
                        }

                        else if (EnquiryType == "经销商合作")
                        {
                            Entities.ConsultDCoop ConsultDCoopCarModel = new Entities.ConsultDCoop();
                            ConsultDCoopCarModel.CustID       = CustID;
                            ConsultDCoopCarModel.Type         = 1;
                            ConsultDCoopCarModel.CreateTime   = System.DateTime.Now;
                            ConsultDCoopCarModel.CreateUserID = userid;

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultDCoopCarModel.CallRecord = PhoneRecord;
                            }
                            rerVal = BLL.ConsultDCoop.Instance.Insert(ConsultDCoopCarModel);
                        }
                        else if (EnquiryType == "经销商反馈")
                        {
                            Entities.ConsultDCoop ConsultDCoopCarModel = new Entities.ConsultDCoop();
                            ConsultDCoopCarModel.CustID       = CustID;
                            ConsultDCoopCarModel.Type         = 2;
                            ConsultDCoopCarModel.CreateTime   = System.DateTime.Now;
                            ConsultDCoopCarModel.CreateUserID = userid;

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultDCoopCarModel.CallRecord = PhoneRecord;
                            }
                            rerVal = BLL.ConsultDCoop.Instance.Insert(ConsultDCoopCarModel);
                        }
                        else if (EnquiryType == "经销商其他")
                        {
                            Entities.ConsultDCoop ConsultDCoopCarModel = new Entities.ConsultDCoop();
                            ConsultDCoopCarModel.CustID       = CustID;
                            ConsultDCoopCarModel.Type         = 3;
                            ConsultDCoopCarModel.CreateTime   = System.DateTime.Now;
                            ConsultDCoopCarModel.CreateUserID = userid;

                            if (!string.IsNullOrEmpty(PhoneRecord))
                            {
                                ConsultDCoopCarModel.CallRecord = PhoneRecord;
                            }
                            rerVal = BLL.ConsultDCoop.Instance.Insert(ConsultDCoopCarModel);
                        }
                    }
                    catch (Exception ex1)
                    {
                        ex.Append("第" + rowNum + "行数据插入报错。");
                        insertflag = false;
                        if (CustID != string.Empty)
                        {
                            //回滚数据
                            BLL.CustBasicInfo.Instance.Delete(CustID);
                            BLL.CustTel.Instance.Delete(CustID);
                            BLL.CustEmail.Instance.Delete(CustID);
                            if (EnquiryType == "新车")
                            {
                                BLL.ConsultNewCar.Instance.Delete(rerVal);
                            }
                            else if (EnquiryType == "二手车")
                            {
                                BLL.ConsultSecondCar.Instance.Delete(rerVal);
                            }
                            else if (EnquiryType == "个人反馈")
                            {
                                BLL.ConsultPFeedback.Instance.Delete(rerVal);
                            }
                            else if (EnquiryType == "活动")
                            {
                                BLL.ConsultActivity.Instance.Delete(rerVal);
                            }
                            else if (EnquiryType == "个人其他")
                            {
                                BLL.ConsultPOther.Instance.Delete(rerVal);
                            }

                            else if (EnquiryType == "个人用车")
                            {
                                BLL.ConsultPUseCar.Instance.Delete(rerVal);
                            }

                            else if (EnquiryType == "经销商合作")
                            {
                                BLL.ConsultDCoop.Instance.Delete(rerVal);
                            }
                            else if (EnquiryType == "经销商反馈")
                            {
                                BLL.ConsultDCoop.Instance.Delete(rerVal);
                            }
                            else if (EnquiryType == "经销商其他")
                            {
                                BLL.ConsultDCoop.Instance.Delete(rerVal);
                            }
                        }
                    }
                }
            }
            if (insertflag == false)
            {
                DataRow newRow = dtExport.NewRow();
                newRow["username"]     = UserName;
                newRow["sex"]          = Sex;
                newRow["tel1"]         = Tel1;
                newRow["custcategory"] = CustCategory;
                newRow["tel2"]         = Tel2;
                newRow["email"]        = Email;

                newRow["province"] = Province;
                newRow["city"]     = City;
                newRow["county"]   = County;

                newRow["address"]    = Address;
                newRow["datasource"] = DataSource;

                newRow["EnquiryType"] = EnquiryType;
                newRow["brand"]       = Brand;

                newRow["carmodel"]   = Models;
                newRow["Dealer"]     = DealerName;
                newRow["callrecord"] = PhoneRecord;
                newRow["failinfo"]   = ex.ToString();
                dtExport.Rows.Add(newRow);
            }
            return(insertflag);
        }