public bool UpdateGroupInfo(CustomerAttributeGroupInfoModel model, out string message) { bool result = false; message = "操作失败,请与管理员联系"; model.Tabname = "customer_info_" + CharacterUtil.ConvertToPinyin(model.GroupName); Dictionary <string, CustomerAttributeGroupInfoModel> dict = GetCustomeGroupInfoList(true); CustomerAttributeGroupInfoModel oldInfo = dict[model.GroupId]; try { BeginTransaction(); if (oldInfo.GroupName != model.GroupName) { string NewsTableName = "customer_info_" + CharacterUtil.ConvertToPinyin(model.GroupName); string TableName = "customer_info_" + CharacterUtil.ConvertToPinyin(oldInfo.GroupName); string renSQL = DTableUtil.GetRenameTableSQL(TableName, NewsTableName); ExecuteNonQuery(renSQL); } if (Update(model) == 1) { GetGroupInfoById(model.GroupId, true); message = "成功更新客户分组属性"; result = true; CommitTransaction(); } else { RollbackTransaction(); message = "更新产客户分组属性失败,请与管理员联系"; result = false; } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("更新客户分组属性异常", ex); throw ex; } return(result); }
// 在此添加你的代码.... public bool UpdateCustomerAttribute(CustomerExtAttributesModel attInfo, out string message, string oldName) { bool result = false; message = "操作失败,请与管理员联系"; CustomerExtAttributesModel model = GetCustomerAttributeById(attInfo.ExtAttributeId, true); Dictionary <string, CustomerAttributeGroupInfoModel> dict = CustomerAttributeGroupInfoService.Instance.GetCustomeGroupInfoList(true); CustomerAttributeGroupInfoModel oldInfo = dict[model.GroupId]; try { BeginTransaction(); if (attInfo.AttributeName != oldName) { string TableName = "customer_info_" + CharacterUtil.ConvertToPinyin(oldInfo.GroupName); string renameFieldSQL = DTableUtil.GetRenameFieldSQL(TableName, oldName, attInfo.AttributeName); ExecuteNonQuery(renameFieldSQL); } if (Update(attInfo) == 1) { GetCustomerAttributeList(attInfo.ExtAttributeId, true); message = "成功更新客户属性"; result = true; CommitTransaction(); } else { RollbackTransaction(); message = "更新产客户属性失败,请与管理员联系"; result = false; } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("更新客户属性异常", ex); throw ex; } return(result); }
protected string GetImportProductInfoSQL(ProductCategoryInfoModel catInfo, Dictionary <string, ProductCategoryAttributesModel> proAttList) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("INSERT INTO [{0}] ( ", catInfo.TableName); foreach (ProductCategoryAttributesModel item in proAttList.Values) { sb.AppendFormat(" [{0}],", item.AttributeName); } sb.Append("product_id, product_category_id, category_group_id, created_on, created_by, status_code ) VALUES ( "); foreach (ProductCategoryAttributesModel item in proAttList.Values) { sb.AppendFormat(" ${0}$,", CharacterUtil.ConvertToPinyin(item.AttributeName)); } sb.AppendFormat("$product_id$, $product_category_id$, $category_group_id$, $created_on$, $created_by$, 0 ) "); return(sb.ToString()); }
// 在此添加你的代码... /// <summary> /// 根据ID删除客户分组属性信息。 /// </summary> /// <param name="departmentId"></param> /// <param name="message"></param> /// <returns></returns> public bool DeleteGroupInfoById(string groupid, out string message) { message = "操作失败,请与管理员联系"; bool result = false; Dictionary <string, CustomerAttributeGroupInfoModel> dict = GetCustomeGroupInfoList(true); CustomerAttributeGroupInfoModel oldInfo = dict[groupid]; string TableName = "customer_info_" + CharacterUtil.ConvertToPinyin(oldInfo.GroupName); string deleteCustomerAttributesSQL = "DELETE FROM customer_ext_attributes WHERE group_id = $groupid$;"; ParameterCollection pc = new ParameterCollection(); pc.Add("groupid", groupid); try { BeginTransaction(); if (Delete(groupid) > 0) { ExecuteNonQuery(deleteCustomerAttributesSQL, pc); string dropTableSQL = DTableUtil.GetDropTableSQL(TableName); ExecuteNonQuery(dropTableSQL); CommitTransaction(); result = true; message = "成功删除客户属性信息"; GetCustomeGroupInfoList(true); } else { RollbackTransaction(); } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("删除删除客户属性信息异常", ex); throw ex; } return(result); }
/// <summary> /// 根据ID删除客户属性信息。 /// </summary> /// <param name="departmentId"></param> /// <param name="message"></param> /// <returns></returns> public bool DeleteCustomerAttributeById(string extattributeid, out string message) { message = "操作失败,请与管理员联系"; bool result = false; CustomerExtAttributesModel model = GetCustomerAttributeById(extattributeid, true); Dictionary <string, CustomerAttributeGroupInfoModel> dict = CustomerAttributeGroupInfoService.Instance.GetCustomeGroupInfoList(true); CustomerAttributeGroupInfoModel oldInfo = dict[model.GroupId]; try { BeginTransaction(); string TableName = "customer_info_" + CharacterUtil.ConvertToPinyin(oldInfo.GroupName); string deleteFieldSQL = DTableUtil.GetDeleteFieldSQL(TableName, model.AttributeName); ExecuteNonQuery(deleteFieldSQL); if (Delete(extattributeid) > 0) { CommitTransaction(); result = true; message = "成功删除客户属性信息"; GetCustomerAttributeList(extattributeid, true); } else { RollbackTransaction(); } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("删除删除客户属性信息异常", ex); throw ex; } return(result); }
public bool ImportProductInfoList(DataSet productDataSet, out string importLogs, out string message) { bool result = false; importLogs = ""; message = "操作失败,请与管理员联系"; if (productDataSet == null && productDataSet.Tables.Count == 0) { message = "Excel数据文件异常,请检查"; return(false); } Dictionary <string, ProductCategoryInfoModel> productCategoryList = ProductCategoryInfoService.Instance.GetProductCategoryList(false); if (productCategoryList == null || productCategoryList.Count == 0) { message = "数据库中无产品类型信息,请检查"; return(false); } string productCategoryCode = null, importSQL = null; Dictionary <string, ProductCategoryAttributesModel> proAttList = null; ProductCategoryInfoModel catInfo = null; ParameterCollection pc = new ParameterCollection(); ProductInfoModel proInfo = null; try { BeginTransaction(); for (int t = 0; t < productDataSet.Tables.Count; t++) { if (productDataSet.Tables[t].TableName.Contains("-") == false) { continue; } if (productDataSet.Tables[t].TableName.Split('-')[1] != "产品信息表") { continue; } for (int i = 0; i < productDataSet.Tables[t].Rows.Count; i++) { productCategoryCode = productDataSet.Tables[t].Rows[i]["商品编号"].ToString(); catInfo = ProductCategoryInfoService.Instance.GetProductCategoryInfoByCategoryCode(productCategoryCode); if (productDataSet.Tables[t].Rows[i]["操作"].ToString() == "") { break; } if (catInfo == null) { RollbackTransaction(); message = string.Format("数据库中不存在产品类型编码为【{0}】的产品类型,数据导入失败", productCategoryCode); return(false); } proAttList = ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(catInfo.ProductCategoryId, false); if (proAttList == null) { RollbackTransaction(); message = string.Format("数据库中不存在产品类型编码为【{0}】的产品类型属性数据,数据导入失败", productCategoryCode); return(false); } Dictionary <string, ProductCategorySalesStatusModel> statusList = ProductCategorySalesStatusService.Instance.GetProductCategorySalesStatusList(catInfo.ProductCategoryId, false); if (proAttList == null) { RollbackTransaction(); message = string.Format("数据库中不存在产品类型编码为【{0}】的产品类型销售状态数据,数据导入失败", productCategoryCode); return(false); } importSQL = GetImportProductInfoSQL(catInfo, proAttList); pc.Clear(); foreach (ProductCategoryAttributesModel attInfo in proAttList.Values) { if (attInfo.FieldType == "decmial" && productDataSet.Tables[t].Rows[i][attInfo.AttributeName].ToString() == "") { pc.Add(string.Format("{0}", CharacterUtil.ConvertToPinyin(attInfo.AttributeName)), 0); } else { if (attInfo.AttributeName == "销售状态") { pc.Add(string.Format("{0}", CharacterUtil.ConvertToPinyin(attInfo.AttributeName)), GetProductSaleStatusId(statusList, productDataSet.Tables[t].Rows[i][attInfo.AttributeName].ToString())); } else { pc.Add(string.Format("{0}", CharacterUtil.ConvertToPinyin(attInfo.AttributeName)), productDataSet.Tables[t].Rows[i][attInfo.AttributeName].ToString()); } } } proInfo = new ProductInfoModel(); proInfo.ProductId = GetGuid(); proInfo.CreatedOn = DateTime.Now; proInfo.CategoryId = catInfo.ProductCategoryId; proInfo.ItemPrice = Convert.ToDecimal(productDataSet.Tables[t].Rows[i]["销售价格"].ToString()); proInfo.ProductCode = productDataSet.Tables[t].Rows[i]["产品代码"].ToString(); proInfo.ProductName = productDataSet.Tables[t].Rows[i]["产品名称"].ToString(); proInfo.SalesStatus = productDataSet.Tables[t].Rows[i]["销售状态"].ToString();// productDataSet.Tables[t].Rows[i]["销售状态"].ToString(); // proInfo.SalesStatus = GetProductSaleStatusId(statusList, productDataSet.Tables[t].Rows[i]["销售状态"].ToString());// productDataSet.Tables[t].Rows[i]["销售状态"].ToString(); proInfo.Status = 0; pc.Add("product_id", proInfo.ProductId); pc.Add("product_category_id", proInfo.CategoryId); pc.Add("category_group_id", catInfo.GroupName); pc.Add("created_on", proInfo.CreatedOn); pc.Add("created_by", "C792D747-6B74-4A58-BB5B-D98EF420F99F"); if (Create(proInfo) != 1) { RollbackTransaction(); message = "导入Excel数据失败"; return(false); } else { if (ExecuteNonQuery(importSQL, pc) != 1) { RollbackTransaction(); message = "导入Excel数据失败"; return(false); } } } } CommitTransaction(); } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("从Excel导入产品数据异常", ex); throw ex; } return(result); }
public bool CreateGroupInfo(CustomerAttributeGroupInfoModel model, out string message) { bool result = false; message = "操作失败,请与管理员联系"; model.GroupId = GetGuid(); model.Tabname = "customer_info_" + CharacterUtil.ConvertToPinyin(model.GroupName); if (CheckExistGroupname(model.GroupName)) { message = string.Format("操作失败,已经存在名为【{0}】属性名称", model.GroupName); return(false); } string TableName = "customer_info_" + CharacterUtil.ConvertToPinyin(model.GroupName); #region 创建表字段 List <FieldInfo> fieldList = new List <FieldInfo>(); FieldInfo field = new FieldInfo(); field.FieldName = "customer_id"; field.FieldType = "varchar"; field.MinLength = 50; field.MaxLength = 50; field.IsNull = false; field.IsPrimaryKey = true; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "created_on"; field.FieldType = "datetime"; field.IsNull = false; field.IsPrimaryKey = false; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "created_by"; field.FieldType = "varchar"; field.MinLength = 50; field.MaxLength = 50; field.IsNull = false; field.IsPrimaryKey = false; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "modified_on"; field.FieldType = "datetime"; field.IsNull = true; field.IsPrimaryKey = false; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "modified_by"; field.FieldType = "varchar"; field.MinLength = 50; field.MaxLength = 50; field.IsNull = true; field.IsPrimaryKey = false; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "status_code"; field.FieldType = "int"; field.IsNull = true; fieldList.Add(field); string createTableSql = DTableUtil.GetCreateTableSQL(TableName, fieldList); #endregion try { BeginTransaction(); ExecuteNonQuery(createTableSql); if (Create(model) == 1) { message = "成功创建分组属性"; result = true; GetGroupInfoById(model.GroupId, true); CommitTransaction(); } else { RollbackTransaction(); result = false; message = "创建客户分组属性失败,请与管理员联系"; } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("创建客户分组属性异常", ex); throw ex; } return(result); }
/// <summary> /// 创建产品型信息。 /// </summary> /// <param name="categoryInfo"></param> /// <param name="message"></param> /// <returns></returns> public bool CreateProductCategory(ProductCategoryInfoModel categoryInfo, out string message) { bool result = false; message = "操作失败,请与管理员联系"; if (categoryInfo == null || string.IsNullOrEmpty(categoryInfo.CategoryName)) { message = "缺少参数,请与管理员联系"; return(false); } Dictionary <string, ProductCategoryInfoModel> dict = GetProductCategoryList(false); if (dict != null) { foreach (ProductCategoryInfoModel item in dict.Values) { if (item.CategoryName == categoryInfo.CategoryName) { message = "操作失败,当前存在相同的产品类型名称"; return(false); } } } CustomDataDomainModel SaleCity = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("销售城市", false); string saleCityString = null; foreach (CustomDataValueDomainModel item in SaleCity.ValueList.Values) { saleCityString += item.DataValue + " "; } categoryInfo.ProductCategoryId = GetGuid(); categoryInfo.SortOrder = (dict == null) ? 1 : dict.Count + 1; categoryInfo.TableName = "product_info_" + CharacterUtil.ConvertToPinyin(categoryInfo.CategoryName); #region 创建表字段 List <FieldInfo> fieldList = new List <FieldInfo>(); FieldInfo field = new FieldInfo(); field.FieldName = "product_id"; field.FieldType = "varchar"; field.MinLength = 50; field.MaxLength = 50; field.IsNull = false; field.IsPrimaryKey = true; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "product_category_id"; field.FieldType = "varchar"; field.MinLength = 50; field.MaxLength = 50; field.IsNull = false; field.IsPrimaryKey = false; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "category_group_id"; field.FieldType = "varchar"; field.MinLength = 50; field.MaxLength = 50; field.IsNull = false; field.IsPrimaryKey = false; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "item_price"; field.FieldType = "decimal"; field.MinLength = 18; field.MaxLength = 2; field.DefaultValue = "0"; field.IsNull = false; field.IsPrimaryKey = false; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "created_on"; field.FieldType = "datetime"; field.IsNull = false; field.IsPrimaryKey = false; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "created_by"; field.FieldType = "varchar"; field.MinLength = 50; field.MaxLength = 50; field.IsNull = false; field.IsPrimaryKey = false; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "modified_on"; field.FieldType = "datetime"; field.IsNull = true; field.IsPrimaryKey = false; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "modified_by"; field.FieldType = "varchar"; field.MinLength = 50; field.MaxLength = 50; field.IsNull = true; field.IsPrimaryKey = false; fieldList.Add(field); field = new FieldInfo(); field.FieldName = "status_code"; field.FieldType = "int"; field.IsNull = true; fieldList.Add(field); string createTableSql = DTableUtil.GetCreateTableSQL(categoryInfo.TableName, fieldList); #endregion try { BeginTransaction(); ExecuteNonQuery(createTableSql); if (Create(categoryInfo) == 1) { GetProductCategoryList(true); #region 创建默认字段 ProductCategoryAttributesModel att = new ProductCategoryAttributesModel(); att.AttributeName = "产品代码"; att.CategoryAttributeId = GetGuid(); att.FieldMinLength = 50; att.FieldType = "string"; att.IsDisplay = 0; att.IsRequest = 0; att.NodeId = 0; att.ProductCategoryId = categoryInfo.ProductCategoryId; att.SortOrder = 1; att.Status = 0; if (!ProductCategoryAttributesService.Instance.CreateProductCategoryAttribute(att, out message)) { RollbackTransaction(); return(false); } ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryInfo.ProductCategoryId, true); att = new ProductCategoryAttributesModel(); att.AttributeName = "产品名称"; att.CategoryAttributeId = GetGuid(); att.FieldMinLength = 50; att.FieldType = "string"; att.IsDisplay = 0; att.IsRequest = 0; att.NodeId = 0; att.ProductCategoryId = categoryInfo.ProductCategoryId; att.SortOrder = 2; att.Status = 0; if (!ProductCategoryAttributesService.Instance.CreateProductCategoryAttribute(att, out message)) { RollbackTransaction(); return(false); } ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryInfo.ProductCategoryId, true); att = new ProductCategoryAttributesModel(); att.AttributeName = "销售状态"; att.CategoryAttributeId = GetGuid(); att.FieldMinLength = 50; att.FieldType = "custom"; att.CustomValue = "已建档"; att.IsDisplay = 0; att.IsRequest = 0; att.NodeId = 0; att.ProductCategoryId = categoryInfo.ProductCategoryId; att.SortOrder = 3; att.Status = 0; if (!ProductCategoryAttributesService.Instance.CreateProductCategoryAttribute(att, out message)) { RollbackTransaction(); return(false); } ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryInfo.ProductCategoryId, true); att = new ProductCategoryAttributesModel(); att.AttributeName = "销售城市"; att.CategoryAttributeId = GetGuid(); att.FieldMinLength = 50; att.FieldType = "custom"; att.CustomValue = "所有"; att.IsDisplay = 0; att.IsRequest = 0; att.NodeId = 0; att.ProductCategoryId = categoryInfo.ProductCategoryId; att.SortOrder = 3; att.Status = 0; if (!ProductCategoryAttributesService.Instance.CreateProductCategoryAttribute(att, out message)) { RollbackTransaction(); return(false); } ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryInfo.ProductCategoryId, true); att = new ProductCategoryAttributesModel(); att.AttributeName = "销售价格"; att.CategoryAttributeId = GetGuid(); att.FieldMinLength = 18; att.FieldMaxLength = 2; att.FieldType = "decimal"; att.CustomValue = "0"; att.IsDisplay = 0; att.IsRequest = 0; att.NodeId = 0; att.ProductCategoryId = categoryInfo.ProductCategoryId; att.SortOrder = 4; att.Status = 0; if (!ProductCategoryAttributesService.Instance.CreateProductCategoryAttribute(att, out message)) { RollbackTransaction(); return(false); } ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryInfo.ProductCategoryId, true); #endregion #region 创建默认的销售状态 ProductCategorySalesStatusModel saleStatus = new ProductCategorySalesStatusModel(); saleStatus.ProductCategoryId = categoryInfo.ProductCategoryId; saleStatus.SalesStatusId = GetGuid(); saleStatus.SalestatusName = "已建档"; saleStatus.SortOrder = 1; saleStatus.Status = 0; if (!ProductCategorySalesStatusService.Instance.CreateProductCategorySaleStatus(saleStatus, out message)) { RollbackTransaction(); return(false); } ProductCategorySalesStatusService.Instance.GetProductCategorySalesStatusList(categoryInfo.ProductCategoryId, true); #endregion #region 创建默认的销售城市 ProductCategorySalesStatusModel saleCityList = new ProductCategorySalesStatusModel(); saleCityList.ProductCategoryId = categoryInfo.ProductCategoryId; saleCityList.SalesStatusId = GetGuid(); saleCityList.SalestatusName = "所有"; saleCityList.SortOrder = 1; saleCityList.Status = 0; if (!ProductCategorySalesStatusService.Instance.CreateProductCategorySaleStatus(saleCityList, out message)) { RollbackTransaction(); return(false); } ProductCategorySalesStatusService.Instance.GetProductCategorySalesStatusList(categoryInfo.ProductCategoryId, true); #endregion ProductCategoryAttributesService.Instance.GetProductCategoryAttributeList(categoryInfo.ProductCategoryId, true); GetProductCategoryList(true); message = "成功创建产品类型信息"; result = true; CommitTransaction(); } else { RollbackTransaction(); message = "创建产品类型信息失败"; result = false; } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("创建产品类型异常", ex); throw ex; } return(result); }
/// <summary> /// 更新产品信息。 /// </summary> /// <param name="categoryInfo"></param> /// <param name="message"></param> /// <returns></returns> public bool UpdateProductCategory(ProductCategoryInfoModel categoryInfo, out string message) { bool result = false; message = "操作失败,请与管理员联系"; if (categoryInfo == null || string.IsNullOrEmpty(categoryInfo.CategoryName)) { message = "缺少参数,请与管理员联系"; return(false); } Dictionary <string, ProductCategoryInfoModel> dict = GetProductCategoryList(false); if (dict.ContainsKey(categoryInfo.ProductCategoryId) == false) { message = "操作失败,产品类型ID不存在"; return(false); } foreach (ProductCategoryInfoModel item in dict.Values) { if (item.CategoryName == categoryInfo.CategoryName && item.ProductCategoryId != categoryInfo.ProductCategoryId) { message = "操作失败,当前存在相同的产品类型名称"; return(false); } } ProductCategoryInfoModel oldCatInfo = dict[categoryInfo.ProductCategoryId]; try { BeginTransaction(); if (oldCatInfo.CategoryName != categoryInfo.CategoryName) { categoryInfo.TableName = "product_info_" + CharacterUtil.ConvertToPinyin(categoryInfo.CategoryName); string renSQL = DTableUtil.GetRenameTableSQL(oldCatInfo.TableName, categoryInfo.TableName); ExecuteNonQuery(renSQL); } if (Update(categoryInfo) == 1) { CommitTransaction(); GetProductCategoryList(true); message = "成功更新产品类型信息"; result = true; } else { RollbackTransaction(); message = "更新产品类型信息失败"; result = true; } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("更新产品类型信息异常", ex); throw ex; } return(result); }
public bool ImportCustomerBasicInfo(DataTable customerTable, out string importLogs, out string message) { message = "操作失败,请与管理员联系"; importLogs = ""; bool result = false; if (customerTable == null && customerTable.Rows.Count == 0) { message = "客户信息表为空,请检查Excel文件是否正确"; importLogs = message; return(false); } #region 验证表头 List <CustomerAttributeGroupInfoModel> attGrouList = new List <CustomerAttributeGroupInfoModel>(); CustomerExtAttributesModel attributeInfo = null; for (int i = 0; i < customerTable.Rows.Count; i++) { for (int j = 0; j < customerTable.Columns.Count; j++) { attributeInfo = CustomerExtAttributesInfoService.Instance.GetCustomerExtAttributeInfoModelByAttributeName(customerTable.Columns[j].ColumnName, true); if (attributeInfo == null) { message = string.Format("【{0}】列不存在数据库中", customerTable.Columns[j].ColumnName); return(false); } switch (attributeInfo.FieldType) { case "string": break; case "text": break; case "custom": List <string> customList = attributeInfo.CustomValue.Split(',').ToList(); if (customList != null && customList.Contains(customerTable.Rows[i][j].ToString()) == false) { message = string.Format("因为Excel第【{0}】行第【{0}】列的值不存在于属性名为A的自定义值列表中", customerTable.Rows[i], customerTable.Columns[j]); return(false); } break; case "decimal": if (Framework.Utilities.CharacterUtil.isNumber(customerTable.Rows[i][j].ToString()) == false) { message = string.Format("因为Excel第【{0}】行第【{0}】列的值不为数值", customerTable.Rows[i], customerTable.Columns[j]); return(false); } break; default: break; } } } #endregion CustomerAttributeGroupInfoModel attGroupInfo = CustomerAttributeGroupInfoService.Instance.GetGroupInfoById(attributeInfo.GroupId, false); if (attGroupInfo == null) { message = "操作失败,请与管理员联系"; return(false); } attGrouList.Add(attGroupInfo); List <string> insertSQLList = new List <string>(); foreach (CustomerAttributeGroupInfoModel groupInfo in attGrouList) { StringBuilder insertSQLBuilder = new StringBuilder(); insertSQLBuilder.AppendFormat("INSERT INTO {0} (customer_id, created_on, created_by, status_code,", groupInfo.Tabname); for (int k = 0; k < customerTable.Columns.Count; k++) { attributeInfo = CustomerExtAttributesInfoService.Instance.GetCustomerExtAttributeInfoModelByAttributeName(customerTable.Columns[k].ColumnName, true); if (attributeInfo.GroupId == groupInfo.GroupId) { insertSQLBuilder.AppendFormat("[{0}],", attributeInfo.AttributeName); } } insertSQLBuilder.Length = insertSQLBuilder.Length - 1; insertSQLBuilder.Append(" ) VALUES ( $customer_id$, GETDATE(), $created_by$, 0, "); for (int k = 0; k < customerTable.Columns.Count; k++) { attributeInfo = CustomerExtAttributesInfoService.Instance.GetCustomerExtAttributeInfoModelByAttributeName(customerTable.Columns[k].ColumnName, true); if (attributeInfo.GroupId == groupInfo.GroupId) { insertSQLBuilder.AppendFormat("${0}$,", CharacterUtil.ConvertToPinyin(attributeInfo.AttributeName)); } } insertSQLBuilder.Length = insertSQLBuilder.Length - 1; insertSQLBuilder.Append(" )"); insertSQLList.Add(insertSQLBuilder.ToString()); } try { ParameterCollection pc = new ParameterCollection(); CustomerBasicInfoModel basicInfo = null; BeginTransaction(); for (int i = 0; i < customerTable.Rows.Count; i++) { #region 插入客户基本信息表数据 basicInfo = new CustomerBasicInfoModel(); basicInfo.CustomerId = GetGuid(); basicInfo.MobilePhone = customerTable.Rows[i]["手机号码"].ToString(); basicInfo.HomePhone = customerTable.Rows[i]["电话号码"].ToString(); basicInfo.OtherPhone = customerTable.Rows[i]["其他号码"].ToString(); basicInfo.Sex = (customerTable.Rows[i]["性别"].ToString() == "男") ? 0 : 1; if (!string.IsNullOrEmpty(customerTable.Rows[i]["手机价位"].ToString())) { basicInfo.MobilePhonePrice = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("手机价位", false).GetCustomDataValueDomainByDataValue(customerTable.Rows[i]["手机价位"].ToString()).ValueId; } else { basicInfo.MobilePhonePrice = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("手机价位", false).GetCustomDataValueDomainByDataValue("未知").ValueId; } basicInfo.Level = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("客户等级", false).GetCustomDataValueDomainByDataValue(customerTable.Rows[i]["客户等级"].ToString()).ValueId; if (!string.IsNullOrEmpty(customerTable.Rows[i]["运营商"].ToString())) { basicInfo.Carriers = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("运营商", false).GetCustomDataValueDomainByDataValue(customerTable.Rows[i]["运营商"].ToString()).ValueId; } else { basicInfo.Carriers = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("运营商", false).GetCustomDataValueDomainByDataValue("未知").ValueId; } basicInfo.UsingPhoneType = customerTable.Rows[i]["手机型号"].ToString(); basicInfo.CommunicationConsumer = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("通讯消费", false).GetCustomDataValueDomainByDataValue(customerTable.Rows[i]["通讯消费"].ToString()).ValueId; basicInfo.PreferredPhoneBrand = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("优选品牌", false).GetCustomDataValueDomainByDataValue(customerTable.Rows[i]["优选品牌"].ToString()).ValueId; basicInfo.UsingPhoneBrand = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("优选品牌", false).GetCustomDataValueDomainByDataValue(customerTable.Rows[i]["在用品牌"].ToString()).ValueId; basicInfo.UsingSmartphone = (customerTable.Rows[i]["是否智能机"].ToString() == "是") ? 0 : 1; basicInfo.SalesFrom = CustomDataInfoService.Instance.GetCustomDataDomainModelByName("客户来源", false).GetCustomDataValueDomainByDataValue(customerTable.Rows[i]["客户来源"].ToString()).ValueId; basicInfo.CustomerCode = "C" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + i; PhoneLocationInfoModel loc = PhoneLocationInfoService.Instance.GetLocationInfo(basicInfo.MobilePhone, false); basicInfo.CustomerId = GetGuid(); if (loc != null) { basicInfo.ChinaId = loc.ChinaId; basicInfo.ComeFrom = loc.City; } else { basicInfo.ComeFrom = ""; } if (!string.IsNullOrEmpty(basicInfo.MobilePhone)) { if (CheckExistPhoneNumber(basicInfo.MobilePhone)) { continue; } } if (!string.IsNullOrEmpty(basicInfo.HomePhone)) { if (CheckExistPhoneNumber(basicInfo.HomePhone)) { continue; } } if (!string.IsNullOrEmpty(basicInfo.OtherPhone)) { if (CheckExistPhoneNumber(basicInfo.OtherPhone)) { continue; } } #endregion pc.Clear(); pc.Add("customer_id", basicInfo.CustomerId); pc.Add("created_by", SessionUtil.Current.UserId); for (int k = 0; k < customerTable.Columns.Count; k++) { pc.Add(CharacterUtil.ConvertToPinyin(customerTable.Columns[k].ColumnName), customerTable.Rows[i][k].ToString()); } if (CustomerBasicInfoService.Instance.Create(basicInfo) > 0) { foreach (string sql in insertSQLList) { if (DbUtil.Current.IData.ExecuteNonQuery(sql, pc) != 1) { RollbackTransaction(); message = ""; return(false); } } #region 判断插入customer_phone_info表 if (!string.IsNullOrEmpty(basicInfo.MobilePhone)) { if (!CustomerPhoneInfoService.Instance.CreateCustomerPhoneInfo(basicInfo.MobilePhone, basicInfo.CustomerId, out message)) { RollbackTransaction(); return(false); } } if (!string.IsNullOrEmpty(basicInfo.HomePhone)) { if (!CustomerPhoneInfoService.Instance.CreateCustomerPhoneInfo(basicInfo.HomePhone, basicInfo.CustomerId, out message)) { RollbackTransaction(); return(false); } } if (!string.IsNullOrEmpty(basicInfo.OtherPhone)) { if (!CustomerPhoneInfoService.Instance.CreateCustomerPhoneInfo(basicInfo.OtherPhone, basicInfo.CustomerId, out message)) { RollbackTransaction(); return(false); } } #endregion CustomerInfoService.Instance.GetCustomerDomainModelById(basicInfo.CustomerId, true); } } CommitTransaction(); message = "成功添加客户信息"; result = true; } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("导入客户信息异常", ex); throw ex; } return(result); }
public bool CreateCustomerAttribute(CustomerExtAttributesModel attInfo, out string message) { bool result = false; message = "操作失败,请与管理员联系"; CustomerAttributeGroupInfoModel GroupInfoModel = null; GroupInfoModel = CustomerAttributeGroupInfoService.Instance.GetCustomerGroupFromDatabase(attInfo.GroupId); if (attInfo.FieldType.ToLower() == "string") { if (attInfo.FieldMinLength <= 1 || attInfo.FieldMaxLength <= 1 || attInfo.FieldMaxLength <= attInfo.FieldMinLength) { message = "属性字段长度有误,请检查输入"; return(false); } } if (CheckExistAttributename(attInfo.AttributeName)) { message = string.Format("操作失败,已经存在名为【{0}】属性名称", attInfo.AttributeName); return(false); } Dictionary <string, CustomerAttributeGroupInfoModel> dict = CustomerAttributeGroupInfoService.Instance.GetCustomeGroupInfoList(false); attInfo.SortOrder = (dict == null) ? 1 : dict.Count + 1; string TableName = "customer_info_" + CharacterUtil.ConvertToPinyin(GroupInfoModel.GroupName); #region 添加属性 attInfo.ExtAttributeId = Guid.NewGuid().ToString(); attInfo.SortOrder = (dict == null) ? 1 : dict.Count + 1; attInfo.NodeId = "0"; attInfo.ParnetId = "0"; FieldInfo fieldInfo = new FieldInfo(); fieldInfo.FieldName = attInfo.AttributeName; if (attInfo.FieldType == "string" || attInfo.FieldType == "custom") { fieldInfo.FieldType = "varchar"; fieldInfo.MinLength = Convert.ToInt32(attInfo.FieldMinLength); fieldInfo.MaxLength = Convert.ToInt32(attInfo.FieldMaxLength); } else { fieldInfo.FieldType = attInfo.FieldType; fieldInfo.MinLength = Convert.ToInt32(attInfo.FieldMinLength); fieldInfo.MaxLength = Convert.ToInt32(attInfo.FieldMaxLength); } if (fieldInfo.MinLength < 0 && fieldInfo.FieldType == "varchar") { fieldInfo.MinLength = 50; } if (fieldInfo.MaxLength < 0 && fieldInfo.FieldType == "varchar") { fieldInfo.MaxLength = 50; } if (attInfo.FieldType == "text") { fieldInfo.FieldType = "varchar"; fieldInfo.MaxLength = -1; } fieldInfo.DefaultValue = attInfo.DefaultValue; fieldInfo.Description = attInfo.Description; string addFieldSQL = DTableUtil.GetAddFieldSQL(TableName, fieldInfo); #endregion try { BeginTransaction(); if (Create(attInfo) == 1) { ExecuteNonQuery(addFieldSQL); message = "成功创建客户属性"; result = true; GetCustomerAttributeList(attInfo.ExtAttributeId, true); CommitTransaction(); } else { RollbackTransaction(); result = false; message = "创建客户属性失败,请与管理员联系"; } } catch (Exception ex) { RollbackTransaction(); LogUtil.Error("创建客户属性异常", ex); throw ex; } return(result); }