WPF多表新增方法
Posted weixin_44543308
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF多表新增方法相关的知识,希望对你有一定的参考价值。
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
开发工具与关键技术:WPF 、Insert
撰写日期:2020年10月07日
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在WPF多表新增其实也不是想象中的那么难,只要获取到你要新增的
ID就可以了。下面来看数据可的写法:
接下来,来看服务端的方法代码:
//操作契约
[OperationContract]
//新增客户
public int btnInsert_Click_InsertClient(int intStaffID,int intCustomerTypeID, string strClienteleName,string strDuty,string strEmail,string strFaxes,bool blGender,string strPhone,string strQQ,string strRemark,string strAddress,DateTime dtReleaseTime,string strClientNumber)
SqlParameter[] myInsertClient =
new SqlParameter("@type",SqlDbType.Char),
new SqlParameter("@StaffID",SqlDbType.Int),//员工ID
new SqlParameter("@CustomerTypeID",SqlDbType.Int),//客户类型ID
new SqlParameter("@ClienteleName",SqlDbType.Char),//客户名称
new SqlParameter("@Duty",SqlDbType.Char),//职务
new SqlParameter("@Email",SqlDbType.Char),//电子邮件
new SqlParameter("@Faxes",SqlDbType.Char),//传真
new SqlParameter("@Gender",SqlDbType.Bit),//性别
new SqlParameter("@Phone",SqlDbType.Char),//电话号码
new SqlParameter("@QQ",SqlDbType.Char),//QQ
new SqlParameter("@Remark",SqlDbType.Char),//备注
new SqlParameter("@Address",SqlDbType.Char),//地址
new SqlParameter("@ReleaseTime",SqlDbType.DateTime),//发布时间
new SqlParameter("@ClientNumber",SqlDbType.Char),//客户编号;
myInsertClient[0].Value = "btnInsert_Click_InsertClient";
myInsertClient[1].Value = intStaffID;//员工ID
myInsertClient[2].Value = intCustomerTypeID;//客户类型ID
myInsertClient[3].Value = strClienteleName;//客户名称
myInsertClient[4].Value = strDuty;//职务
myInsertClient[5].Value = strEmail;//电子邮件
myInsertClient[6].Value = strFaxes;//传真
myInsertClient[7].Value = blGender;//性别
myInsertClient[8].Value = strPhone;//电话号码
myInsertClient[9].Value = strQQ;//QQ
myInsertClient[10].Value = strRemark;//备注
myInsertClient[11].Value = strAddress;//地址
myInsertClient[12].Value = dtReleaseTime;//发布时间
myInsertClient[13].Value = strClientNumber;//客户编号
DataTable dt = myDALMethod.QueryDataSet("UC_ClientManagement", myInsertClient).Tables[0];//这里用的是DataTable的方法来获取刚刚新增的ID
int count = int.Parse(dt.Rows[0][0].ToString());
return count;
//操作契约
[OperationContract]
//新增客户明细表
public int btnInsert_Clients(int intClienteleID)
SqlParameter[] myClient =
new SqlParameter("@type",SqlDbType.Char),
new SqlParameter("@ClienteleID",SqlDbType.Int), ;
myClient[0].Value = "btnInsert_Clients";
myClient[1].Value = intClienteleID;
DataTable dt = myDALMethod.QueryDataSet("UC_ClientManagement", myClient).Tables[0];
int count = int.Parse(dt.Rows[0][0].ToString());
return count;
最后来看下;客户端的代码,如下:
//保存新增
private void btnSave_Click(object sender, RoutedEventArgs e)
try
// 获取页面数据
bool blGender = true || false;//性别
if (cbo_Sex.Text.Equals("男"))
blGender = true;
else if (cbo_Sex.Text.Equals("女"))
blGender = false;
int intStaffID = Convert.ToInt32(cbo_Staff.SelectedValue);//员工名称
int intCustomerTypeID = Convert.ToInt32(cbo_DepartType.SelectedValue);
string strClienteleName = txt_ClientName.Text.ToString();//客户名称
string strEmail = txt_Email.Text.ToString();//邮件
string strDuty = txt_Duty.Text.ToString();//职务
string strQQ = txt_QQ.Text.ToString();//QQ
string strPhone = txt_Phone.Text.ToString();//联系电话
string strFaxes = txt_Faxes.Text.ToString();//传真
string strAddress = txt_Address.Text.ToString();//地址
string strRemark = txt_Remark.Text.ToString();//备注
DateTime dtReleaseTime = Convert.ToDateTime(dtp_ReleaseTime.Text.ToString());//发布时间
string strClientNumber = txt_ClientNumber.Text.ToString();//客户编号
//判断页面数据不为空
if (intStaffID > 0 && intCustomerTypeID > 0 && strClienteleName != "" && strEmail != "" && strPhone != "" && strAddress != ""&& strClientNumber != "")
int count = myClient.btnInsert_Click_InsertClient(intStaffID, intCustomerTypeID, strClienteleName, strDuty, strEmail, strFaxes, blGender, strPhone, strQQ, strRemark, strAddress, dtReleaseTime,strClientNumber);
if (count > 0)
//新增客户明细表
int counts = myClient.btnInsert_Clients(count);
if (counts > 0)
MessageBoxResult dr = MessageBox.Show("新增客户信息成功!", "系统提示", MessageBoxButton.OKCancel, MessageBoxImage.Asterisk);//弹出确定对话框
if (dr == MessageBoxResult.OK)//如果点了 确定按钮
//关闭窗口
this.Close();
else if (count == -1)
MessageBox.Show("客户名称重复!", "系统提示", MessageBoxButton.OKCancel, MessageBoxImage.Exclamation);//弹出确定对话框
else
MessageBox.Show("请把页面数据填写完整!", "系统提示", MessageBoxButton.OK, MessageBoxImage.Warning); //弹出确定对话框
catch (Exception ex)
MessageBox.Show(ex.Message);
最后我给大家看下,在运行的时候的获取ID值图片:图一是:新增客户的ID,图二:是获取到客户的ID新增到客户明细表中的ID
最后是结果图:图一是新增客户成功的ID,图二是新增客户明细的图片:
以上是关于WPF多表新增方法的主要内容,如果未能解决你的问题,请参考以下文章