private void btnOk_Click_1(object sender, EventArgs e) { if (CheckEmpty())//判断所有的文本框不为空 { CategoryInfoBll cBll = new CategoryInfoBll(); CategoryInfo c = new CategoryInfo(); c.CName = txtCName.Text;//名字 c.CNum = txtCNum.Text;//编号 c.CRemark = txtCRemark.Text;//备注 //判断是新增还是修改 if (Temp == 1)//新增 { c.DelFlag = 0; c.SubBy = 1; c.SubTime = System.DateTime.Now;//提交时间 }//修改 else if (Temp == 2) { c.CId = Convert.ToInt32(labId.Text);//id类别 } string msg = cBll.AddOrUpdateCategoryInfo(c, Temp) ? "操作成功" : "操作失败"; md.MsgDivShow(msg, 1, Bind); // md.MsgDivShow(msg, 1); } }
public static FrmCategoryAddOrModify Single(int temp, CategoryInfo c) { if (_instance == null || _instance.IsDisposed) { _instance = new FrmCategoryAddOrModify(c); Temp = temp; } return _instance; }
/// <summary> /// 新增或者是修改商品类别信息 /// </summary> /// <param name="c">商品类别对象</param> /// <param name="temp">标识:1----新增,2----修改</param> /// <returns>是否成功</returns> public bool AddOrUpdateCategoryInfo(CategoryInfo c, int temp) { if (temp == 1)//新增 { return cDal.AddCategoryInfo(c) > 0; } else if (temp == 2)//修改 { return cDal.UpdateCategoryInfo(c) > 0; } return false; }
private FrmCategoryAddOrModify(CategoryInfo c) { InitializeComponent(); //为文本框赋值 if (c != null)//修改 { txtCName.Text = c.CName;//名字 txtCNum.Text = c.CNum;//编号 txtCRemark.Text = c.CRemark;//备注 labId.Text = c.CId.ToString();//类别的id } }
private int AddOrUpdateCategoryInfo(CategoryInfo c, string sql, int temp) { List<SqlParameter> list = new List<SqlParameter>(); SqlParameter[] ps = { new SqlParameter("@CName",c.CName), new SqlParameter("@CNum",c.CNum), new SqlParameter("@CRemark",c.CRemark) }; list.AddRange(ps); if (temp == 1)//新增 { list.Add(new SqlParameter("@DelFlag", c.DelFlag)); list.Add(new SqlParameter("@SubTime", c.SubTime)); list.Add(new SqlParameter("@SubBy", c.SubBy)); } else if (temp == 2)//修改 { list.Add(new SqlParameter("@CId", c.CId)); } return SqlHelper.ExecuteNonQuery(sql, list.ToArray()); }
private void ShowFrmCategoryAddOrModify(int temp, CategoryInfo c) { this.Hide(); FrmCategoryAddOrModify fcam = FrmCategoryAddOrModify.Single(temp, c); fcam.FormClosed += new FormClosedEventHandler(fcam_FormClosed); fcam.Show();//显示商品类别信息新增或者修改的窗体 }
//关系转对象 private CategoryInfo RowToCategoryInfoByDataRow(DataRow dr) { CategoryInfo c = new CategoryInfo(); c.CId = Convert.ToInt32(dr["CId"]); c.CName = dr["CName"].ToString(); c.CNum = dr["CNum"].ToString(); c.CRemark = dr["CRemark"].ToString(); c.DelFlag = Convert.ToInt32(dr["DelFlag"]); c.SubBy = Convert.ToInt32(dr["SubBy"]); c.SubTime = Convert.ToDateTime(dr["SubTime"]); return c; }
//修改 public int UpdateCategoryInfo(CategoryInfo c) { string sql = "update CategoryInfo set CName=@CName, CNum=@CNum, CRemark=@CRemark where CId=@CId"; return AddOrUpdateCategoryInfo(c, sql, 2);//新增 }
//新增 public int AddCategoryInfo(CategoryInfo c) { string sql = "insert into CategoryInfo(CName, CNum, CRemark, DelFlag, SubTime, SubBy)values(@CName, @CNum, @CRemark, @DelFlag, @SubTime, @SubBy)"; return AddOrUpdateCategoryInfo(c, sql, 1);//新增 }