// 验证是否能够通过 private void FormMain_Load(object sender, EventArgs e) { try { toolStripStatusLabel1.Text = " 欢饮您!" + username; if (usertype == "普通用户") { //toolStripButton4.Visible = false; toolStripButton5.Visible = false; //toolStripLabel5.Visible = false; toolStripLabel4.Visible = false; } DataSet ds = ClassDB.getDataSet("select * from 用户表"); // 没有用户 用户密码错误 用户次数小于1 if (ds.Tables[0].Rows.Count < 1 || ClassDB.Decrypt(ds.Tables[0].Rows[0]["用户密码"].ToString()) != "55555" || long.Parse(ClassDB.Decrypt(ds.Tables[0].Rows[0]["次数期限"].ToString())) < 1) { // 验证不通过 FormPassowrd pass = new FormPassowrd(); // 锁定 pass.ShowDialog(); } else { string sql = "update 用户表 set 次数期限='" + ClassDB.Encrypt((long.Parse(ClassDB.Decrypt(ds.Tables[0].Rows[0]["次数期限"].ToString())) - 1).ToString()) + "'"; ClassDB.ExcuteSql(sql); } } catch { FormPassowrd pass = new FormPassowrd(); // 锁定 pass.ShowDialog(); } }
private void button2_Click(object sender, EventArgs e) { if (textBox1.Text.Trim() == "") { MessageBox.Show("不能为空"); textBox1.SelectAll(); textBox1.Focus(); return; } try { string sql = "select * from 产品类别 where 产品类别='" + textBox1.Text.Trim() + "'"; if (ClassDB.getDataSet(sql).Tables[0].Rows.Count > 0) { MessageBox.Show(textBox1.Text.Trim() + " 已存在,请修改"); textBox1.SelectAll(); textBox1.Focus(); return; } sql = "insert into 产品类别(产品类别) values('" + textBox1.Text.Trim() + "')"; ClassDB.ExcuteSql(sql); MessageBox.Show("添加完成"); this.Close(); ((FormSysSet)this.Owner).bingCPLB(textBox1.Text.Trim()); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonAdd_Click(object sender, EventArgs e) { if (textBoxDHDW.Text.Trim() == "") { MessageBox.Show("不能为空"); textBoxDHDW.SelectAll(); textBoxDHDW.Focus(); return; } try { string sql = "select * from 订货单位 where 订货单位='" + textBoxDHDW.Text.Trim() + "'"; if (ClassDB.getDataSet(sql).Tables[0].Rows.Count > 0) { MessageBox.Show(textBoxDHDW.Text.Trim() + " 已存在,请修改"); textBoxDHDW.SelectAll(); textBoxDHDW.Focus(); return; } sql = "insert into 订货单位(订货单位) values('" + textBoxDHDW.Text.Trim() + "')"; ClassDB.ExcuteSql(sql); textBoxDHDW.Text = ""; bingdata(); MessageBox.Show("添加完成"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button2_Click(object sender, EventArgs e) { if (textBox1.Text.Trim() == "") { MessageBox.Show("不能为空"); textBox1.SelectAll(); textBox1.Focus(); return; } if (comboBox1.SelectedIndex < 0) { MessageBox.Show("请选择产品类别"); return; } try { string sql = "select * from 产品名称 where 产品名称='" + textBox1.Text.Trim() + "' and 产品类别='" + comboBox1.SelectedItem.ToString() + "'"; if (ClassDB.getDataSet(sql).Tables[0].Rows.Count > 0) { MessageBox.Show(textBox1.Text.Trim() + " 已存在,请修改"); textBox1.SelectAll(); textBox1.Focus(); return; } sql = "insert into 产品名称(产品名称,产品类别) values('" + textBox1.Text.Trim() + "','" + comboBox1.SelectedItem.ToString() + "')"; ClassDB.ExcuteSql(sql); textBox1.Text = ""; bingdata(); MessageBox.Show("添加完成"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void refresh() { try { ClassDB.bindCombobox1("订单表", "订货单位", DHDW); // 绑定订货单位 ClassDB.bindCombobox1("订单表", "订货渠道", DHQD); // 绑定订货单位 ClassDB.bindCombobox1("订单表", "经办人", JBR); // 绑定订货单位 ClassDB.bindCombobox1("订单详单表", "产品类别", CPLB); // 绑定订货单位 string sql = "select 订单表.订单编号,订货单位,订货时间,送货地址,产品类别,产品名称,数量,收货人,联系方式,订货渠道,经办人 from 订单表 left join 订单详单表 on 订单表.订单编号=订单详单表.订单编号 " + "where (订货时间 Between #" + DHSJ.Value.ToString("yyyy-MM-dd hh:mm:ss") + "# and #" + DHSJEnd.Value.ToString("yyyy-MM-dd hh:mm:ss") + "#) and 订货单位 like '%" + DHDW.Text.Trim() + "%' and 订货渠道 like '%" + DHQD.Text.Trim() + "%' and 经办人 like '%" + JBR.Text.Trim() + "%' and 产品类别 like '%" + CPLB.Text.Trim() + "%' and 产品名称 like '%" + CPMC.Text.Trim() + "%' order by 订货时间 desc"; DataSet ds = ClassDB.getDataSet(sql); dataGridView1.DataSource = ds.Tables[0]; int nums = 0; for (int i = 0; i < dataGridView1.Rows.Count; i++) { nums += int.Parse(dataGridView1.Rows[i].Cells["数量"].Value.ToString()); } groupBox2.Text = "产品信息(合计:" + nums.ToString() + ")"; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button3_Click(object sender, EventArgs e) { if (dataGridView1.SelectedCells.Count == 0) { MessageBox.Show("请选择要删除的用户", "提示", //弹出消息对话框 MessageBoxButtons.OK, MessageBoxIcon.Information); return; //退出事件 } else { try { string username1 = dataGridView1.SelectedCells[0].Value.ToString(); //得到用户名 string strsql = //创建SQL字符串 "delete from 权限表 where 用户名='" + username1 + "'"; ClassDB.ExcuteSql(strsql); //删除数据库中指定记录 MessageBox.Show("删除成功!", "提示", //弹出消息对话框 MessageBoxButtons.OK, MessageBoxIcon.Information); ShowUserInfo(); } catch (Exception ex) { MessageBox.Show("数据库错误\r\n" + ex.Message); } } }
private void button1_Click(object sender, EventArgs e) { try { if (textBox1.Text.Trim() != "55555") { MessageBox.Show("密码错误"); textBox1.Focus(); textBox1.SelectAll(); return; } if (ClassDB.getDataSet("select * from 用户表").Tables[0].Rows.Count > 0) { ClassDB.ExcuteSql("update 用户表 set 用户密码='" + ClassDB.Encrypt(textBox1.Text.Trim()) + "',次数期限='" + ClassDB.Encrypt(textBox2.Text.Trim()) + "'"); } else { ClassDB.ExcuteSql("insert into 用户表(用户密码,次数期限) values('" + ClassDB.Encrypt(textBox1.Text.Trim()) + "','" + ClassDB.Encrypt(textBox2.Text.Trim()) + "')"); } this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
// 用户管理 // 显示用户信息 private void ShowUserInfo() { string getUser =//创建SQL字符串 "select 用户名,'*****' as 用户密码,用户类型 from 权限表"; try { DataSet ds = ClassDB.getDataSet(getUser); dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ex) { MessageBox.Show("数据库错误\r\n" + ex.Message); return; } try { dataGridView1.Columns[0].Width = (dataGridView1.Width - 30) / 3; //设置列宽度 dataGridView1.Columns[1].Width = dataGridView1.Columns[0].Width; //设置列宽度 dataGridView1.Columns[2].Width = dataGridView1.Columns[1].Width; } catch { } txtOPwd.Text = ""; //清除文本内容 txtOUser.Text = ""; //清除文本内容 }
private void 除ToolStripMenuItem_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count < 1) { MessageBox.Show("请选择需要删除的订单"); return; } if (MessageBox.Show("是否确定要删除订单" + dataGridView1.SelectedRows[0].Cells["订单流水号"].Value.ToString() + "?\r\n删除不可恢复!", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } try { string sql = "delete from 订单表 where 订单编号='" + dataGridView1.SelectedRows[0].Cells["订单流水号"].Value.ToString() + "'"; ClassDB.ExcuteSql(sql); sql = "delete from 订单详单表 where 订单编号='" + dataGridView1.SelectedRows[0].Cells["订单流水号"].Value.ToString() + "'"; ClassDB.ExcuteSql(sql); MessageBox.Show("删除成功"); refresh(); } catch (Exception ex) { MessageBox.Show("Error Info:" + ex.Message); } }
// 确认 private void buttonOK_Click(object sender, EventArgs e) { if (username.Text.Trim() == "") { MessageBox.Show("用户名不能为空"); username.Focus(); return; } if (userpassword.Text.Trim() == "") { MessageBox.Show("密码不能为空"); userpassword.Focus(); return; } string type = "普通用户"; if (radioButton2.Checked) { type = "管理员"; // 管理员 } //验证用户是否存在 string sql = "select * from 权限表 where 用户名='" + username.Text.Trim() + "' and 用户类型='" + type + "'"; DataSet dt = ClassDB.getDataSet(sql); if (dt.Tables[0].Rows.Count < 1) { MessageBox.Show("用户" + username.Text.Trim() + "不存在"); username.Focus(); username.SelectAll(); return; } //验证密码是否正确 sql = "select * from 权限表 where 用户名='" + username.Text.Trim() + "' and 用户密码='" + userpassword.Text.Trim() + "' and 用户类型='" + type + "'"; dt = ClassDB.getDataSet(sql); if (dt.Tables[0].Rows.Count < 1) { MessageBox.Show("用户" + username.Text.Trim() + "的密码错误,请确认"); userpassword.Focus(); userpassword.SelectAll(); return; } //验证通过 隐藏登录界面 显示主界面 this.Hide(); FormMain main = new FormMain(); main.username = username.Text.Trim(); main.usertype = type; main.Show(); }
public void refreshdata() { try { string strsql =//创建SQL字符串 "select * from 客户表 where 单位名称 like '%" + toolStripTextBox1.Text.Trim() + "%' and 电话 like '%" + toolStripTextBox1.Text.Trim() + "%' order by 添加时间"; dataGridView1.DataSource = ClassDB.getDataSet(strsql).Tables[0]; } catch (Exception ex) { MessageBox.Show("数据库错误\r\n" + ex.Message); } }
private void FormAddCP_Load(object sender, EventArgs e) { parent = (FormOrderInfo)this.Owner; try { ClassDB.bindCombobox("产品类别", "产品类别", CPLB); // 绑定订货单位 ClassDB.bindCombobox("产品单位", "产品单位", CPDW); // 绑定产品单位 CPLB_SelectedIndexChanged(sender, e); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void CPLB_SelectedIndexChanged(object sender, EventArgs e) { //产品名称 string sql = "select 产品名称 from 产品名称 where 产品类别='" + CPLB.Text.ToString() + "' order by 编号"; DataSet ds = ClassDB.getDataSet(sql); CPMC.Items.Clear(); int i = 0; while (i < ds.Tables[0].Rows.Count) { CPMC.Items.Add(ds.Tables[0].Rows[i++]["产品名称"].ToString()); } CPMC.Text = ""; }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex >= 0) { //产品名称 string sql = "select 产品名称 from 产品名称 where 产品类别='" + comboBox1.SelectedItem.ToString() + "' order by 编号"; DataSet ds = ClassDB.getDataSet(sql); listBox1.Items.Clear(); int i = 0; while (i < ds.Tables[0].Rows.Count) { listBox1.Items.Add(ds.Tables[0].Rows[i++]["产品名称"].ToString()); } groupBox2.Text = "类别" + comboBox1.SelectedItem.ToString() + "的所有产品名称"; } }
public void refresh() { try { ClassDB.bindCombobox1("订单表", "订货单位", DHDW); // 绑定订货单位 ClassDB.bindCombobox1("订单表", "订货渠道", DHQD); // 绑定订货单位 ClassDB.bindCombobox1("订单表", "经办人", JBR); // 绑定订货单位 string sql = "select 订单编号 as 订单流水号,订货单位,订货时间,送货地址,收货人,联系方式,订货渠道,经办人,提货方式,产品合计,备注 from 订单表 where (订货时间 Between #" + DHSJ.Value.ToString("yyyy-MM-dd hh:mm:ss") + "# and #" + DHSJEnd.Value.ToString("yyyy-MM-dd hh:mm:ss") + "#) and 订货单位 like '%" + DHDW.Text.Trim() + "%' and 订货渠道 like '%" + DHQD.Text.Trim() + "%' and 经办人 like '%" + JBR.Text.Trim() + "%' order by 订货时间 desc"; //MessageBox.Show(sql); DataSet ds = ClassDB.getDataSet(sql); dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button2_Click(object sender, EventArgs e) { if (txtOUser.Text.Trim() == "" || txtOPwd.Text.Trim() == "") { MessageBox.Show("请填写完整用户信息!", "提示",//弹出消息对话框 MessageBoxButtons.OK, MessageBoxIcon.Information); txtOUser.Focus(); return;//退出事件 } try { string str =//创建SQL字符串 "select * from 权限表 where 用户名='" + txtOUser.Text.Trim() + "'"; DataSet ds = ClassDB.getDataSet(str); if (ds.Tables[0].Rows.Count > 0) { MessageBox.Show("用户已存在!", "提示",//弹出消息对话框 MessageBoxButtons.OK, MessageBoxIcon.Information); txtOUser.Focus(); return;//退出事件 } else { if (txtOPwd.Text.Length < 6) { MessageBox.Show("请确保密码大于6位字符"); txtOPwd.Focus(); return; } str =//创建SQL字符串 "insert into 权限表 values('" + txtOUser.Text.Trim() + "','" + txtOPwd.Text.Trim() + "','" + type.SelectedItem.ToString() + "')"; ClassDB.ExcuteSql(str); MessageBox.Show("添加成功!", "提示",//弹出消息对话框 MessageBoxButtons.OK, MessageBoxIcon.Information); ShowUserInfo(); } } catch (Exception ex) { MessageBox.Show("添加用户失败!" + ex.Message, "提示",//弹出消息对话框 MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void button11_Click(object sender, EventArgs e) { if (listBox6.SelectedIndex < 0) { MessageBox.Show("请选择需要删除的一项"); return; } try { string sql = "delete from 产品类别 where 产品类别='" + listBox6.SelectedItem.ToString() + "'"; ClassDB.ExcuteSql(sql); bingdata(); MessageBox.Show("删除完成"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void dataGridView1_SelectionChanged(object sender, EventArgs e) { dataGridView2.DataSource = null; if (dataGridView1.SelectedRows.Count < 1) { return; } try { string sql = "select 产品类别,产品名称,数量&产品单位 as 产品数量 from 订单详单表 where 订单编号='" + dataGridView1.SelectedRows[0].Cells["订单流水号"].Value.ToString() + "' order by 添加时间 "; DataSet ds = ClassDB.getDataSet(sql); dataGridView2.DataSource = ds.Tables[0]; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button1_Click(object sender, EventArgs e) { if (MessageBox.Show("是否确定要清空数据库?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } try { string sql = "delete from 订单表 wher"; ClassDB.ExcuteSql(sql); sql = "delete from 订单详单表"; ClassDB.ExcuteSql(sql); MessageBox.Show("清空完成"); } catch (Exception ex) { MessageBox.Show("Error Info:" + ex.Message); } }
private void button4_Click(object sender, EventArgs e) { if (txtOUser.Text.Trim() == "" || txtOPwd.Text.Trim() == "") { MessageBox.Show("请填写完整用户信息!", "提示",//弹出消息对话框 MessageBoxButtons.OK, MessageBoxIcon.Information); txtOUser.Focus(); return;//退出事件 } if (txtOPwd.Text.Length < 6) { MessageBox.Show("请确保密码大于6位字符"); txtOPwd.Focus(); return; } try { string str =//创建SQL字符串 "select * from 权限表 where 用户名='" + txtOUser.Text.Trim() + "'"; DataSet ds = ClassDB.getDataSet(str); if (ds.Tables[0].Rows.Count > 0) { str = //创建SQL字符串 "update 权限表 set 用户密码='" + txtOPwd.Text.Trim() + "',用户类型='" + type.SelectedItem.ToString() + "' where 用户名='" + txtOUser.Text.Trim() + "'"; ClassDB.ExcuteSql(str); //更新数据库信息 MessageBox.Show("修改成功!", "提示", //弹出消息对话框 MessageBoxButtons.OK, MessageBoxIcon.Information); ShowUserInfo(); } else { MessageBox.Show("指定用户不存在!", "提示",//弹出消息对话框 MessageBoxButtons.OK, MessageBoxIcon.Information); txtOUser.Focus(); } } catch (Exception ex) { MessageBox.Show("数据库错误\r\n" + ex.Message); } }
private void bingdata() { switch (tabControl1.SelectedIndex) { case 0: ClassDB.bindlistbox("订货单位", "订货单位", listBoxDHDW); // 绑定订货单位 break; case 1: ClassDB.bindlistbox("产品类别", "产品类别", listBox6); // 绑定订货单位 break; case 2: //产品名称 string sql = "select 产品名称 from 产品名称 where 产品类别='" + comboBox1.SelectedItem.ToString() + "' order by 编号"; DataSet ds = ClassDB.getDataSet(sql); listBox1.Items.Clear(); int i = 0; while (i < ds.Tables[0].Rows.Count) { listBox1.Items.Add(ds.Tables[0].Rows[i++]["产品名称"].ToString()); } groupBox2.Text = "类别" + comboBox1.SelectedItem.ToString() + "的所有产品名称"; break; case 3: ClassDB.bindlistbox("产品单位", "产品单位", listBox5); // 绑定订货单位 break; case 4: ClassDB.bindlistbox("订货渠道", "订货渠道", listBox2); // 绑定订货单位 break; case 5: ClassDB.bindlistbox("经办人", "经办人", listBox3); // 绑定订货单位 break; case 6: ClassDB.bindlistbox("提货方式", "提货方式", listBox4); // 绑定订货单位 break; } }
public void bingCPLB(string show) { if (tabControl1.SelectedIndex == 2) { string sql = "select 产品类别 from 产品类别 order by 编号"; DataSet ds = ClassDB.getDataSet(sql); int i = 0; comboBox1.Items.Clear(); while (i < ds.Tables[0].Rows.Count) { comboBox1.Items.Add(ds.Tables[0].Rows[i++]["产品类别"].ToString()); } comboBox1.SelectedIndex = comboBox1.Items.Count > 0 ? 0 : -1; if (comboBox1.Items.IndexOf(show) >= 0) { comboBox1.SelectedIndex = comboBox1.Items.IndexOf(show); } } bingdata(); }
private void FormCustomerInfo_Load(object sender, EventArgs e) { if (this.Text == "修改客户") { DWMC.Text = name; DWMC.ReadOnly = true; try { string sql = "select * from 客户表 where 单位名称='" + name + "'"; DataSet ds = ClassDB.getDataSet(sql); FZR.Text = ds.Tables[0].Rows[0]["负责人"].ToString(); DWDZ.Text = ds.Tables[0].Rows[0]["单位地址"].ToString(); LXFS.Text = ds.Tables[0].Rows[0]["电话"].ToString(); JYXM.Text = ds.Tables[0].Rows[0]["经营项目"].ToString(); BZ.Text = ds.Tables[0].Rows[0]["备注"].ToString(); } catch (Exception ex) { MessageBox.Show("Error Info:" + ex.Message); } } }
private void buttonOK_Click(object sender, EventArgs e) { if (DWMC.Text.Trim() == "") { MessageBox.Show("单位名称不能为空"); DWMC.Focus(); return; } try { string sql; if (this.Text == "修改客户") { sql = "delete from 客户表 where 单位名称='" + DWMC.Text.Trim() + "'"; ClassDB.ExcuteSql(sql); } else if (this.Text == "添加客户") { sql = "select 单位名称 from 客户表 where 单位名称='" + DWMC.Text.Trim() + "'"; if (ClassDB.getDataSet(sql).Tables[0].Rows.Count > 0) { MessageBox.Show("客户" + DWMC.Text.Trim() + "已经存在,请修改"); return; } } sql = "insert into 客户表 values('" + DWMC.Text.Trim() + "','" + DWDZ.Text.Trim() + "','" + FZR.Text + "','" + LXFS.Text.Trim() + "','" + JYXM.Text.Trim() + "','" + BZ.Text.Trim() + "','" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "')"; ClassDB.ExcuteSql(sql); MessageBox.Show("保存完成"); this.Close(); } catch (Exception ex) { MessageBox.Show("Error Info:" + ex.Message); } }
private void FormOrderInfo_Load(object sender, EventArgs e) { parent = (FormOrderMana)this.Owner; try { ClassDB.bindCombobox("订货单位", "订货单位", DHDW); // 绑定订货单位 ClassDB.bindCombobox("订货渠道", "订货渠道", DHQD); // 绑定订货单位 ClassDB.bindCombobox("经办人", "经办人", JBR); // 绑定订货单位 ClassDB.bindCombobox("提货方式", "提货方式", THFS); // 绑定订货单位 dt = new DataTable(); dt.Columns.Add("产品类别", Type.GetType("System.String")); dt.Columns.Add("产品名称", Type.GetType("System.String")); dt.Columns.Add("数量", Type.GetType("System.String")); dt.Columns.Add("产品单位", Type.GetType("System.String")); //DDBH.Text = string.Format("{0:yyyyMMddHHmmss}", DateTime.Now); if (this.Text == "修改订单" || this.Text == "查看订单") { DDBH.ReadOnly = true; // 修改订单 单号不能改变 //修改订单\ DDBH.Text = orderid; string sql = "select * from 订单表 where 订单编号='" + orderid + "'"; DataSet ds = ClassDB.getDataSet(sql); if (ds.Tables[0].Rows.Count < 1) { MessageBox.Show("打开订单失败,请重试"); this.Close(); } DHDW.Text = ds.Tables[0].Rows[0]["订货单位"].ToString(); SHR.Text = ds.Tables[0].Rows[0]["收货人"].ToString(); LXFS.Text = ds.Tables[0].Rows[0]["联系方式"].ToString(); SHDZ.Text = ds.Tables[0].Rows[0]["送货地址"].ToString(); DHQD.Text = ds.Tables[0].Rows[0]["订货渠道"].ToString(); THFS.Text = ds.Tables[0].Rows[0]["提货方式"].ToString(); JBR.Text = ds.Tables[0].Rows[0]["经办人"].ToString(); BZ.Text = ds.Tables[0].Rows[0]["备注"].ToString(); DHSJ.Value = DateTime.Parse(ds.Tables[0].Rows[0]["订货时间"].ToString()); sql = "select 产品类别,产品名称,数量,产品单位 from 订单详单表 where 订单编号='" + orderid + "'"; ds = ClassDB.getDataSet(sql); dt = ds.Tables[0]; } dataGridView1.DataSource = dt; if (this.Text == "查看订单") { button1.Visible = false; button2.Visible = false; buttonOK.Visible = false; buttonCancel.Text = "关闭"; dataGridView1.ReadOnly = true; DHDW.Enabled = false; SHR.Enabled = false; LXFS.Enabled = false; SHDZ.Enabled = false; DHQD.Enabled = false; DHSJ.Enabled = false; THFS.Enabled = false; JBR.Enabled = false; BZ.Enabled = false; DDBH.Enabled = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void buttonOK_Click(object sender, EventArgs e) { if (DDBH.Text.Trim() == "") { MessageBox.Show("订货编号不能空"); DDBH.Focus(); return; } if (DHDW.Text.Trim() == "") { MessageBox.Show("订货单位不能空"); DHDW.Focus(); return; } if (dt.Rows.Count < 1) { MessageBox.Show("产品详单不能空"); return; } if (SHR.Text.Trim() == "") { MessageBox.Show("收货人不能空"); SHDZ.Focus(); return; } if (LXFS.Text.Trim() == "") { MessageBox.Show("联系方式不能空"); LXFS.Focus(); return; } if (DHQD.Text.Trim() == "") { MessageBox.Show("订货渠道不能空"); DHQD.Focus(); return; } if (JBR.Text.Trim() == "") { MessageBox.Show("经办人不能空"); JBR.Focus(); return; } if (THFS.Text.Trim() == "") { MessageBox.Show("提货方式不能空"); THFS.Focus(); return; } try { int counts = 0; string sql; int i = 0; if (this.Text == "修改订单") { sql = "delete from 订单表 where 订单编号='" + DDBH.Text.Trim() + "'"; ClassDB.ExcuteSql(sql); sql = "delete from 订单详单表 where 订单编号='" + DDBH.Text.Trim() + "'"; ClassDB.ExcuteSql(sql); } else if (this.Text == "添加订单") { sql = "select 订单编号 from 订单表 where 订单编号='" + DDBH.Text.Trim() + "'"; if (ClassDB.getDataSet(sql).Tables[0].Rows.Count > 0) { MessageBox.Show("订单流水号已经被使用过,请修改"); return; } } while (i < dataGridView1.Rows.Count) { sql = "insert into 订单详单表 values('" + DDBH.Text.Trim() + "','" + dataGridView1.Rows[i].Cells["产品类别"].Value.ToString() + "','" + dataGridView1.Rows[i].Cells["产品名称"].Value.ToString() + "','" + dataGridView1.Rows[i].Cells["数量"].Value.ToString() + "','" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "','" + dataGridView1.Rows[i].Cells["产品单位"].Value.ToString() + "')"; ClassDB.ExcuteSql(sql); //更新订单 counts += int.Parse(dataGridView1.Rows[i].Cells["数量"].Value.ToString()); i++; } sql = "insert into 订单表(订单编号,订货单位,订货时间,送货地址,收货人,联系方式,产品合计,订货渠道,经办人,提货方式,备注) values('" + DDBH.Text.Trim() + "','" + DHDW.Text.Trim() + "','" + DHSJ.Value.ToString("yyyy-MM-dd hh:mm:ss") + "','" + SHDZ.Text.Trim() + "','" + SHR.Text.Trim() + "','" + LXFS.Text.Trim() + "','" + counts.ToString() + "','" + DHQD.Text.Trim() + "','" + JBR.Text.Trim() + "','" + THFS.Text.Trim() + "','" + BZ.Text.Trim() + "')"; ClassDB.ExcuteSql(sql); //更新订单 parent.refresh(); MessageBox.Show("提交完成"); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }