📄 kitchenform.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.Kitchen;
using DaFanRongMIS.Model.Shop;
namespace DaFanRongMIS.ViewController.Kitchen
{
public partial class KitchenForm : Form
{
TextBox strText = null;
public KitchenForm()
{
InitializeComponent();
}
public KitchenForm(TextBox tb)
{
InitializeComponent();
strText = tb;
}
#region 声明
public string strselect;
KitchenEntity KE = new KitchenEntity();
KitchenDAO KD = new KitchenDAOImpl();
ShopEntity SE = new ShopEntity();
ShopDAO SD = new ShopDAOImpl();
#endregion
#region 填充LV
public void Fill()
{
this.LVKitchen.Items.Clear();
DataTable dt = KD.SelectKitchen(KE);
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());
LVKitchen.Items.Add(item);
}
}
#endregion
#region 填充LVED
public void Filled()
{
this.LVKitchen.Items.Clear();
DataTable dt = KD.SelectedKitchen(KE);
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());
this.LVKitchen.Items.Add(item);
}
}
#endregion
#region 填充店号
public void FillCmb()
{
SqlDataReader dr = SD.SelectShop(SE);
while (dr.Read())
{
this.cboShopID.Items.Add(dr["ID"].ToString());
}
}
#endregion
#region 自动编号
public void AutoID()
{
DataTable dt = new DataTable();
KE.ShopID = this.cboShopID.Text;
dt = KD.SelectMaxIDKitchen(KE);
if (dt.Rows.Count > 0)
{
int n = Convert.ToInt32(dt.Rows[0][0].ToString());
this.txtID.Text = (n + 1).ToString("00");
}
}
private void cboShopID_SelectionChangeCommitted(object sender, EventArgs e)
{
this.AutoID();
}
#endregion
#region 数据回填
private void LVKitchen_Click(object sender, EventArgs e)
{
this.cboShopID.Text = this.LVKitchen.SelectedItems[0].SubItems[0].Text;
this.txtID.Text = this.LVKitchen.SelectedItems[0].SubItems[1].Text;
this.txtName.Text=this.LVKitchen.SelectedItems[0].SubItems[2].Text;
this.txtMemo.Text=this.LVKitchen.SelectedItems[0].SubItems[3].Text;
}
#endregion
#region 窗体载入
private void KitchenForm_Load_1(object sender, EventArgs e)
{
this.Fill();
this.FillCmb();
this.tbDelete.Enabled = false;
this.tbUpdate.Enabled = false;
if (strText != null)
{
this.tbAdd.Visible = false;
this.tbUpdate.Visible = false;
tbDelete.Visible = false;
this.groupBox1.Enabled = false;
}
}
#endregion
#region 增加
private void tbAdd_Click(object sender, EventArgs e)
{
if (this.cboShopID.Text != "" && this.txtID.Text != "" && this.txtName.Text!= "")
{
KE.ShopID = this.cboShopID.Text;
KE.ID = this.txtID.Text;
KE.Name = this.txtName.Text;
KE.Memo = this.txtMemo.Text;
if (KD.AddKitchen(KE) == "OK")
MessageBox.Show("增加成功!");
this.Fill();
}
else
{
MessageBox.Show("请填写相关信息!");
}
}
#endregion
#region 修改
private void tbUpdate_Click(object sender, EventArgs e)
{
KE.ShopID = this.cboShopID.Text;
KE.ID = this.txtID.Text;
KE.Name = this.txtName.Text;
KE.Memo = this.txtMemo.Text;
if (KD.UpdateKitchen(KE) == "OK")
{
MessageBox.Show("修改成功!");
KitchenForm kf = new KitchenForm();
kf.Show();
this.Close();
}
this.Fill();
}
#endregion
#region 删除
private void tbDelete_Click(object sender, EventArgs e)
{
if (MessageBox.Show("您确认要删除该条记录?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
KE.ID = this.txtID.Text;
KE.ShopID = this.cboShopID.Text;
if (KD.DeleteKitchen(KE) == "OK")
{
MessageBox.Show("删除成功!");
KitchenForm kf = new KitchenForm();
kf.Show();
this.Close();
}
this.Fill();
this.cboShopID.Text = "";
this.txtID.Text = "";
this.txtName.Text = "";
this.txtMemo.Text = "";
}
}
#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 == "店号") KE.ShopID = this.tbTxtSelect.Text;
if (strselect == "编号") KE.ID = this.tbTxtSelect.Text;
if (strselect == "名称") KE.Name = this.tbTxtSelect.Text;
if (strselect == "备注") KE.Memo = this.tbTxtSelect.Text;
KD.SelectedKitchen(KE);
this.Filled();
}
this.tbAdd.Enabled = false;
this.tbDelete.Enabled = true;
this.tbUpdate.Enabled = true;
}
#endregion
#region 退出
private void tbExit_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
private void LVKitchen_DoubleClick(object sender, EventArgs e)
{
if (strText != null)
{
if (this.LVKitchen.SelectedItems.Count > 0)
{
strText.Text = LVKitchen.SelectedItems[0].SubItems[2].Text;
strText.Tag = LVKitchen.SelectedItems[0].SubItems[1].Text;
this.Close();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -