using System; using System.Data; using System.Windows.Forms; using DevComponents.DotNetBar; namespace Cyberpipe { public partial class FrmUserRepo : Office2007Form { int id; public FrmUserRepo(int _id) { InitializeComponent(); id = _id; } /// <summary> /// 添加、保存按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonX1_Click(object sender, EventArgs e) { if (txtName.Text.Trim() == "") { MessageBox.Show("请输入仓库名称!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); return; } if (txtType.Text.Trim() == "") { MessageBox.Show("请输入仓库类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (txtRepocode.Text.Trim() == "") { MessageBox.Show("请输入仓库代号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } int repocode; if (!int.TryParse(txtRepocode.Text.Trim(), out repocode)) { MessageBox.Show("仓库代号请输入数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string sql =""; if (id == -1) { sql = "select * from casic_userrepo where \"name\"='" + txtName.Text.Trim() + "' or \"repocode\" =" + txtRepocode.Text.Trim(); DataTable dt = OledbHelper.QueryTable(sql); if (dt != null && dt.Rows.Count > 0) { MessageBox.Show("该用户仓库名称或代码已录入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } sql = "insert into casic_userrepo(\"name\",\"type\",\"repocode\",\"desc\") values('" + txtName.Text.Trim() + "','" + txtType.Text.Trim() + "'," + txtRepocode.Text + ",'" + txtDesc.Text.Trim() + "')"; } else { if (txtName.Text.Trim() == table.Rows[0]["name"].ToString().Trim() && txtRepocode.Text.Trim() == table.Rows[0]["repocode"].ToString().Trim() && txtType.Text.Trim() == table.Rows[0]["type"].ToString().Trim() && txtDesc.Text.Trim() == table.Rows[0]["desc"].ToString().Trim()) { MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); return; } sql = "select * from casic_userrepo where (\"name=\"'" + txtName.Text.Trim() + "' and \"id\" <> " + id + ") or (\"repocode\" =" + txtRepocode.Text.Trim() + " and \"id\" <>" + id + ")"; DataTable dt = OledbHelper.QueryTable(sql); if (dt != null && dt.Rows.Count > 0) { MessageBox.Show("该用户仓库名称或代码已录入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } sql = "update casic_userrepo set \"name\"='" + txtName.Text.Trim() + "' ,\"type\"='" + txtType.Text.Trim() + "' ,\"repocode\" =" + txtRepocode.Text.Trim() + ",\"desc\"='" + txtDesc.Text.Trim() + "' where \"id\" =" + id; } try { if (OledbHelper.sqlExecuteNonQuery(sql) > 0) { MessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } } catch (Exception ex) { LogError.PublishError(ex); } } /// <summary> /// 取消按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonX2_Click(object sender, EventArgs e) { Close(); } DataTable table; /// <summary> /// 窗体初始化事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmUserRepo_Load(object sender, EventArgs e) { if (id != -1) { Text = "编辑用户仓库信息"; buttonX1.Text = "保存"; string sql = "select * from casic_userrepo where \"id\" =" + id; table = OledbHelper.QueryTable(sql); if (table != null) { if (table.Rows.Count > 0) { txtName.Text = table.Rows[0]["name"].ToString(); txtDesc.Text = table.Rows[0]["desc"].ToString(); txtRepocode.Text = table.Rows[0]["repocode"].ToString(); txtType.Text = table.Rows[0]["type"].ToString(); } } } } } }