📄 providerform.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using DaFanRongMIS.Model.Provider;
using System.Text.RegularExpressions;
namespace DaFanRongMIS.ViewController.Provider
{
public partial class ProviderForm : Form
{
public ProviderForm()
{
InitializeComponent();
}
#region 声明
ProviderEntity PE=new ProviderEntity();
ProviderDAO PD=new ProviderDAOImpl();
public string strselect;
public string strPhonevalidate="";
public string strMobilevalidate="";
public string strPostalCodevalidate="";
public string strFaxvalidate="";
public string strEMailvalidate="";
#endregion
#region 填充LV
public void Fill()
{
this.LVProvider.Items.Clear();
DataTable dt = PD.SelectProvider(PE);
for (int i = 0; i < dt.Rows.Count; i++)
{
ListViewItem item = new ListViewItem(dt.Rows[i][0].ToString());
item.SubItems.Add(dt.Rows[i][1].ToString());
item.SubItems.Add(dt.Rows[i][2].ToString());
item.SubItems.Add(dt.Rows[i][3].ToString());
item.SubItems.Add(dt.Rows[i][4].ToString());
item.SubItems.Add(dt.Rows[i][5].ToString());
item.SubItems.Add(dt.Rows[i][6].ToString());
item.SubItems.Add(dt.Rows[i][7].ToString());
item.SubItems.Add(dt.Rows[i][8].ToString());
item.SubItems.Add(dt.Rows[i][9].ToString());
LVProvider.Items.Add(item);
}
}
#endregion
#region 填充LVED
public void Filled()
{
this.LVProvider.Items.Clear();
DataTable dt = PD.SelectedProvider(PE);
for (int i = 0; i < dt.Rows.Count; i++)
{
ListViewItem item = new ListViewItem(dt.Rows[i][0].ToString());
item.SubItems.Add(dt.Rows[i][1].ToString());
item.SubItems.Add(dt.Rows[i][2].ToString());
item.SubItems.Add(dt.Rows[i][3].ToString());
item.SubItems.Add(dt.Rows[i][4].ToString());
item.SubItems.Add(dt.Rows[i][5].ToString());
item.SubItems.Add(dt.Rows[i][6].ToString());
item.SubItems.Add(dt.Rows[i][7].ToString());
item.SubItems.Add(dt.Rows[i][8].ToString());
item.SubItems.Add(dt.Rows[i][9].ToString());
LVProvider.Items.Add(item);
}
}
#endregion
#region 自动编号
public void AutoID()
{
DataTable dt = PD.SelectProvider(PE);
string strid = dt.Rows[dt.Rows.Count - 1][0].ToString();
if (strid == "")
{
this.txtID.Text = "01";
}
else
{
if ((Convert.ToInt32(strid) + 1) < 10)
{
this.txtID.Text ='0'+ Convert.ToString(Convert.ToInt32(strid) + 1);
}
else
{
this.txtID.Text = Convert.ToString(Convert.ToInt32(strid) + 1);
}
}
}
#endregion
#region 数据回填
private void LVProvider_Click(object sender, EventArgs e)
{
this.txtID.Text = this.LVProvider.SelectedItems[0].SubItems[0].Text;
this.txtName.Text = this.LVProvider.SelectedItems[0].SubItems[1].Text;
this.txtLinkman.Text = this.LVProvider.SelectedItems[0].SubItems[2].Text;
this.txtPhone.Text = this.LVProvider.SelectedItems[0].SubItems[3].Text;
this.txtMobile.Text = this.LVProvider.SelectedItems[0].SubItems[4].Text;
this.txtAddress.Text = this.LVProvider.SelectedItems[0].SubItems[5].Text;
this.txtPostalCode.Text = this.LVProvider.SelectedItems[0].SubItems[6].Text;
this.txtFax.Text = this.LVProvider.SelectedItems[0].SubItems[7].Text;
this.txtEMail.Text = this.LVProvider.SelectedItems[0].SubItems[8].Text;
this.txtMemo.Text = this.LVProvider.SelectedItems[0].SubItems[9].Text;
this.tbAdd.Enabled = false;
this.tbDelete.Enabled = true;
this.tbUpdate.Enabled = true;
}
#endregion
#region 窗体载入
private void ProviderForm_Load(object sender, EventArgs e)
{
this.Fill();
this.AutoID();
this.tbDelete.Enabled = false;
this.tbUpdate.Enabled = false;
}
#endregion
#region 增加
private void tbAdd_Click(object sender, EventArgs e)
{
#region 联系电话验证
string aa = @"(\(\d{3}\)|\d{3}-)?\d{8}";
Regex zz = new Regex(aa);
if (!zz.IsMatch(this.txtPhone.Text))
{
MessageBox.Show( "联系电话格式不正确!");
txtPhone.Focus();
txtPhone.SelectAll();
return;
}
#endregion
#region 手机号码验证
if (this.txtMobile.Text != "")
{
string bb = @"^\d{11}$";
Regex ww = new Regex(bb);
if (!ww.IsMatch(this.txtMobile.Text))
{
MessageBox.Show("手机号码格式不正确,只能是11位数字!");
this.txtMobile.Focus();
this.txtMobile.SelectAll();
return;
}
}
#endregion
#region 邮政编码验证
if (this.txtPostalCode.Text != "")
{
string cc = @"\d{6}";
Regex yy = new Regex(cc);
if (!yy.IsMatch(this.txtPostalCode.Text))
{
MessageBox.Show("邮政编码格式不正确,只能是6位数字!");
this.txtPostalCode.Focus();
this.txtPostalCode.SelectAll();
return;
}
}
#endregion
#region 传真验证
if (this.txtFax.Text != "")
{
string dd = @"(\(\d{3}\)|\d{3}-)?\d{8}";
Regex xx = new Regex(dd);
if (!xx.IsMatch(this.txtFax.Text))
{
MessageBox.Show("传真号码格式不正确!");
this.txtFax.Focus();
this.txtPostalCode.SelectAll();
return;
}
}
#endregion
#region E-Mail验证
if (this.txtEMail.Text != "")
{
string ee = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";
Regex vv = new Regex(ee);
if (!vv.IsMatch(this.txtEMail.Text))
{
MessageBox.Show("E-mail格式不正确!");
this.txtEMail.Focus();
this.txtEMail.SelectAll();
return;
}
}
#endregion
if (this.txtID.Text != "" && this.txtName.Text != "" && this.txtLinkman.Text != "" && this.txtPhone.Text != "")
{
PE.ID = this.txtID.Text;
PE.Name = this.txtName.Text;
PE.Linkman = this.txtLinkman.Text;
PE.Phone = this.txtPhone.Text;
PE.Mobile = this.txtMobile.Text;
PE.Address = this.txtAddress.Text;
PE.PostalCode = this.txtPostalCode.Text;
PE.Fax = this.txtFax.Text;
PE.EMail = this.txtEMail.Text;
PE.Memo = this.txtMemo.Text;
if (PD.AddProvider(PE) == "OK")
{
MessageBox.Show("增加成功!");
}
this.Fill();
this.txtID.Text = "";
this.txtName.Text = "";
this.txtLinkman.Text = "";
this.txtPhone.Text = "";
this.txtMobile.Text = "";
this.txtAddress.Text = "";
this.txtPostalCode.Text = "";
this.txtFax.Text = "";
this.txtEMail.Text = "";
this.txtMemo.Text = "";
this.tbUpdate.Enabled = false;
this.tbDelete.Enabled = false;
this.tbAdd.Enabled = true;
}
else
{
MessageBox.Show("请填写相关信息!");
}
}
#endregion
#region 修改
private void tbUpdate_Click(object sender, EventArgs e)
{
PE.ID = this.txtID.Text;
PE.Name = this.txtName.Text;
PE.Linkman = this.txtLinkman.Text;
PE.Phone = this.txtPhone.Text;
PE.Mobile = this.txtMobile.Text;
PE.Address = this.txtAddress.Text;
PE.PostalCode = this.txtPostalCode.Text;
PE.Fax = this.txtFax.Text;
PE.EMail = this.txtEMail.Text;
PE.Memo = this.txtMemo.Text;
if (PD.UpdateProvider(PE) == "OK")
{
MessageBox.Show("修改成功!");
ProviderForm pf = new ProviderForm();
pf.Show();
this.Close();
}
this.Fill();
}
#endregion
#region 删除
private void tbDelete_Click(object sender, EventArgs e)
{
if (MessageBox.Show("您确认要删除该条记录?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
PE.ID = this.txtID.Text;
if (PD.DeleteProvider(PE) == "OK")
{
MessageBox.Show("删除成功!");
ProviderForm pf = new ProviderForm();
pf.Show();
this.Close();
}
this.Fill();
this.txtID.Text = "";
this.txtName.Text = "";
this.txtLinkman.Text = "";
this.txtPhone.Text = "";
this.txtMobile.Text = "";
this.txtAddress.Text = "";
this.txtPostalCode.Text = "";
this.txtFax.Text = "";
this.txtEMail.Text = "";
this.txtMemo.Text = "";
this.tbUpdate.Enabled = false;
this.tbDelete.Enabled = false;
this.tbAdd.Enabled = true;
}
}
#endregion
#region 查找
private void tbSelect_Click(object sender, EventArgs e)
{
if (this.tbCboSelect.Text == "")
{
MessageBox.Show("请输入查询条件!");
this.tbCboSelect.Focus();
}
else
{
strselect = this.tbCboSelect.Text;
if (strselect == "编号") PE.ID = this.tbTxtSelect.Text;
if (strselect == "供货商名称") PE.Name = this.tbTxtSelect.Text;
if (strselect == "联系人") PE.Linkman = this.tbTxtSelect.Text;
if (strselect == "联系电话") PE.Phone = this.tbTxtSelect.Text;
if (strselect == "手机") PE.Mobile = this.tbTxtSelect.Text;
if (strselect == "联系地址") PE.Address = this.tbTxtSelect.Text;
if (strselect == "邮政编码") PE.PostalCode = this.tbTxtSelect.Text;
if (strselect == "传真") PE.Fax = this.tbTxtSelect.Text;
if (strselect == "信箱") PE.EMail = this.tbTxtSelect.Text;
if (strselect == "备注") PE.Memo = this.tbTxtSelect.Text;
PD.SelectedProvider(PE);
this.Filled();
}
}
#endregion
#region 退出
private void tbExit_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -