/// <summary> /// 增加一条数据 /// </summary> public int Add(TSM.Model.CK_Product model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CK_Product("); strSql.Append("CK_ProductTypeID,CK_ProductName,CK_ProductPrice)"); strSql.Append(" values ("); strSql.Append("@CK_ProductTypeID,@CK_ProductName,@CK_ProductPrice)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@CK_ProductTypeID", SqlDbType.Int, 4), new SqlParameter("@CK_ProductName", SqlDbType.VarChar, 100), new SqlParameter("@CK_ProductPrice", SqlDbType.Decimal, 9) }; parameters[0].Value = model.CK_ProductTypeID; parameters[1].Value = model.CK_ProductName; parameters[2].Value = model.CK_ProductPrice; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
private void LoadData() { btnClose.OnClientClick = ActiveWindow.GetHideReference(); DataSet ds = m_bllCK_ProductType.GetList(""); DropDownListProductType.DataTextField = "CK_ProductTypeName"; DropDownListProductType.DataValueField = "CK_ProductTypeID"; DropDownListProductType.DataSource = ds.Tables[0]; DropDownListProductType.DataBind(); DropDownListProductType.SelectedIndex = 0; int id = GetQueryIntValue("id"); TSM.Model.CK_Product modelCK_Product = m_bllCK_Product.GetModel(id); if (modelCK_Product == null) { // 参数错误,首先弹出Alert对话框然后关闭弹出窗口 Alert.Show("参数错误!", String.Empty, ActiveWindow.GetHideReference()); return; } tbxName.Text = modelCK_Product.CK_ProductName; tbxPrice.Text = modelCK_Product.CK_ProductPrice.ToString(); DropDownListProductType.SelectedValue = modelCK_Product.CK_ProductTypeID.ToString(); }
private void SaveProduct() { TSM.Model.CK_Product modelCK_Product = new TSM.Model.CK_Product(); modelCK_Product.CK_ProductName = tbxName.Text.Trim(); modelCK_Product.CK_ProductPrice = Convert.ToDecimal(tbxPrice.Text.Trim()); //modelCK_Product.CK_Comment = tbxNote.Text.Trim(); modelCK_Product.CK_ProductTypeID = int.Parse(DropDownListProductType.SelectedValue); m_bllCK_Product.Add(modelCK_Product); }
protected void btnSaveClose_Click(object sender, EventArgs e) { int id = GetQueryIntValue("id"); TSM.Model.CK_Product modelCK_Product = m_bllCK_Product.GetModel(id); modelCK_Product.CK_ProductName = tbxName.Text.Trim(); modelCK_Product.CK_ProductPrice = Convert.ToDecimal(tbxPrice.Text.Trim()); modelCK_Product.CK_ProductTypeID = int.Parse(DropDownListProductType.SelectedValue); m_bllCK_Product.Update(modelCK_Product); //FineUI.Alert.Show("保存成功!", String.Empty, FineUI.Alert.DefaultIcon, FineUI.ActiveWindow.GetHidePostBackReference()); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); }
/// <summary> /// 更新一条数据 /// </summary> public void Update(TSM.Model.CK_Product model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CK_Product set "); strSql.Append("CK_ProductTypeID=@CK_ProductTypeID,"); strSql.Append("CK_ProductName=@CK_ProductName,"); strSql.Append("CK_ProductPrice=@CK_ProductPrice"); strSql.Append(" where CK_ProductID=@CK_ProductID "); SqlParameter[] parameters = { new SqlParameter("@CK_ProductID", SqlDbType.Int, 4), new SqlParameter("@CK_ProductTypeID", SqlDbType.Int, 4), new SqlParameter("@CK_ProductName", SqlDbType.VarChar, 100), new SqlParameter("@CK_ProductPrice", SqlDbType.Decimal, 9) }; parameters[0].Value = model.CK_ProductID; parameters[1].Value = model.CK_ProductTypeID; parameters[2].Value = model.CK_ProductName; parameters[3].Value = model.CK_ProductPrice; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 得到一个对象实体 /// </summary> public TSM.Model.CK_Product GetModel(int CK_ProductID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CK_ProductID,CK_ProductTypeID,CK_ProductName,CK_ProductPrice from CK_Product "); strSql.Append(" where CK_ProductID=@CK_ProductID "); SqlParameter[] parameters = { new SqlParameter("@CK_ProductID", SqlDbType.Int, 4) }; parameters[0].Value = CK_ProductID; TSM.Model.CK_Product model = new TSM.Model.CK_Product(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["CK_ProductID"].ToString() != "") { model.CK_ProductID = int.Parse(ds.Tables[0].Rows[0]["CK_ProductID"].ToString()); } if (ds.Tables[0].Rows[0]["CK_ProductTypeID"].ToString() != "") { model.CK_ProductTypeID = int.Parse(ds.Tables[0].Rows[0]["CK_ProductTypeID"].ToString()); } model.CK_ProductName = ds.Tables[0].Rows[0]["CK_ProductName"].ToString(); if (ds.Tables[0].Rows[0]["CK_ProductPrice"].ToString() != "") { model.CK_ProductPrice = decimal.Parse(ds.Tables[0].Rows[0]["CK_ProductPrice"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public TSM.Model.CK_Product GetModel(int CK_ProductID) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 CK_ProductID,CK_ProductTypeID,CK_ProductName,CK_ProductPrice from CK_Product "); strSql.Append(" where CK_ProductID=@CK_ProductID "); SqlParameter[] parameters = { new SqlParameter("@CK_ProductID", SqlDbType.Int,4)}; parameters[0].Value = CK_ProductID; TSM.Model.CK_Product model=new TSM.Model.CK_Product(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["CK_ProductID"].ToString()!="") { model.CK_ProductID=int.Parse(ds.Tables[0].Rows[0]["CK_ProductID"].ToString()); } if(ds.Tables[0].Rows[0]["CK_ProductTypeID"].ToString()!="") { model.CK_ProductTypeID=int.Parse(ds.Tables[0].Rows[0]["CK_ProductTypeID"].ToString()); } model.CK_ProductName=ds.Tables[0].Rows[0]["CK_ProductName"].ToString(); if(ds.Tables[0].Rows[0]["CK_ProductPrice"].ToString()!="") { model.CK_ProductPrice=decimal.Parse(ds.Tables[0].Rows[0]["CK_ProductPrice"].ToString()); } return model; } else { return null; } }