-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormAddProduct.cs
83 lines (74 loc) · 2.24 KB
/
FormAddProduct.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using Trace.entity;
using Trace.util;
namespace Trace
{
public partial class FormAddProduct : Form
{
OleDbConnection mycon;
FormConfig formConfig;
string opType;
Product product;
public FormAddProduct(string type, OleDbConnection con, FormConfig config, Product pdt)
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
mycon = con;
formConfig = config;
opType = type;
product = pdt;
}
private void FormAddProduct_Load(object sender, EventArgs e)
{
if (opType.Equals("add"))
{
this.Text = "添加产品";
}
if (opType.Equals("edit"))
{
this.Text = "修改产品信息";
tbxName.Text = product.name;
tbxSort.Text = product.sort.ToString();
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnSave_Click(object sender, EventArgs e)
{
string name = tbxName.Text;
string sort = tbxSort.Text;
if(StringUtil.isEmpty(name)){
MessageBox.Show("请填写名称");
return;
}
if (StringUtil.isEmpty(sort))
{
MessageBox.Show("请填写排序");
return;
}
string sql = "";
if (opType.Equals("add"))
{
sql = "insert into PRODUCT (NAME, SORT) values (\"" + name + "\"," + sort + ")";
}
if (opType.Equals("edit"))
{
sql = "update PRODUCT set NAME = \"" + name + "\", SORT = " + sort + " where ID = " + product.id;
}
OleDbCommand cmd = new OleDbCommand(sql, mycon);
cmd.ExecuteNonQuery();
formConfig.queryProduct();
this.Close();
}
}
}