private void dgvCellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } optrowid = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); if (!String.IsNullOrEmpty(optrowid)) { model = dal.GetModel(Int32.Parse(optrowid)); if (model != null) { txtOderNo.Text = model.o_no; txtkhid.Text = model.o_busy.ToString(); modelz = dalz.GetModel((int)model.o_busy); txtProvider.Text = modelz.r_name; txtsum.Text = model.o_sum; txtdesc.Text = model.o_desc; txtuser.Text = model.o_user; txtnum.Text = model.o_num + ""; DataTable dt = dalt.GetList(" p_id='" + model.o_pid + "'").Tables[0]; if (dt.Rows.Count > 0) { txtname.Text = dt.Rows[0]["p_name"].ToString(); txtProdNo.Text = dt.Rows[0]["p_no"].ToString(); } } } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.tb_ruzhu model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.r_no != null) { strSql1.Append("r_no,"); strSql2.Append("'" + model.r_no + "',"); } if (model.r_name != null) { strSql1.Append("r_name,"); strSql2.Append("'" + model.r_name + "',"); } if (model.r_uname != null) { strSql1.Append("r_uname,"); strSql2.Append("'" + model.r_uname + "',"); } if (model.r_utel != null) { strSql1.Append("r_utel,"); strSql2.Append("'" + model.r_utel + "',"); } if (model.r_address != null) { strSql1.Append("r_address,"); strSql2.Append("'" + model.r_address + "',"); } if (model.r_desc != null) { strSql1.Append("r_desc,"); strSql2.Append("'" + model.r_desc + "',"); } strSql.Append("insert into tb_ruzhu("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); strSql.Append(";select @@IDENTITY"); object obj = DbSQL.GetSingle(strSql.ToString()); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.tb_ruzhu GetModel(int r_id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" r_id,r_no,r_name,r_uname,r_utel,r_address,r_desc "); strSql.Append(" from tb_ruzhu "); strSql.Append(" where r_id=" + r_id + ""); Model.tb_ruzhu model = new Model.tb_ruzhu(); DataSet ds = DbSQL.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["r_id"] != null && ds.Tables[0].Rows[0]["r_id"].ToString() != "") { model.r_id = int.Parse(ds.Tables[0].Rows[0]["r_id"].ToString()); } if (ds.Tables[0].Rows[0]["r_no"] != null && ds.Tables[0].Rows[0]["r_no"].ToString() != "") { model.r_no = ds.Tables[0].Rows[0]["r_no"].ToString(); } if (ds.Tables[0].Rows[0]["r_name"] != null && ds.Tables[0].Rows[0]["r_name"].ToString() != "") { model.r_name = ds.Tables[0].Rows[0]["r_name"].ToString(); } if (ds.Tables[0].Rows[0]["r_uname"] != null && ds.Tables[0].Rows[0]["r_uname"].ToString() != "") { model.r_uname = ds.Tables[0].Rows[0]["r_uname"].ToString(); } if (ds.Tables[0].Rows[0]["r_utel"] != null && ds.Tables[0].Rows[0]["r_utel"].ToString() != "") { model.r_utel = ds.Tables[0].Rows[0]["r_utel"].ToString(); } if (ds.Tables[0].Rows[0]["r_address"] != null && ds.Tables[0].Rows[0]["r_address"].ToString() != "") { model.r_address = ds.Tables[0].Rows[0]["r_address"].ToString(); } if (ds.Tables[0].Rows[0]["r_desc"] != null && ds.Tables[0].Rows[0]["r_desc"].ToString() != "") { model.r_desc = ds.Tables[0].Rows[0]["r_desc"].ToString(); } return(model); } else { return(null); } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } optrowid = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); if (!String.IsNullOrEmpty(optrowid)) { model = dal.GetModel(Int32.Parse(optrowid)); if (model != null) { txtno.Text = model.r_no; txtname.Text = model.r_name; txttel.Text = model.r_utel; txtuname.Text = model.r_uname; txtaddress.Text = model.r_address; } } }
private string getStr(int type, int id) { string reStr = ""; if (type == 1) { molt = new Model.tb_type(); molt = dalt.GetModel(id); reStr = molt != null ? molt.t_name : ""; } else if (type == 2 || type == 3) { molk = new Model.tb_ku(); molk = dalk.GetModel(id); reStr = molk != null ? molk.k_name : ""; } else if (type == 4) { molr = new Model.tb_ruzhu(); molr = dalr.GetModel(id); reStr = molr != null ? molr.r_name : ""; } return(reStr); }
private void toolBar1_ButtonClick(object sender, ToolBarButtonClickEventArgs e) { if (e.Button.ToolTipText == "新增") { ClearCtlValue(); SetModifyMode(true); optrowid = null; } if (e.Button.ToolTipText == "修改") { if (!String.IsNullOrEmpty(optrowid)) { SetModifyMode(true); } else { MessageBox.Show("请选择所要修改的行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (e.Button.ToolTipText == "删除") { if (!String.IsNullOrEmpty(optrowid)) { DialogResult result = MessageBox.Show("确认删除?", "删除数据", MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { dal.Delete(int.Parse(optrowid)); ClearCtlValue(); MessageBox.Show("恭喜你,删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); BindData(" "); SetModifyMode(false); optrowid = null; } } else { MessageBox.Show("请选择所要删除的行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (e.Button.ToolTipText == "提交") { if (ValidateIput()) { model = new Model.tb_ruzhu(); if (!String.IsNullOrEmpty(optrowid)) { model = dal.GetModel(int.Parse(optrowid)); } model.r_no = this.txtno.Text; model.r_name = this.txtname.Text; model.r_utel = this.txttel.Text; model.r_uname = this.txtuname.Text; model.r_address = this.txtaddress.Text; if (String.IsNullOrEmpty(optrowid)) { int i = dal.Add(model); if (i > 0) { MessageBox.Show("恭喜你,新增成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearCtlValue(); BindData(" "); SetModifyMode(false); optrowid = null; } } else { if (dal.Update(model)) { MessageBox.Show("恭喜你,修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); ClearCtlValue(); BindData(" "); SetModifyMode(false); optrowid = null; } } } } if (e.Button.ToolTipText == "取消") { BindData(" "); ClearCtlValue(); SetModifyMode(false); optrowid = null; } if (e.Button.ToolTipText == "退出") { this.Close(); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.tb_ruzhu model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_ruzhu set "); if (model.r_no != null) { strSql.Append("r_no='" + model.r_no + "',"); } else { strSql.Append("r_no= null ,"); } if (model.r_name != null) { strSql.Append("r_name='" + model.r_name + "',"); } if (model.r_uname != null) { strSql.Append("r_uname='" + model.r_uname + "',"); } else { strSql.Append("r_uname= null ,"); } if (model.r_utel != null) { strSql.Append("r_utel='" + model.r_utel + "',"); } else { strSql.Append("r_utel= null ,"); } if (model.r_address != null) { strSql.Append("r_address='" + model.r_address + "',"); } else { strSql.Append("r_address= null ,"); } if (model.r_desc != null) { strSql.Append("r_desc='" + model.r_desc + "',"); } else { strSql.Append("r_desc= null ,"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where r_id=" + model.r_id + ""); int rowsAffected = DbSQL.ExecuteSql(strSql.ToString()); if (rowsAffected > 0) { return(true); } else { return(false); } }