主表界面模板code
来源:互联网 发布:工业软件 排名 编辑:程序博客网 时间:2024/06/16 06:18
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.SqlClient;
namespace meifengSystem
{
public partial class shouhuoForm : Form
{
public Form PForm = null;
public int mode = 0;
SqlConnection conn = null;
string DRIVER = "Server=127.0.0.1;UID=sa;PWD=admin;DataBase=factory";
SqlDataAdapter da;
DataSet ds = new DataSet();
//select_all:无条件搜索+where1=1
string sql_select_all = "select s.id, kehu_name, doctor_name, yamo_no, ya_type, yawi, color, remark_id, remark_text, price, amount, yewuyuan, product_no, shouhuo_date, huanzhe, fangong_yuanyin from shouhuo s left join remark r on s.remark_id=r.id where 1=1";
public shouhuoForm()
{
InitializeComponent();
}
private void shouhuoForm_Load(object sender, EventArgs e)
{
initForm();
dv1Load();
}
private void BN_add_Click(object sender, EventArgs e)
{
addRowClick();
}
private void shouhuoForm_FormClosed(object sender, FormClosedEventArgs e)
{
formClose();
}
private void TB_key_TextChanged(object sender, EventArgs e)
{
mohuSearch();
}
private void BN_search_all_Click(object sender, EventArgs e)
{
mohuSearch();
}
private void BN_search_Click(object sender, EventArgs e)
{
search();
}
private void DT_start_ValueChanged(object sender, EventArgs e)
{
search();
}
private void BN_add_date_Click(object sender, EventArgs e)
{
showDate();
search();
}
private void BN_del_date_Click(object sender, EventArgs e)
{
hideDate();
search();
}
private void BN_delete_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确定删除当前选中的行吗?", "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
deleteRows();
}
}
private void BN_modify_Click(object sender, EventArgs e)
{
modifyClick();
}
private void TB_yamo_no_TextChanged(object sender, EventArgs e)
{
search();
}
private void DT_end_ValueChanged(object sender, EventArgs e)
{
search();
}
private void TB_kehu_name_TextChanged(object sender, EventArgs e)
{
search();
}
private void TB_huanzhe_TextChanged(object sender, EventArgs e)
{
search();
}
private void TB_yewuyuan_TextChanged(object sender, EventArgs e)
{
search();
}
private void BN_print_Click(object sender, EventArgs e)
{
}
//-----------------common-----------------------------------
public void formClose()
{
this.PForm.Show();
this.Dispose();
}
public void mohuSearch()
{
try
{
conn = new SqlConnection(DRIVER);
string SqlStr = "";
if (String.IsNullOrEmpty(TB_key.Text.Trim()))
{
SqlStr = "select s.id, kehu_name, doctor_name, yamo_no, ya_type, yawi, color, remark_id, remark_text, price, amount, yewuyuan, product_no, shouhuo_date, huanzhe, fangong_yuanyin from shouhuo s left join remark r on s.remark_id=r.id";
}
else
{ //没有price 和amount 的like
SqlStr = "select s.id, kehu_name, doctor_name, yamo_no, ya_type, yawi, color, remark_id, remark_text, price, amount, yewuyuan, product_no, shouhuo_date, huanzhe, fangong_yuanyin from shouhuo s left join remark r on s.remark_id=r.id"
+ " where "
+ "remark_text like '" + "%" + TB_key.Text.Trim() + "%" + "' "
+ "or s.id like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or kehu_name like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or doctor_name like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or yamo_no like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or ya_type like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or yawi like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or color like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or remark_id like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or remark_text like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or yewuyuan like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or product_no like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or shouhuo_date like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or huanzhe like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or fangong_yuanyin like '" + "%" + TB_key.Text.Trim() + "%" + "'";
}
da = new SqlDataAdapter(SqlStr, conn);
ds.Clear();
da.Fill(ds);
this.dv1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception err)
{
Console.WriteLine("读取数据库出错" + err.Message);
}
finally
{
conn.Close();
}
}
public bool checkForm()
{
bool flag = true;
return flag;
}
//search by options
public void search()
{
try
{
conn = new SqlConnection(DRIVER);
string resultStr = addSearchOptions(sql_select_all);
da = new SqlDataAdapter(resultStr, conn);
ds.Clear();
da.Fill(ds);
this.dv1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception err)
{
MessageBox.Show("数据库出错" + err.Message);
}
finally
{
conn.Close();
}
}
public void addRowClick()
{
shouhuoAddForm shouhuoaddForm = new shouhuoAddForm();
shouhuoaddForm.Pform = this;
shouhuoaddForm.Show();
}
public void dv1Load()
{
try
{
conn = new SqlConnection(DRIVER);
da = new SqlDataAdapter(sql_select_all, conn);
ds.Clear();
da.Fill(ds);
this.dv1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception err)
{
MessageBox.Show("数据库出错" + err.Message);
}
finally
{
conn.Close();
}
}
public string addSearchOptions(string SqlStr)
{
//根据是否为空为sql添加条件
if (TB_yamo_no.Text.Trim() != "")
{
SqlStr = SqlStr + "and yamo_no like '" + "%"+TB_yamo_no.Text.Trim() + "%"+"'";
}
if (TB_huanzhe.Text.Trim() != "")
{
SqlStr = SqlStr + "and huanzhe like '" + "%" + TB_huanzhe.Text.Trim() + "%" + "'";
}
if (TB_kehu_name.Text.Trim() != "")
{
SqlStr = SqlStr + "and kehu_name like '" + "%" + TB_kehu_name.Text.Trim() + "%" + "'";
}
if (TB_yewuyuan.Text.Trim() != "")
{
SqlStr = SqlStr + "and yewuyuan like '" + "%" + TB_yewuyuan.Text.Trim() + "%" + "'";
}
//时间条件
if ((DT_start.Visible == true) && (DT_end.Visible == true))
{
SqlStr = SqlStr + "and shouhuo_date between '" + DT_start.Value.Date + "' and '" + DT_end.Value.Date + "'";
}
return SqlStr;
}
public void showDate()
{
DT_start.Visible = true;
DT_end.Visible = true;
LB_fro.Visible = true;
LB_to.Visible = true;
}
public void hideDate()
{
DT_start.Visible = false;
DT_end.Visible = false;
LB_fro.Visible = false;
LB_to.Visible = false;
}
public void deleteRows()
{
for (int i = this.dv1.SelectedRows.Count; i > 0; i--)
{
string ID = this.dv1.SelectedRows[i - 1].Cells[0].Value.ToString();
this.dv1.Rows.RemoveAt(this.dv1.SelectedRows[i - 1].Index);
string SQL_Delete = "delete from shouhuo where id ='" + ID + "'";
int s = Convert.ToInt32(Execute(SQL_Delete)); //cl是操作类的一个对像,Execute()是类中的一个方法
if (s != 0)
{
MessageBox.Show("成功删除选中行数据!");
}
}
}
public int Execute(string SQL)
{
conn = new SqlConnection(DRIVER);
SqlCommand cmd = new SqlCommand(SQL, conn);
int i = 0;
try
{
conn.Open();
i = Convert.ToInt32(cmd.ExecuteNonQuery());
}
catch (Exception err)
{
Console.WriteLine("读取数据库出错" + err.Message);
}
finally
{
conn.Close();
}
return i;
}
public void modifyClick()
{
shouhuoMForm mForm = new shouhuoMForm();
mForm.pForm = this;
try
{
mForm.PID = this.dv1.SelectedRows[0].Cells[0].Value.ToString();
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
mForm.Show();
}
public void initForm()
{
if (this.mode == 0)
{
DT_start.Visible = false;
DT_end.Visible = false;
LB_fro.Visible = false;
LB_to.Visible = false;
BN_make_chuhuo.Visible = false;
}
if (this.mode == 1)
{
DT_start.Visible = false;
DT_end.Visible = false;
LB_fro.Visible = false;
LB_to.Visible = false;
BN_make_chuhuo.Visible = true;
BN_add.Visible = false;
BN_delete.Visible = false;
BN_modify.Visible = false;
}
}
}
}
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.SqlClient;
namespace meifengSystem
{
public partial class shouhuoForm : Form
{
public Form PForm = null;
public int mode = 0;
SqlConnection conn = null;
string DRIVER = "Server=127.0.0.1;UID=sa;PWD=admin;DataBase=factory";
SqlDataAdapter da;
DataSet ds = new DataSet();
//select_all:无条件搜索+where1=1
string sql_select_all = "select s.id, kehu_name, doctor_name, yamo_no, ya_type, yawi, color, remark_id, remark_text, price, amount, yewuyuan, product_no, shouhuo_date, huanzhe, fangong_yuanyin from shouhuo s left join remark r on s.remark_id=r.id where 1=1";
public shouhuoForm()
{
InitializeComponent();
}
private void shouhuoForm_Load(object sender, EventArgs e)
{
initForm();
dv1Load();
}
private void BN_add_Click(object sender, EventArgs e)
{
addRowClick();
}
private void shouhuoForm_FormClosed(object sender, FormClosedEventArgs e)
{
formClose();
}
private void TB_key_TextChanged(object sender, EventArgs e)
{
mohuSearch();
}
private void BN_search_all_Click(object sender, EventArgs e)
{
mohuSearch();
}
private void BN_search_Click(object sender, EventArgs e)
{
search();
}
private void DT_start_ValueChanged(object sender, EventArgs e)
{
search();
}
private void BN_add_date_Click(object sender, EventArgs e)
{
showDate();
search();
}
private void BN_del_date_Click(object sender, EventArgs e)
{
hideDate();
search();
}
private void BN_delete_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("确定删除当前选中的行吗?", "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
deleteRows();
}
}
private void BN_modify_Click(object sender, EventArgs e)
{
modifyClick();
}
private void TB_yamo_no_TextChanged(object sender, EventArgs e)
{
search();
}
private void DT_end_ValueChanged(object sender, EventArgs e)
{
search();
}
private void TB_kehu_name_TextChanged(object sender, EventArgs e)
{
search();
}
private void TB_huanzhe_TextChanged(object sender, EventArgs e)
{
search();
}
private void TB_yewuyuan_TextChanged(object sender, EventArgs e)
{
search();
}
private void BN_print_Click(object sender, EventArgs e)
{
}
//-----------------common-----------------------------------
public void formClose()
{
this.PForm.Show();
this.Dispose();
}
public void mohuSearch()
{
try
{
conn = new SqlConnection(DRIVER);
string SqlStr = "";
if (String.IsNullOrEmpty(TB_key.Text.Trim()))
{
SqlStr = "select s.id, kehu_name, doctor_name, yamo_no, ya_type, yawi, color, remark_id, remark_text, price, amount, yewuyuan, product_no, shouhuo_date, huanzhe, fangong_yuanyin from shouhuo s left join remark r on s.remark_id=r.id";
}
else
{ //没有price 和amount 的like
SqlStr = "select s.id, kehu_name, doctor_name, yamo_no, ya_type, yawi, color, remark_id, remark_text, price, amount, yewuyuan, product_no, shouhuo_date, huanzhe, fangong_yuanyin from shouhuo s left join remark r on s.remark_id=r.id"
+ " where "
+ "remark_text like '" + "%" + TB_key.Text.Trim() + "%" + "' "
+ "or s.id like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or kehu_name like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or doctor_name like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or yamo_no like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or ya_type like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or yawi like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or color like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or remark_id like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or remark_text like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or yewuyuan like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or product_no like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or shouhuo_date like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or huanzhe like '" + "%" + TB_key.Text.Trim() + "%" + "'"
+ "or fangong_yuanyin like '" + "%" + TB_key.Text.Trim() + "%" + "'";
}
da = new SqlDataAdapter(SqlStr, conn);
ds.Clear();
da.Fill(ds);
this.dv1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception err)
{
Console.WriteLine("读取数据库出错" + err.Message);
}
finally
{
conn.Close();
}
}
public bool checkForm()
{
bool flag = true;
return flag;
}
//search by options
public void search()
{
try
{
conn = new SqlConnection(DRIVER);
string resultStr = addSearchOptions(sql_select_all);
da = new SqlDataAdapter(resultStr, conn);
ds.Clear();
da.Fill(ds);
this.dv1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception err)
{
MessageBox.Show("数据库出错" + err.Message);
}
finally
{
conn.Close();
}
}
public void addRowClick()
{
shouhuoAddForm shouhuoaddForm = new shouhuoAddForm();
shouhuoaddForm.Pform = this;
shouhuoaddForm.Show();
}
public void dv1Load()
{
try
{
conn = new SqlConnection(DRIVER);
da = new SqlDataAdapter(sql_select_all, conn);
ds.Clear();
da.Fill(ds);
this.dv1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception err)
{
MessageBox.Show("数据库出错" + err.Message);
}
finally
{
conn.Close();
}
}
public string addSearchOptions(string SqlStr)
{
//根据是否为空为sql添加条件
if (TB_yamo_no.Text.Trim() != "")
{
SqlStr = SqlStr + "and yamo_no like '" + "%"+TB_yamo_no.Text.Trim() + "%"+"'";
}
if (TB_huanzhe.Text.Trim() != "")
{
SqlStr = SqlStr + "and huanzhe like '" + "%" + TB_huanzhe.Text.Trim() + "%" + "'";
}
if (TB_kehu_name.Text.Trim() != "")
{
SqlStr = SqlStr + "and kehu_name like '" + "%" + TB_kehu_name.Text.Trim() + "%" + "'";
}
if (TB_yewuyuan.Text.Trim() != "")
{
SqlStr = SqlStr + "and yewuyuan like '" + "%" + TB_yewuyuan.Text.Trim() + "%" + "'";
}
//时间条件
if ((DT_start.Visible == true) && (DT_end.Visible == true))
{
SqlStr = SqlStr + "and shouhuo_date between '" + DT_start.Value.Date + "' and '" + DT_end.Value.Date + "'";
}
return SqlStr;
}
public void showDate()
{
DT_start.Visible = true;
DT_end.Visible = true;
LB_fro.Visible = true;
LB_to.Visible = true;
}
public void hideDate()
{
DT_start.Visible = false;
DT_end.Visible = false;
LB_fro.Visible = false;
LB_to.Visible = false;
}
public void deleteRows()
{
for (int i = this.dv1.SelectedRows.Count; i > 0; i--)
{
string ID = this.dv1.SelectedRows[i - 1].Cells[0].Value.ToString();
this.dv1.Rows.RemoveAt(this.dv1.SelectedRows[i - 1].Index);
string SQL_Delete = "delete from shouhuo where id ='" + ID + "'";
int s = Convert.ToInt32(Execute(SQL_Delete)); //cl是操作类的一个对像,Execute()是类中的一个方法
if (s != 0)
{
MessageBox.Show("成功删除选中行数据!");
}
}
}
public int Execute(string SQL)
{
conn = new SqlConnection(DRIVER);
SqlCommand cmd = new SqlCommand(SQL, conn);
int i = 0;
try
{
conn.Open();
i = Convert.ToInt32(cmd.ExecuteNonQuery());
}
catch (Exception err)
{
Console.WriteLine("读取数据库出错" + err.Message);
}
finally
{
conn.Close();
}
return i;
}
public void modifyClick()
{
shouhuoMForm mForm = new shouhuoMForm();
mForm.pForm = this;
try
{
mForm.PID = this.dv1.SelectedRows[0].Cells[0].Value.ToString();
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
mForm.Show();
}
public void initForm()
{
if (this.mode == 0)
{
DT_start.Visible = false;
DT_end.Visible = false;
LB_fro.Visible = false;
LB_to.Visible = false;
BN_make_chuhuo.Visible = false;
}
if (this.mode == 1)
{
DT_start.Visible = false;
DT_end.Visible = false;
LB_fro.Visible = false;
LB_to.Visible = false;
BN_make_chuhuo.Visible = true;
BN_add.Visible = false;
BN_delete.Visible = false;
BN_modify.Visible = false;
}
}
}
}
- 主表界面模板code
- 修改窗口模板code
- Flex界面模板
- TabHost指界面模板
- 后台模板界面
- 界面元模板构件
- 网站UI界面模板
- code smith 三层实体模板
- 新增子窗口模板code
- c++ 模板、特化实例 code
- Eclipse 导入Code Template模板
- Code::Blocks自定义代码模板
- [应用模板]移动应用界面
- 改code blocks的终端界面
- 安卓微信不回调授权界面,无法获取code原因
- myeclipse设置代码模板Code Templates
- 自定义Xcode代码模板:Code Snippet
- Java 编译器中的code templates的模板
- HDU 1421 搬寝室
- C-DOCSIS Service Class
- 不用额外变量实现变量交换 及 大数相加
- poj2184 Cow Exhibition 01背包 变形
- 悟透delphi 第三章 多线程
- 主表界面模板code
- 1.3.1 FatMouse trade
- CentOS-6.4 下成功安装openvswitch
- Python学习笔记(5)--类相关语法
- 移动终端的多国语言支持
- [经验总结] HIT CS科班对计算机专业素养的理解
- 事务日志传送用户权限设置及配置(2篇)
- 关于Zbar和ZXing这两个无比强大的二维码和条形码识别工具
- 从零开始打造自己的Linux开发环境(三, vim)