Example #1
0
        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>");
        }
Example #2
0
        /// <summary>
        /// �õ�һ������ʵ��
        /// </summary>
        public SYCRM.Model.CustomerProduct GetModel(Guid CustomerId,Guid ProductId)
        {
            StringBuilder strSql=new StringBuilder();
            strSql.Append("select  top 1 CustomerId,ProductId,Status from CustomerProduct ");
            strSql.Append(" where CustomerId=@CustomerId and ProductId=@ProductId ");
            SqlParameter[] parameters = {
                    new SqlParameter("@CustomerId", SqlDbType.UniqueIdentifier),
                    new SqlParameter("@ProductId", SqlDbType.UniqueIdentifier)};
            parameters[0].Value = CustomerId;
            parameters[1].Value = ProductId;

            SYCRM.Model.CustomerProduct model=new SYCRM.Model.CustomerProduct();
            DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
            if(ds.Tables[0].Rows.Count>0)
            {
                if(ds.Tables[0].Rows[0]["CustomerId"].ToString()!="")
                {
                    model.CustomerId=new Guid(ds.Tables[0].Rows[0]["CustomerId"].ToString());
                }
                if(ds.Tables[0].Rows[0]["ProductId"].ToString()!="")
                {
                    model.ProductId=new Guid(ds.Tables[0].Rows[0]["ProductId"].ToString());
                }
                if(ds.Tables[0].Rows[0]["Status"].ToString()!="")
                {
                    model.Status=int.Parse(ds.Tables[0].Rows[0]["Status"].ToString());
                }
                return model;
            }
            else
            {
                return null;
            }
        }