/// <summary> /// 得到一个对象实体 /// </summary> public Model.tb_order GetModel(int o_id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 "); strSql.Append(" o_id,o_no,o_type,o_time,o_busy,o_sum,o_user,o_desc,o_num,o_pid "); strSql.Append(" from tb_order "); strSql.Append(" where o_id=" + o_id + ""); Model.tb_order model = new Model.tb_order(); DataSet ds = DbSQL.Query(strSql.ToString()); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["o_id"] != null && ds.Tables[0].Rows[0]["o_id"].ToString() != "") { model.o_id = int.Parse(ds.Tables[0].Rows[0]["o_id"].ToString()); } if (ds.Tables[0].Rows[0]["o_no"] != null && ds.Tables[0].Rows[0]["o_no"].ToString() != "") { model.o_no = ds.Tables[0].Rows[0]["o_no"].ToString(); } if (ds.Tables[0].Rows[0]["o_type"] != null && ds.Tables[0].Rows[0]["o_type"].ToString() != "") { model.o_type = int.Parse(ds.Tables[0].Rows[0]["o_type"].ToString()); } if (ds.Tables[0].Rows[0]["o_time"] != null && ds.Tables[0].Rows[0]["o_time"].ToString() != "") { model.o_time = ds.Tables[0].Rows[0]["o_time"].ToString(); } if (ds.Tables[0].Rows[0]["o_busy"] != null && ds.Tables[0].Rows[0]["o_busy"].ToString() != "") { model.o_busy = int.Parse(ds.Tables[0].Rows[0]["o_busy"].ToString()); } if (ds.Tables[0].Rows[0]["o_sum"] != null && ds.Tables[0].Rows[0]["o_sum"].ToString() != "") { model.o_sum = ds.Tables[0].Rows[0]["o_sum"].ToString(); } if (ds.Tables[0].Rows[0]["o_user"] != null && ds.Tables[0].Rows[0]["o_user"].ToString() != "") { model.o_user = ds.Tables[0].Rows[0]["o_user"].ToString(); } if (ds.Tables[0].Rows[0]["o_desc"] != null && ds.Tables[0].Rows[0]["o_desc"].ToString() != "") { model.o_desc = ds.Tables[0].Rows[0]["o_desc"].ToString(); } if (ds.Tables[0].Rows[0]["o_num"] != null && ds.Tables[0].Rows[0]["o_num"].ToString() != "") { model.o_num = int.Parse(ds.Tables[0].Rows[0]["o_num"].ToString()); } if (ds.Tables[0].Rows[0]["o_pid"] != null && ds.Tables[0].Rows[0]["o_pid"].ToString() != "") { model.o_pid = int.Parse(ds.Tables[0].Rows[0]["o_pid"].ToString()); } return(model); } else { return(null); } }
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); txtCustomer.Text = modelz.h_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(); } } } }
private void getStr(string _no) { mode = der.GetModel(Convert.ToInt32(txtorder.SelectedValue)); String provider = Convert.ToString(mode.o_busy); string reStr = ""; if (!string.IsNullOrEmpty(_no)) { //DataTable dt = dalt.GetList(" p_no='" + _no + "' and p_rzfid=" + txtorder.SelectedValue).Tables[0]; DataTable dt = dalt.GetList(" p_no='" + _no + "' and p_rzfid=" + provider).Tables[0]; if (dt.Rows.Count == 0) { MessageBox.Show("该订单所属商家下无此商品"); return; } txttyid.Text = dt.Rows[0]["p_id"].ToString(); reStr = dt.Rows.Count > 0 ? dt.Rows[0]["p_name"].ToString() : ""; txtname.Text = reStr; } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.tb_order model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.o_no != null) { strSql1.Append("o_no,"); strSql2.Append("'" + model.o_no + "',"); } if (model.o_type != null) { strSql1.Append("o_type,"); strSql2.Append("" + model.o_type + ","); } if (model.o_time != null) { strSql1.Append("o_time,"); strSql2.Append("'" + model.o_time + "',"); } if (model.o_busy != null) { strSql1.Append("o_busy,"); strSql2.Append("" + model.o_busy + ","); } if (model.o_sum != null) { strSql1.Append("o_sum,"); strSql2.Append("'" + model.o_sum + "',"); } if (model.o_user != null) { strSql1.Append("o_user,"); strSql2.Append("'" + model.o_user + "',"); } if (model.o_desc != null) { strSql1.Append("o_desc,"); strSql2.Append("'" + model.o_desc + "',"); } if (model.o_num != null) { strSql1.Append("o_num,"); strSql2.Append("" + model.o_num + ","); } if (model.o_pid != null) { strSql1.Append("o_pid,"); strSql2.Append("" + model.o_pid + ","); } strSql.Append("insert into tb_order("); 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 bool Update(Model.tb_order model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tb_order set "); if (model.o_no != null) { strSql.Append("o_no='" + model.o_no + "',"); } else { strSql.Append("o_no= null ,"); } if (model.o_type != null) { strSql.Append("o_type=" + model.o_type + ","); } else { strSql.Append("o_type= null ,"); } if (model.o_time != null) { strSql.Append("o_time='" + model.o_time + "',"); } else { strSql.Append("o_time= null ,"); } if (model.o_busy != null) { strSql.Append("o_busy=" + model.o_busy + ","); } else { strSql.Append("o_busy= null ,"); } if (model.o_sum != null) { strSql.Append("o_sum='" + model.o_sum + "',"); } else { strSql.Append("o_sum= null ,"); } if (model.o_user != null) { strSql.Append("o_user='******',"); } else { strSql.Append("o_user= null ,"); } if (model.o_desc != null) { strSql.Append("o_desc='" + model.o_desc + "',"); } else { strSql.Append("o_desc= null ,"); } if (model.o_num != null) { strSql.Append("o_num=" + model.o_num + ","); } else { strSql.Append("o_num= null ,"); } if (model.o_pid != null) { strSql.Append("o_pid=" + model.o_pid + ","); } else { strSql.Append("o_pid= null ,"); } int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where o_id=" + model.o_id + ""); int rowsAffected = DbSQL.ExecuteSql(strSql.ToString()); if (rowsAffected > 0) { return(true); } else { return(false); } }
private void tbBtnClick(object sender, ToolBarButtonClickEventArgs e) { if (e.Button.ToolTipText == "新增") { rstValue(); 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)); rstValue(); MessageBox.Show("恭喜你,删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); bindData("o_type=2"); setModifyMode(false); optrowid = null; } } else { MessageBox.Show("请选择所要删除的行", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } if (e.Button.ToolTipText == "提交") { if (validateInput()) { model = new Model.tb_order(); if (!String.IsNullOrEmpty(optrowid)) { model = dal.GetModel(int.Parse(optrowid)); } model.o_busy = int.Parse(this.txtkhid.Text); model.o_no = this.txtOderNo.Text; model.o_sum = this.txtsum.Text; model.o_desc = this.txtdesc.Text; model.o_user = this.txtuser.Text; int tempNum = int.Parse(this.txtnum.Text); if (tempNum <= 0) { MessageBox.Show("输入数量有误,请重新输入", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } model.o_num = tempNum; model.o_pid = pid; model.o_type = 2; if (String.IsNullOrEmpty(optrowid)) { model.o_time = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm"); int i = dal.Add(model); if (i > 0) { MessageBox.Show("恭喜你,新增成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); rstValue(); bindData("o_type=2"); setModifyMode(false); optrowid = null; } } else { if (dal.Update(model)) { MessageBox.Show("恭喜你,修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); rstValue(); bindData("o_type=2"); setModifyMode(false); optrowid = null; } } } } if (e.Button.ToolTipText == "取消") { bindData("o_type=2"); rstValue(); setModifyMode(false); optrowid = null; } if (e.Button.ToolTipText == "退出") { this.Close(); } }