/// <summary> /// 保存供货商信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonSave_Click(object sender, EventArgs e) { string id = this.textBoxId.Text; //编号 string name = this.textBoxName.Text; //供货商名字 string address = this.textBoxAddress.Text; string phone = this.textBoxPhone.Text; string UserName = this.textBoxName2.Text; //联系人名字 try { if (name != "" && address != "" && phone != "" && UserName != "") { if (operat.FindIdExist("Vendors", "Vendors_id", id) == true) { MessageBox.Show("该编号已经存在,请重新输入", "提示"); this.textBoxId.Text = ""; //清除编号 this.textBoxId.Focus(); //设置焦点 return; } else { string insertsql = "insert into Vendors (vendors_id,vendors_name,vendors_user_name,vendors_address,vendors_phone) values("; insertsql += id; insertsql += ",'" + name + "','" + UserName + "','" + address + "','" + phone + "')"; operat.OperateData(insertsql); operat.DataBind(this.dataGridViewVendors, "select *from vendors", "Vendors"); MessageBox.Show("添加数据成功", "提示"); this.buttonAdd.Enabled = true; this.buttonSave.Enabled = false; } } else { MessageBox.Show("必须填满所有的字段", "提示"); } } catch (Exception ex) { MessageBox.Show("保存供货商信息时发生 " + ex.Message + "错误"); } finally { //关闭数据库的连接 operat.CloseDatabaseCnn(); } }
//添加商品信息 private void buttonOk_Click(object sender, EventArgs e) { try { if (textBoxId.Text != "") { //string sql = "select *from Products where products_id = "+textBoxId.Text; // string insertSql = "insert into "; int num = operat.AddProductsSum(textBoxId.Text) + 1; //先判断表中的条码是否存在,存在则商品数目+1,否则继续添加 if (operat.FindIdExist("Products_Temp", "products_id", textBoxId.Text) == true) { //进行商品数目+1操作 string UpdateSql = "update Products_Temp set products_num = " + num; UpdateSql += " where products_id = " + textBoxId.Text; if (operat.OperateData(UpdateSql) > 0) { //更新显示 //MessageBox.Show("更新成功","提示"); operat.BindDataGridView(this.dataGridView1, "select *from Products_Temp"); operat.InsertSeall(textBoxId.Text); CountProductNum(); } else { MessageBox.Show("没有该商品", "提示"); } } else { //进行插入商品操作 operat.OpProductTemp(textBoxId.Text); //更新显示 operat.BindDataGridView(this.dataGridView1, "select *from Products_Temp"); CountProductNum(); } } else { MessageBox.Show("请输入条形码", "提示"); return; } } catch (Exception ex) { MessageBox.Show("添加商品信息时发生" + ex.Message + "的错误!!!"); return; } finally { //关闭数据库 operat.CloseDatabaseCnn(); } }
//保存会员信息 private void buttonMemberSave_Click(object sender, EventArgs e) { try { if (textBoxId.Text != "" && textBoxName.Text != "") { if (DialogResult.OK == MessageBox.Show("你确定要添加记录吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation)) { if (operat.FindIdExist("Customers", "cust_id", textBoxId.Text) == true) { MessageBox.Show("会员编号已经存在,请重新输入!", "提示"); textBoxId.Text = ""; textBoxId.Focus(); } else { string sql = "insert into Customers values("; sql += textBoxId.Text; sql += ",'" + textBoxName.Text + "'"; sql += ",'" + textBoxIntegral.Text + "'"; sql += ",'" + textBoxRank.Text + "'"; sql += ",'" + textBoxAddress.Text + "'"; sql += ",'" + textBoxPhone.Text + "'"; sql += ",'" + textBoxEmail.Text + "'"; sql += ",'" + dateTimePickerBirthday.Value.ToShortDateString().ToString() + "'"; sql += ",'" + dateTimePickerReg.Value.ToShortDateString().ToString() + "')"; if (operat.OperateData(sql) > 0) { MessageBox.Show("添加会员成功", "提示"); operat.DataBind(this.dataGridViewMember, "select *from Customers", "Customers"); this.buttonMemberAdd.Enabled = true; this.buttonMemberSave.Enabled = false; } else { MessageBox.Show("添加会员信息失败", "提示"); } } } } else { MessageBox.Show("请填满所有字段!", "错误"); return; } } catch (Exception ex) { MessageBox.Show("添加会员信息时发生 " + ex.Message + " 的错误!"); } finally { //关闭数据库的连接 operat.CloseDatabaseCnn(); } }
/// <summary> /// 录入商品信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonOk_Click(object sender, EventArgs e) { try { if (textBoxId.Text != "" && textBoxName.Text != "" && textBoxBid.Text != "" && textBoxSellPrice.Text != "") { if (operat.FindIdExist("Products", "products_id", textBoxId.Text) == true) { MessageBox.Show("该商品编号已经存在,请重新添加!", "提示"); return; } else { string productor_id = this.textBoxId.Text; string vendorsname = ""; //供货商名称 string productor_name = this.textBoxName.Text; string productor_spec = this.comboBoxSpec.Text; string productor_bid = this.textBoxBid.Text; string productor_sell_price = this.textBoxSellPrice.Text; string productor_date = this.dateTimePicker1.Text; string productor_quality_date = this.comboBoxQuality.Text; vendorsname = operat.FindVendorsId("Vendors", comboBoxVen.Text); string InsertSql = "insert into Products values(" + productor_id + ",'" + vendorsname + "','" + productor_name + "','"; InsertSql += productor_spec + "','" + productor_bid + "','" + productor_sell_price + "','" + textBoxProNum.Text + "','" + productor_date + "','"; InsertSql += productor_quality_date + "')"; if (operat.OperateData(InsertSql) > 0) { operat.StoreManage(productor_id, productor_sell_price, textBoxProNum.Text); MessageBox.Show("录入商品信息成功!", "提示"); operat.DataBind(this.dataGridViewPurchase, "select *from Products", "Products"); return; } } } else { MessageBox.Show("请填满所有字段", "提示"); return; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { //关闭数据库 operat.CloseDatabaseCnn(); } }