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 { } } }
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>"); }
private bool IsExistPhone(string strPhone) { SYCRM.BLL.Customer customer = new SYCRM.BLL.Customer(); List<SYCRM.Model.Customer> cList = customer.GetModelList("Phone='" + strPhone+"'"); if (cList.Count == 0) { return false; } return true; }
protected void tbnReload_Click(object sender, EventArgs e) { List<SYCRM.Model.Area> listMA = GetOwnArea(areaId); string strWhere = " 1=1 and ("; hdCheckList.Value = ""; foreach (SYCRM.Model.Area a in listMA) { string strValue = Request.Form["chk_" + a.Id.ToString()]; if (strValue == "on") { strWhere += " Area = '" + a.Id.ToString() + "' or "; hdCheckList.Value += a.Id.ToString() + "."; } } strWhere += " 1<>1) order by Area desc, Code desc"; List<SYCRM.Model.Customer> customerList = new List<SYCRM.Model.Customer>(); SYCRM.BLL.Customer customerBll = new SYCRM.BLL.Customer(); customerList = customerBll.GetModelList(strWhere); gvCustomer.DataSource = handleAList(customerList); gvCustomer.DataBind(); }
private void BindGv(Guid areaID) { string sqlwhere = " Area='" + areaId + "' "; //新加搜索 string strSearchContion = hdSearchCondition.Value; if (!String.IsNullOrEmpty(strSearchContion)) { sqlwhere+=" and "; string[] arrSearchContion = strSearchContion.Split('&'); sqlwhere += "("; foreach (string s in arrSearchContion) { if (String.IsNullOrEmpty(s)) { continue; } string[] arrS = s.Split(','); sqlwhere += "("; sqlwhere += "[Name] like '%" + Server.UrlDecode(arrS[0]) + "%' and "; sqlwhere += "BabyName like '%" + Server.UrlDecode(arrS[1]) + "%' and "; if (arrS[2] != "0") sqlwhere += "BabySex = " + arrS[2] + " and "; if (!String.IsNullOrEmpty(arrS[3])) { int startmonth = 1; int startday = 1; try { startmonth = int.Parse(arrS[3].Substring(0, arrS[3].IndexOf("-"))); startday = int.Parse(arrS[3].Substring(arrS[3].IndexOf("-") + 1, arrS[3].Length - arrS[3].IndexOf("-") - 1)); } catch { Page.RegisterStartupScript("", "<script>alert('宝宝生日格式不正确!');</script>"); } sqlwhere += "(DATEPART(mm,[BadyBirthday])>" + startmonth.ToString() + " or DATEPART(mm,[BadyBirthday])=" + startmonth.ToString() + " and DATEPART(dd,[BadyBirthday])>=" + startday.ToString() + " ) and "; } if (!String.IsNullOrEmpty(arrS[4])) { int endmonth = 1; int endday = 1; try { endmonth = int.Parse(arrS[4].Substring(0, arrS[4].IndexOf("-"))); endday = int.Parse(arrS[4].Substring(arrS[4].IndexOf("-") + 1, arrS[4].Length - arrS[4].IndexOf("-") - 1)); } catch { Page.RegisterStartupScript("", "<script>alert('宝宝生日格式不正确!');</script>"); } sqlwhere += "(DATEPART(m,[BadyBirthday])<" + endmonth.ToString() + " or DATEPART(m,[BadyBirthday])=" + endmonth.ToString() + " and DATEPART(d,[BadyBirthday])=" + endday.ToString() + " ) and "; } int startcode = 0, endcode = 0; if (!String.IsNullOrEmpty(arrS[6]) && int.TryParse(arrS[6], out startcode)) { sqlwhere += "[Code] >=" + startcode + " and "; } else if (!String.IsNullOrEmpty(arrS[6])) { Page.RegisterStartupScript("", "<script>alert('编码不合法!');</script>"); return; } if (!String.IsNullOrEmpty(arrS[7]) && int.TryParse(arrS[7], out endcode)) { sqlwhere += "[Code] <=" + endcode + " and "; } else if (!String.IsNullOrEmpty(arrS[7])) { Page.RegisterStartupScript("", "<script>alert('编码不合法!');</script>"); return; } if (String.IsNullOrEmpty(arrS[8])) sqlwhere += "Phone like '%" + Server.UrlDecode(arrS[8]) + "%'"; else { sqlwhere = sqlwhere.Remove(sqlwhere.Length - 4, 4); } sqlwhere += ")"; if (arrS[5] == "0") { sqlwhere += " or"; } else { sqlwhere += " and"; } } int length = 2; if (sqlwhere.EndsWith("and")) length = 3; sqlwhere = sqlwhere.Remove(sqlwhere.Length - length, length); sqlwhere += ")"; } //新加搜索结束 List<SYCRM.Model.Customer> customerList = new List<SYCRM.Model.Customer>(); SYCRM.BLL.Customer customerBll = new SYCRM.BLL.Customer(); customerList = customerBll.GetModelList(sqlwhere); gvCustomer.DataSource = handleAList(customerList); gvCustomer.DataBind(); }
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; }
void bindUnGv(bool first) { Guid areaid = new Guid("d722f5e8-5832-4946-9b5e-be2cff806fc0"); List<SYCRM.Model.Area> listMA = GetOwnArea(areaid); List<SYCRM.Model.Customer> listCustomer = new List<SYCRM.Model.Customer>(); SYCRM.BLL.Customer customer = new SYCRM.BLL.Customer(); if (!first) { string condition =String.Empty; hdCheckList.Value = ""; condition +="(Area in ("; foreach (SYCRM.Model.Area a in listMA) { string strValue = Request.Form["chk_" + a.Id.ToString()]; if (strValue == "on") { //listCustomer.AddRange(listUnCustomer.Where(Item => Item.Area == a.Id).ToList()); hdCheckList.Value += a.Id.ToString() + "."; condition+="'"+a.Id+"',"; } } condition = condition.Remove(condition.Length - 1, 1); condition+="))"; condition += " and "; string strSearchContion = hdSearchCondition.Value; string[] arrSearchContion = strSearchContion.Split('&'); condition += "("; foreach (string s in arrSearchContion) { if (String.IsNullOrEmpty(s)) { continue; } string[] arrS =s.Split(','); condition += "("; condition += "[Name] like '%" + Server.UrlDecode(arrS[0]) + "%' and "; condition += "BabyName like '%" + Server.UrlDecode(arrS[1]) + "%' and "; if(arrS[2]!="0") condition += "BabySex = " + arrS[2] + " and "; if(!String.IsNullOrEmpty(arrS[3])) { int startmonth =1; int startday=1; try { startmonth = int.Parse(arrS[3].Substring(0, arrS[3].IndexOf("-"))); startday = int.Parse(arrS[3].Substring(arrS[3].IndexOf("-")+1, arrS[3].Length - arrS[3].IndexOf("-")-1)); } catch { Page.RegisterStartupScript("", "<script>alert('宝宝生日格式不正确!');</script>"); } condition += "(DATEPART(mm,[BadyBirthday])>" + startmonth.ToString() + " or DATEPART(mm,[BadyBirthday])=" + startmonth.ToString() + " and DATEPART(dd,[BadyBirthday])>=" + startday.ToString() + " ) and "; } if (!String.IsNullOrEmpty(arrS[4])) { int endmonth = 1; int endday = 1; try { endmonth = int.Parse(arrS[4].Substring(0, arrS[4].IndexOf("-"))); endday = int.Parse(arrS[4].Substring(arrS[4].IndexOf("-")+1, arrS[4].Length - arrS[4].IndexOf("-")-1)); } catch { Page.RegisterStartupScript("", "<script>alert('宝宝生日格式不正确!');</script>"); } condition += "(DATEPART(m,[BadyBirthday])<" + endmonth.ToString() + " or DATEPART(m,[BadyBirthday])=" + endmonth.ToString() + " and DATEPART(d,[BadyBirthday])=" + endday.ToString() + " ) and "; } if (arrS[5] != "0") condition += "Id in (Select CustomerId From CustomerProduct Where ProductId = '" + arrS[5] + "') and "; int startcode=0,endcode=0; if (!String.IsNullOrEmpty(arrS[7]) && int.TryParse(arrS[7], out startcode)) { condition += "[Code] >=" + startcode + " and "; } else if (!String.IsNullOrEmpty(arrS[7])) { Page.RegisterStartupScript("", "<script>alert('编码不合法!');</script>"); return; } if (!String.IsNullOrEmpty(arrS[8]) && int.TryParse(arrS[8], out endcode)) { condition += "[Code] <=" + endcode + " and "; } else if (!String.IsNullOrEmpty(arrS[8])) { Page.RegisterStartupScript("", "<script>alert('编码不合法!');</script>"); return; } if(!String.IsNullOrEmpty(arrS[9])) condition += "[AgentId] in (Select Id From Agent Where Name like '%" + Server.UrlDecode(arrS[9]) + "%') and "; if(String.IsNullOrEmpty(arrS[10])) condition += "Phone like '%" + Server.UrlDecode(arrS[10]) + "%'"; else { condition = condition.Remove(condition.Length - 4, 4); } condition+=")"; if (arrS[6] == "0") { condition += " or"; } else { condition += " and"; } } int length = 2; if (condition.EndsWith("and")) length = 3; condition = condition.Remove(condition.Length - length, length); condition += ")"; listCustomer = customer.GetModelList(condition); listCustomer = HandleList(listCustomer); //if (tbUName.Text.Trim() != "") //{ // listCustomer = // listCustomer.Where(Item => Item.Name.Contains(tbUName.Text.Trim())).ToList(); //} //if (tbUBabyName.Text.Trim() != "") //{ // listCustomer = // listCustomer.Where(Item => Item.BabyName.Contains(tbUBabyName.Text.Trim())).ToList(); //} //if (ddUlBabySex.SelectedValue != "0") //{ // int iSex = int.Parse(ddUlBabySex.SelectedValue); // listCustomer = // listCustomer.Where(Item => Item.BabySex == iSex).ToList(); //} //if (ddlUProduct.SelectedValue != "0") //{ // listCustomer = // listCustomer.Where(Item => Item.ProductName.Contains(ddlUProduct.SelectedValue)).ToList(); //} GridViewUnList.DataSource = listCustomer; listUnNowCustomer = listCustomer; } else { GridViewUnList.DataSource = listUnCustomer; listUnNowCustomer = listUnCustomer; } GridViewUnList.DataBind(); ltrUnDes.Text = (GridViewUnList.PageIndex+1).ToString() + "/" + GridViewUnList.PageCount.ToString() + " " + GridViewUnList.PageSize.ToString() + "/" + listUnNowCustomer.Count.ToString(); }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { List<SYCRM.Model.Customer> listMC = new List<SYCRM.Model.Customer>(); SYCRM.BLL.Customer BC = new SYCRM.BLL.Customer(); string strWhere = " status=1 "; strWhere += " order by [AgentId] asc, Name asc,BabyName asc "; listMC = HandleList(BC.GetModelList("")); if (Type == "1") { ltrType.Text = "生日问候"; DateTime now = DateTime.Now.AddDays(7.0D); DateTime start = now.AddDays(0 - double.Parse(((int)now.DayOfWeek).ToString())); DateTime end = start.AddDays(6.0D); listMC = listMC.Where(item => item.thisyearB >= start && item.thisyearB <= end).ToList(); } else if (Type == "2") { ltrType.Text = "节日问候"; } else if (Type == "3") { ltrType.Text = "活动互动"; } else { ltrType.Text = "普通"; } listUnCustomer = listMC; listCCustomer = null; BindData(); bindUnGv(true); bindddl(); } }