修改窗口模板code
2013-04-02 21:31
417 查看
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 shouhuoMForm : Form
{
//common
public Form pForm = null;
public string PID = "";
string DRIVER = "Server=127.0.0.1;UID=sa;PWD=admin;DataBase=factory";
SqlConnection conn = null;
SqlDataAdapter da = null;
DataSet ds = new DataSet();
//private
decimal price;
decimal amount;
public shouhuoMForm()
{
InitializeComponent();
}
private void shouhuoMForm_Load(object sender, EventArgs e)
{
init();
}
private void BN_modef_Click(object sender, EventArgs e)
{
if (checkForm() == true)
{
DialogResult result = MessageBox.Show("确定修改吗?", "修改", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
if (deleteRow(L_PID.Text) !=0)
{
if (addShouhuoRow(L_PID.Text) != 0)
{
MessageBox.Show("修改成功!");
}
else
{
MessageBox.Show("修改失败!");
}
}
else
{
MessageBox.Show("修改失败!");
}
}
}
}
private void shouhuoMForm_FormClosed(object sender, FormClosedEventArgs e)
{
FormClose();
}
//---------Common---------------------------------------------------------------------
public void init()
{
LoadData();
L_PID.Visible = false;
Load_CB_Remark();
}
public void LoadData()
{
if (PID == "")
{
MessageBox.Show("请先选择要修改的行!");
this.Hide();
this.Dispose();
}
else
{
try
{
conn = new SqlConnection(DRIVER);
string MainStr = "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 s.id='" + PID + "'";
da = new SqlDataAdapter(MainStr, conn);
da.Fill(ds);
L_PID.Text = ds.Tables[0].Rows[0]["id"].ToString();
TB_amount.Text = ds.Tables[0].Rows[0]["amount"].ToString();
TB_color.Text = ds.Tables[0].Rows[0]["color"].ToString();
TB_doctor_name.Text = ds.Tables[0].Rows[0]["doctor_name"].ToString();
TB_fangong_yuanyin.Text = ds.Tables[0].Rows[0]["fangong_yuanyin"].ToString();
TB_huanzhe.Text = ds.Tables[0].Rows[0]["huanzhe"].ToString();
TB_kehu_name.Text = ds.Tables[0].Rows[0]["kehu_name"].ToString();
TB_price.Text = ds.Tables[0].Rows[0]["price"].ToString();
TB_product_no.Text = ds.Tables[0].Rows[0]["product_no"].ToString();
TB_ya_type.Text = ds.Tables[0].Rows[0]["ya_type"].ToString();
TB_yamo_no.Text = ds.Tables[0].Rows[0]["yamo_no"].ToString();
TB_yawi.Text = ds.Tables[0].Rows[0]["yawi"].ToString();
TB_yewuyuan.Text = ds.Tables[0].Rows[0]["yewuyuan"].ToString();
CB_remark.SelectedValue = int.Parse(ds.Tables[0].Rows[0]["remark_id"].ToString());
DT_shouhuo_date.Value = Convert.ToDateTime(ds.Tables[0].Rows[0]["shouhuo_date"].ToString());
}
catch (Exception err)
{
MessageBox.Show("数据库出错" + err.Message);
}
finally
{
conn.Close();
}
}
}
public void Load_CB_Remark()
{
conn = new SqlConnection(DRIVER);
da = new SqlDataAdapter("select * from remark", conn);
da.Fill(ds, "table");
try
{
CB_remark.DataSource = ds.Tables["table"];
CB_remark.ValueMember = "id";
CB_remark.DisplayMember = "remark_text";
}
catch (Exception err)
{
MessageBox.Show("load备注类型出错:" + err.Message);
}
}
public bool checkForm()
{
bool result = true;
if (TB_price.Text.Trim() != "" && (System.Decimal.TryParse(TB_price.Text.Trim(), out price) == false))
{
MessageBox.Show("单价输入不是合法的");
result = false;
}
if (TB_amount.Text.Trim() != "" && (System.Decimal.TryParse(TB_amount.Text.Trim(), out amount) == false))
{
MessageBox.Show("金额输入不是合法的");
result = false;
}
return result;
}
public int deleteRow(string ID)
{
int s = 0;
string SQL_Delete = "delete from shouhuo where id ='" + ID + "'";
s = Execute(SQL_Delete);
return s;
}
public int addShouhuoRow(string ID)
{
int s = 0;
string InsertSql = "insert into shouhuo(id,kehu_name, doctor_name, yamo_no, ya_type, yawi, color, remark_id, price, amount, yewuyuan, product_no, shouhuo_date, huanzhe, fangong_yuanyin)"
+ "values('"
+ ID + "','"
+ TB_kehu_name.Text + "','"
+ TB_doctor_name.Text + "','"
+ TB_yamo_no.Text + "','"
+ TB_ya_type.Text + "','"
+ TB_yawi.Text + "','"
+ TB_color.Text + "',"
+ Convert.ToInt32(this.CB_remark.SelectedValue) + ","
+ price + ","
+ amount + " ,'"
+ TB_yewuyuan.Text + "','"
+ TB_product_no.Text + "','"
+ DT_shouhuo_date.Value.Date + "','"
+ TB_huanzhe.Text + "','"
+ TB_fangong_yuanyin.Text + "')";
s = Execute(InsertSql);
return s;
}
public void FormClose()
{
shouhuoForm sf = (shouhuoForm)this.pForm;
sf.dv1Load();
}
public int Execute(string SQL)
{
conn = new SqlConnection(DRIVER);
SqlCommand cmd = new SqlCommand(SQL, conn);
int i = 0;
try
{
conn.Open();
i =cmd.ExecuteNonQuery();
}
catch (Exception err)
{
Console.WriteLine("数据库出错" + err.Message);
}
finally
{
conn.Close();
}
return i;
}
}
}
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 shouhuoMForm : Form
{
//common
public Form pForm = null;
public string PID = "";
string DRIVER = "Server=127.0.0.1;UID=sa;PWD=admin;DataBase=factory";
SqlConnection conn = null;
SqlDataAdapter da = null;
DataSet ds = new DataSet();
//private
decimal price;
decimal amount;
public shouhuoMForm()
{
InitializeComponent();
}
private void shouhuoMForm_Load(object sender, EventArgs e)
{
init();
}
private void BN_modef_Click(object sender, EventArgs e)
{
if (checkForm() == true)
{
DialogResult result = MessageBox.Show("确定修改吗?", "修改", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
if (deleteRow(L_PID.Text) !=0)
{
if (addShouhuoRow(L_PID.Text) != 0)
{
MessageBox.Show("修改成功!");
}
else
{
MessageBox.Show("修改失败!");
}
}
else
{
MessageBox.Show("修改失败!");
}
}
}
}
private void shouhuoMForm_FormClosed(object sender, FormClosedEventArgs e)
{
FormClose();
}
//---------Common---------------------------------------------------------------------
public void init()
{
LoadData();
L_PID.Visible = false;
Load_CB_Remark();
}
public void LoadData()
{
if (PID == "")
{
MessageBox.Show("请先选择要修改的行!");
this.Hide();
this.Dispose();
}
else
{
try
{
conn = new SqlConnection(DRIVER);
string MainStr = "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 s.id='" + PID + "'";
da = new SqlDataAdapter(MainStr, conn);
da.Fill(ds);
L_PID.Text = ds.Tables[0].Rows[0]["id"].ToString();
TB_amount.Text = ds.Tables[0].Rows[0]["amount"].ToString();
TB_color.Text = ds.Tables[0].Rows[0]["color"].ToString();
TB_doctor_name.Text = ds.Tables[0].Rows[0]["doctor_name"].ToString();
TB_fangong_yuanyin.Text = ds.Tables[0].Rows[0]["fangong_yuanyin"].ToString();
TB_huanzhe.Text = ds.Tables[0].Rows[0]["huanzhe"].ToString();
TB_kehu_name.Text = ds.Tables[0].Rows[0]["kehu_name"].ToString();
TB_price.Text = ds.Tables[0].Rows[0]["price"].ToString();
TB_product_no.Text = ds.Tables[0].Rows[0]["product_no"].ToString();
TB_ya_type.Text = ds.Tables[0].Rows[0]["ya_type"].ToString();
TB_yamo_no.Text = ds.Tables[0].Rows[0]["yamo_no"].ToString();
TB_yawi.Text = ds.Tables[0].Rows[0]["yawi"].ToString();
TB_yewuyuan.Text = ds.Tables[0].Rows[0]["yewuyuan"].ToString();
CB_remark.SelectedValue = int.Parse(ds.Tables[0].Rows[0]["remark_id"].ToString());
DT_shouhuo_date.Value = Convert.ToDateTime(ds.Tables[0].Rows[0]["shouhuo_date"].ToString());
}
catch (Exception err)
{
MessageBox.Show("数据库出错" + err.Message);
}
finally
{
conn.Close();
}
}
}
public void Load_CB_Remark()
{
conn = new SqlConnection(DRIVER);
da = new SqlDataAdapter("select * from remark", conn);
da.Fill(ds, "table");
try
{
CB_remark.DataSource = ds.Tables["table"];
CB_remark.ValueMember = "id";
CB_remark.DisplayMember = "remark_text";
}
catch (Exception err)
{
MessageBox.Show("load备注类型出错:" + err.Message);
}
}
public bool checkForm()
{
bool result = true;
if (TB_price.Text.Trim() != "" && (System.Decimal.TryParse(TB_price.Text.Trim(), out price) == false))
{
MessageBox.Show("单价输入不是合法的");
result = false;
}
if (TB_amount.Text.Trim() != "" && (System.Decimal.TryParse(TB_amount.Text.Trim(), out amount) == false))
{
MessageBox.Show("金额输入不是合法的");
result = false;
}
return result;
}
public int deleteRow(string ID)
{
int s = 0;
string SQL_Delete = "delete from shouhuo where id ='" + ID + "'";
s = Execute(SQL_Delete);
return s;
}
public int addShouhuoRow(string ID)
{
int s = 0;
string InsertSql = "insert into shouhuo(id,kehu_name, doctor_name, yamo_no, ya_type, yawi, color, remark_id, price, amount, yewuyuan, product_no, shouhuo_date, huanzhe, fangong_yuanyin)"
+ "values('"
+ ID + "','"
+ TB_kehu_name.Text + "','"
+ TB_doctor_name.Text + "','"
+ TB_yamo_no.Text + "','"
+ TB_ya_type.Text + "','"
+ TB_yawi.Text + "','"
+ TB_color.Text + "',"
+ Convert.ToInt32(this.CB_remark.SelectedValue) + ","
+ price + ","
+ amount + " ,'"
+ TB_yewuyuan.Text + "','"
+ TB_product_no.Text + "','"
+ DT_shouhuo_date.Value.Date + "','"
+ TB_huanzhe.Text + "','"
+ TB_fangong_yuanyin.Text + "')";
s = Execute(InsertSql);
return s;
}
public void FormClose()
{
shouhuoForm sf = (shouhuoForm)this.pForm;
sf.dv1Load();
}
public int Execute(string SQL)
{
conn = new SqlConnection(DRIVER);
SqlCommand cmd = new SqlCommand(SQL, conn);
int i = 0;
try
{
conn.Open();
i =cmd.ExecuteNonQuery();
}
catch (Exception err)
{
Console.WriteLine("数据库出错" + err.Message);
}
finally
{
conn.Close();
}
return i;
}
}
}
相关文章推荐
- 新增子窗口模板code
- Visual Studio Code修改HTML Snippets插件中默认模板内容
- webstorm 修改文件生成模板 File and Code Templates
- 浅谈Joomla!流行模板的修改方法
- vs2008修改模板-自定义版权信息
- EasyUi – 5.修改$.messager.show() 弹出窗口在浏览器顶部中间出现
- kali linux修改主题和窗口皮肤
- linux中codeblocks程序编译运行后不出现控制台窗口
- [导入]修改VS2008代码重构模板简化接口属性成员实现
- MFC修改窗口背景颜色
- myeclipse中修改servlet的模板代码
- 修改 Ops Manager 的安装和产品模板文件
- MFC修改主窗口的标题
- PB-数据窗口缓冲区与数据修改状态
- Tomcat配置+JSP页面模板修改UTF-8
- 如何修改Carbide.C++ 1.2的模板文件格式
- watij自己修改模态窗口中的按钮[原创]
- 修改MFC标题栏上的图标和修改MFC窗口标题
- spm使用之五修改spm自带文档主题模板
- PhpStorm中terminal窗口字体修改