public ContactEntity GetContactByID(string contactid) { ContactEntity model = new ContactEntity(); DataTable dt = CustomDAL.BaseProvider.GetContactByID(contactid); if (dt.Rows.Count > 0) { model.FillData(dt.Rows[0]); } return model; }
public List<ContactEntity> GetContactsByCustomerID(string ownerID, string customerid = "", string agentid = "") { int total = 0; List<ContactEntity> list = new List<ContactEntity>(); string cloumns = " status<>9 and OwnerID='" + ownerID + "'"; if (!string.IsNullOrEmpty(agentid)) { cloumns += " and agentid='" + agentid + "'"; } if (!string.IsNullOrEmpty(customerid)) { cloumns += " and customerid='" + customerid + "'"; } DataTable dt = CommonBusiness.GetPagerData("Contact", "*", cloumns, "CustomerID", int.MaxValue, 1, out total, out total); foreach (DataRow dr in dt.Rows) { ContactEntity model = new ContactEntity(); model.FillData(dr); list.Add(model); } return list; }
public ContactEntity GetContactByDataRow(DataRow dr, bool isQiYe = false) { ContactEntity contact = new ContactEntity(); contact.Address = dr["详细地址"].ToString(); contact.CompanyName = dr["客户名称"].ToString(); contact.Description = dr["描述"].ToString(); contact.Email = dr["邮箱"].ToString(); contact.MobilePhone = dr["联系电话"].ToString(); contact.Jobs = dr["职位"].ToString(); contact.CityCode = GetCityCode(dr); contact.ClientID = CurrentUser.ClientID; contact.AgentID = CurrentUser.AgentID; contact.CreateUserID = CurrentUser.UserID; contact.OwnerID = CurrentUser.UserID; contact.CustomerID = ""; contact.Name = dr["联系人"].ToString(); contact.CreateTime = DateTime.Now; contact.Type = isQiYe ? 1 : 0; contact.ContactID = Guid.NewGuid().ToString(); return contact; }
public List<ContactEntity> GetContactsByCustomerID(string customerid, string agentid) { List<ContactEntity> list = new List<ContactEntity>(); DataTable dt = CustomDAL.BaseProvider.GetContactsByCustomerID(customerid); foreach (DataRow dr in dt.Rows) { ContactEntity model = new ContactEntity(); model.FillData(dr); model.CreateUser = OrganizationBusiness.GetUserByUserID(model.CreateUserID, model.AgentID); model.City = CommonBusiness.Citys.Where(m => m.CityCode == model.CityCode).FirstOrDefault(); list.Add(model); } return list; }
public ActionResult CustomerImport(HttpPostedFileBase file, int overType = 0, int type=0) { if (file == null) { return Content("请选择要导入的文件"); } if (file.ContentLength > 2097152) { return Content("导入文件超过规定(2M )大小,请修改后再操作."); } if (!file.FileName.Contains(".xls") && !file.FileName.Contains(".xlsx")) { return Content("文件格式类型不正确"); } string mes = ""; try { DataTable dt = ImportExcelToDataTable(file); if (dt.Columns.Count > 0) { ///1.获取系统模版列 var checkColumn = dt.Columns.Contains("是否企业客户"); Dictionary<string, ExcelFormatter> dic = new Dictionary<string, ExcelFormatter>(); Dictionary<string, ExcelModel> listColumn = GetColumnForJson("customer", ref dic, checkColumn ? "Item" : "OwnItem", "import", CurrentUser.ClientID); ///2.上传Excel 与模板中列是否一致 不一致返回提示 foreach (DataColumn dc in dt.Columns) { if (default(KeyValuePair<string, ExcelModel>).Equals(listColumn.FirstOrDefault(x => x.Value.Title == dc.ColumnName))) { mes += dc.ColumnName + ","; } } if (!string.IsNullOrEmpty(mes)) { return Content("Excel模版与系统模版不一致,请重新下载模板,编辑后再上传.错误:缺少列 " + mes); } ///3.开始处理 int k = 1; List<CustomerEntity> list = new List<CustomerEntity>(); List<ContactEntity> contactList = new List<ContactEntity>(); var excelWriter = new ExcelWriter(); foreach (DataRow dr in dt.Rows) { try { if (checkColumn) { CustomerEntity customer = new CustomerEntity(); excelWriter.GetProductByDataRow(dr, listColumn, customer, dic, CurrentUser.ClientID); customer.ClientID = CurrentUser.ClientID; customer.AgentID = CurrentUser.AgentID; customer.CreateUserID = CurrentUser.UserID; customer.CreateTime = DateTime.Now; customer.CustomerID = Guid.NewGuid().ToString(); customer.CityCode = GetCityCode(dr); customer.OwnerID = customer.OwnerID.Trim() == "是" ? CurrentUser.UserID : ""; list.Add(customer); //上面出问题的话请注释以上 使用下面 //list.Add(GetCustomerByDataRow(dr)); } else { ContactEntity contact = new ContactEntity(); excelWriter.GetProductByDataRow(dr, listColumn, contact, dic, CurrentUser.ClientID); contact.CityCode = GetCityCode(dr); contact.ClientID = CurrentUser.ClientID; contact.AgentID = CurrentUser.AgentID; contact.CreateUserID = CurrentUser.UserID; contact.OwnerID = CurrentUser.UserID; contact.CustomerID = ""; contact.CreateTime = DateTime.Now; contact.Type = 0; contact.ContactID = Guid.NewGuid().ToString(); contactList.Add(contact); //contactList.Add( GetContactByDataRow(dr, checkColumn)); } } catch (Exception ex) { mes += k +" 原因:"+ex.Message+ ","; } } try { if (list.Count > 0) ExcelImportBusiness.InsertCustomer(list, type, overType); if (contactList.Count > 0) ExcelImportBusiness.InsertContact(contactList, type, overType); } catch (Exception ex) { return Content("系统异常:请联系管理员,错误原因" + ex.Message); } } if (!string.IsNullOrEmpty(mes)) { return Content("部分数据未导入成功,Excel行位置" + mes); } } catch (Exception ex) { return Content("系统异常:请联系管理员,错误原因:" + ex.Message.ToString()); } return Content("操作成功"); }