protected void btnAdd_Click(object sender, EventArgs e) { SYCRM.Model.Product MF = new SYCRM.Model.Product(); SYCRM.BLL.Product BF = new SYCRM.BLL.Product(); { MF.Name = tbName.Text; MF.status = 1; BF.Add(MF); tbName.Text = ""; Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "添加成功!", "<script>alert('添加成功!');window.location.href=window.location.href</script>"); } }
protected void btnEdit_Click(object sender, EventArgs e) { SYCRM.Model.Product MF = new SYCRM.Model.Product(); SYCRM.BLL.Product BF = new SYCRM.BLL.Product(); { MF = BF.GetModel(new Guid(hfPid.Value.Trim())); MF.Name = tbEName.Text; BF.Update(MF); tbEName.Text = ""; hfPid.Value = ""; Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "修改成功!", "<script>alert('修改成功!');window.location.href=window.location.href</script>"); } }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public SYCRM.Model.Product GetModel(Guid Id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 * from Product "); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.UniqueIdentifier)}; parameters[0].Value = Id; SYCRM.Model.Product model=new SYCRM.Model.Product(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["Id"].ToString()!="") { model.Id=new Guid(ds.Tables[0].Rows[0]["Id"].ToString()); } model.Name=ds.Tables[0].Rows[0]["Name"].ToString(); if(ds.Tables[0].Rows[0]["status"].ToString()!="") { model.status=int.Parse(ds.Tables[0].Rows[0]["status"].ToString()); } if (ds.Tables[0].Rows[0]["Code"].ToString() != "") { model.Code = int.Parse(ds.Tables[0].Rows[0]["Code"].ToString()); } return model; } else { return null; } }