protected void bindDetail(Guid cusId) { SYCRM.Model.Customer cus = new SYCRM.Model.Customer(); SYCRM.BLL.Customer cusBll = new SYCRM.BLL.Customer(); cus = cusBll.GetModel(cusId); tbName.Value = cus.Name; tbage.Value = cus.UserAge.ToString(); if (cus.UserSex == 1) { sexman.Checked = true; } else { sexwoman.Checked = true; } tbbabayname.Value = cus.BabyName; if (cus.BabySex == 1) { sexboy.Checked = true; } else { sexgirl.Checked = true; } tbbrithday.Value = cus.BadyBirthday.ToString(); tbtel.Value = cus.Phone; tbaddress.Value = cus.Address; tbdes.Value = cus.Des; ddlAgent.SelectedValue = cus.AgentId.ToString(); areaId = cus.Area; hdAreaId.Value = areaId.ToString(); List<SYCRM.Model.CustomerProduct> listAllCP = new List<SYCRM.Model.CustomerProduct>(); SYCRM.BLL.CustomerProduct bcp = new SYCRM.BLL.CustomerProduct(); listAllCP = bcp.GetModelList(""); List<SYCRM.Model.Product> listAllP = new List<SYCRM.Model.Product>(); SYCRM.BLL.Product bp = new SYCRM.BLL.Product(); listAllP = bp.GetModelList(""); List<SYCRM.Model.CustomerProduct> listtempCP = listAllCP.Where(Item => Item.CustomerId == cus.Id && Item.Status == 1).ToList(); List<SYCRM.Model.Product> listtempP = new List<SYCRM.Model.Product>(); if (listtempCP.Count > 0) { listtempP = listAllP.Where(Item => listtempCP.Where(b => b.ProductId == Item.Id).Count() > 0 && Item.status == 1).ToList(); if (listtempP.Count > 0) { foreach (SYCRM.Model.Product p in listtempP) { ListItem li = dbProduct.Items.FindByValue(p.Id.ToString()); if (li != null) { li.Selected = true; } } } else { } } }
private void bindPage() { SYCRM.Model.Customer cus = new SYCRM.Model.Customer(); SYCRM.BLL.Customer cusBll = new SYCRM.BLL.Customer(); cus = cusBll.GetModel(cusId); lbName.Text = cus.Name; lbage.Text = cus.UserAge.ToString(); if (cus.UserSex == 1) { lbsex.Text = "男"; } else { lbsex.Text = "女"; } if (cus.Area != null) { SYCRM.BLL.Area areaBll = new SYCRM.BLL.Area(); SYCRM.Model.Area area = areaBll.GetModel(cus.Area); if (area != null) { lbarea.Text = area.Name; } } SYCRM.Model.Agent a = Session["User"] as SYCRM.Model.Agent; if (a.AreaId != null) { List<SYCRM.Model.Area> listA = GetOwnArea(a.AreaId); if (listA == null) { NoP(); return; } if (cus.Area == a.AreaId) { hdP.Value = "2"; } else if (listA.Where(Items => Items.Id == cus.Area).ToList().Count > 0) { hdP.Value = "1"; } else { NoP(); } } else { NoP(); return; } lbbabayname.Text = cus.BabyName; lbbabysex.Text = cus.BabySexName; lbbrithday.Text = cus.BadyBirthday.ToString(); lbtel.Text = cus.Phone.ToString(); lbaddress.Text = cus.Address; if (cus.AgentId != null) { SYCRM.BLL.Agent agentBll = new SYCRM.BLL.Agent(); SYCRM.Model.Agent agent = agentBll.GetModel(cus.AgentId); if (agent != null) { lbagent.Text = agent.Name; } } lbdes.Text = cus.Des; lbAddTime.Text = cus.AddTime.Value.ToShortDateString().ToString(); if (cus.AddUserId != null) { SYCRM.BLL.Agent agentBll = new SYCRM.BLL.Agent(); SYCRM.Model.Agent agent = agentBll.GetModel(cus.AddUserId); if (agent != null) { lbAaddUser.Text = agent.Name; } } List<SYCRM.Model.CustomerProduct> listAllCP = new List<SYCRM.Model.CustomerProduct>(); SYCRM.BLL.CustomerProduct bcp = new SYCRM.BLL.CustomerProduct(); listAllCP = bcp.GetModelList(""); List<SYCRM.Model.Product> listAllP = new List<SYCRM.Model.Product>(); SYCRM.BLL.Product bp = new SYCRM.BLL.Product(); listAllP = bp.GetModelList(""); List<SYCRM.Model.CustomerProduct> listtempCP = listAllCP.Where(Item => Item.CustomerId == cus.Id && Item.Status == 1).ToList(); List<SYCRM.Model.Product> listtempP = new List<SYCRM.Model.Product>(); if (listtempCP.Count > 0) { listtempP = listAllP.Where(Item => listtempCP.Where(b => b.ProductId == Item.Id).Count() > 0 && Item.status == 1).ToList(); if (listtempP.Count > 0) { foreach (SYCRM.Model.Product p in listtempP) { cus.ProductName += p.Code.ToString()+" "+p.Name +" "; } } else { cus.ProductName = "无"; } } lbproduct.Text = cus.ProductName; }
protected void btnAdd_Click(object sender, EventArgs e) { bool isModi = false; SYCRM.Model.Customer cus = new SYCRM.Model.Customer(); SYCRM.BLL.Customer cusBll = new SYCRM.BLL.Customer(); if (IsExistPhone(tbtel.Value.Trim())) { Page.RegisterStartupScript("", "<script>alert('重复客户请查对!');</script>"); return; } if (hdUserId.Value != "") { if (cusBll.GetModel(new Guid(hdUserId.Value)) != null) { cus = cusBll.GetModel(new Guid(hdUserId.Value)); isModi = true; } } cus.Name = tbName.Value; if (sexman.Checked == true) { cus.UserSex = 1; } else { cus.UserSex = 2; } int age = 0; if (int.TryParse(tbage.Value, out age)) { cus.UserAge = int.Parse(tbage.Value); } cus.Area = new Guid(hdAreaId.Value); cus.BabyName = tbbabayname.Value; DateTime brithday = default(DateTime); if (DateTime.TryParse(tbbrithday.Value, out brithday)) { cus.BadyBirthday = DateTime.Parse(tbbrithday.Value); } if (sexboy.Checked == true) { cus.BabySex = 1; } else { cus.BabySex = 2; } cus.Phone = tbtel.Value; cus.Address = tbaddress.Value; cus.Des = tbdes.Value; cus.status = 1; SYCRM.Model.Agent manauser = Session["User"] as SYCRM.Model.Agent; cus.AddUserId = manauser.Id; cus.AddTime = System.DateTime.Now; if (ddlAgent.SelectedIndex != 0) { try { cus.AgentId = new Guid(ddlAgent.SelectedValue); } catch (Exception ex) { } } if (isModi) { cusBll.Update(cus); } else { cusBll.Add(cus); } SYCRM.Model.CustomerProduct cuspro = new SYCRM.Model.CustomerProduct(); SYCRM.BLL.CustomerProduct cusproBll = new SYCRM.BLL.CustomerProduct(); IList<SYCRM.Model.CustomerProduct> cusproList = new List<SYCRM.Model.CustomerProduct>(); try { cusproList = cusproBll.GetModelList("CustomerId='" + cus.Id + "'"); for (int i = cusproList.Count - 1; i >= 0; i--) { cusproBll.Delete(cusproList[i].CustomerId, cusproList[i].ProductId); } for (int i = 0; i < dbProduct.Items.Count; i++) { if (dbProduct.Items[i].Selected) { cuspro.CustomerId = cus.Id; cuspro.ProductId = new Guid(dbProduct.Items[i].Value); cuspro.Status = 1; cusproBll.Add(cuspro); } } } catch (Exception ex) { } Page.RegisterStartupScript("", "<script>alert('添加成功!');window.location.href='CustomerList.aspx';</script>"); }
List<SYCRM.Model.Customer> HandleList(List<SYCRM.Model.Customer> list) { List<SYCRM.Model.CustomerProduct> listAllCP = new List<SYCRM.Model.CustomerProduct>(); SYCRM.BLL.CustomerProduct bcp = new SYCRM.BLL.CustomerProduct(); listAllCP = bcp.GetModelList(""); List<SYCRM.Model.Product> listAllP = new List<SYCRM.Model.Product>(); SYCRM.BLL.Product bp = new SYCRM.BLL.Product(); listAllP = bp.GetModelList(""); List<SYCRM.Model.Agent> listAllA = new List<SYCRM.Model.Agent>(); SYCRM.BLL.Agent ba = new SYCRM.BLL.Agent(); listAllA = ba.GetModelList(""); List<SYCRM.Model.Area> listAllAA = new List<SYCRM.Model.Area>(); SYCRM.BLL.Area baa = new SYCRM.BLL.Area(); listAllAA = baa.GetModelList(""); foreach (SYCRM.Model.Customer c in list) { #region 产品 List<SYCRM.Model.CustomerProduct> listtempCP = listAllCP.Where(Item => Item.CustomerId == c.Id && Item.Status==1).ToList(); List<SYCRM.Model.Product> listtempP = new List<SYCRM.Model.Product>(); if (listtempCP.Count > 0) { listtempP = listAllP.Where(Item => listtempCP.Where(b => b.ProductId == Item.Id).Count() > 0 && Item.status == 1).ToList(); if (listtempP.Count > 0) { foreach(SYCRM.Model.Product p in listtempP) { c.ProductName += p.Name+ " "; } } else { c.ProductName = "无"; } } else { c.ProductName = "无"; } #endregion #region 区域 List<SYCRM.Model.Area> listTempAA = new List<SYCRM.Model.Area>(); listTempAA = listAllAA.Where(item => item.Id == c.Area).ToList(); if (listTempAA.Count > 0) { string strName = listTempAA[0].Name; if (listTempAA[0].status == 2) { strName = listTempAA[0].Name + "(已删除)"; } c.AreaName = strName; } else { c.AreaName = "无"; } #endregion #region 服务人员 List<SYCRM.Model.Agent> listTempA = new List<SYCRM.Model.Agent>(); listTempA = listAllA.Where(item => item.Id == c.AgentId).ToList(); if (listTempA.Count > 0) { string strName = listTempA[0].Name; if (listTempA[0].status == 2) { strName = listTempA[0].Name + "(已删除)"; } c.ChargeName = strName; } else { c.ChargeName = "无"; } #endregion } return list; }