📄 shopoperform.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DaFanRongMIS.Model.Shop;
using DaFanRongMIS.ViewController.Shop;
namespace DaFanRongMIS.ViewController.Shop
{
public partial class ShopOperForm : Form
{
ListView LVShop;
int flag;
ShopEntity shop;
public ShopOperForm()
{
InitializeComponent();
}
public ShopOperForm(int f,ListView lv)
{
InitializeComponent();
/*
构造函数从载,将饭店窗体中
listview与f变量里的值传到本窗体实现同一窗体
中完成增加与修改*/
LVShop = lv;
flag = f;
}
private void ShopOperForm_Load(object sender, EventArgs e)
{
switch (flag)
{
case 1:
ShopDAO shopid = new ShopDAOImpl();
string maxid = shopid.MaxID();//获得最大编号
this.txtID.Text = maxid;
break;
case 2:
this.Text = "信息更新";
this.txtID.Text = LVShop.SelectedItems[0].SubItems[0].Text;
this.txtName.Text = LVShop.SelectedItems[0].SubItems[1].Text;
this.txtAddress.Text = LVShop.SelectedItems[0].SubItems[2].Text;
this.txtMemo.Text = LVShop.SelectedItems[0].SubItems[3].Text;
this.btnOK.Text = "更新";
this.btnClear.Visible = false;
break;
}
}
private void btnClear_Click(object sender, EventArgs e)
{
this.txtName.Text = "";
this.txtAddress.Text = "";
}
private void btnOK_Click(object sender, EventArgs e)
{
switch (flag)
{
case 1://增加
try
{
shop = new ShopEntity();//实例化属性封装类对象
shop.ShopID = this.txtID.Text;//给编号属性赋值
shop.ShopName = this.txtName.Text;//给名称属性赋值
shop.ShopAddress = this.txtAddress.Text;//给地址属性赋值
shop.ShopMemo = this.txtMemo.Text;//给备注属性赋值
//定义接口对象,并用方法实现例为对象实例化
ShopDAO addshop = new ShopDAOImpl();
string flog = addshop.AddShop(shop);
if (flog == "OK")
MessageBox.Show("恭喜!新店注册成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("信息有误!新店未注册成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
catch (Exception ee)
{
MessageBox.Show("失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
break;
case 2://修改
try
{
shop = new ShopEntity();//实例化属性封装类对象
shop.ShopID = this.txtID.Text;//给编号属性赋值
shop.ShopName = this.txtName.Text;//给名称属性赋值
shop.ShopAddress = this.txtAddress.Text;//给地址属性赋值
shop.ShopMemo = this.txtMemo.Text;//给备注属性赋值
//定义接口对象,并用方法实现例为对象实例化
ShopDAO updateshop = new ShopDAOImpl();
string flog = updateshop.UpdateShop(shop);
if (flog == "OK")
{
LVShop.SelectedItems[0].Text = this.txtID.Text;
LVShop.SelectedItems[0].SubItems[1].Text = txtName.Text;
LVShop.SelectedItems[0].SubItems[2].Text = txtAddress.Text;
LVShop.SelectedItems[0].SubItems[3].Text = txtMemo.Text;
MessageBox.Show("信息修改成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
else
{
MessageBox.Show("信息未修改成功!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
catch (Exception ee)
{
MessageBox.Show("失败!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
break;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -