Wpf新增

首先,先在sql写一条新增的存储语句
Wpf新增_第1张图片
然后在服务端写一个新增的方法
Wpf新增_第2张图片
Wpf新增_第3张图片
保存新增
在客户端上,先实例化服务
在这里插入图片描述
然后判断从页面获取的数据是否为空,如果不为空则获取从页面传回的数据
调用服务端的新增方法,如果服务端返回数据,则新增成功
代码如下:

private void btn_Sure_Click(object sender, RoutedEventArgs e)
        {
      try
            {
                //获取页面数据
                //提取上传的文件(图片)
                byte[][] bytePicture = new byte[lstBytes.Count][];
                for (int i = 0; i < lstBytes.Count; i++)
                {
                    bytePicture[i] = lstBytes[i];
                }
                //判断数据是否为空
                if (cbo_StaffType.SelectedValue.ToString() !=string.Empty && cbo_Work.SelectedValue.ToString()!=string.Empty && 
                    cbo_Post.SelectedValue.ToString()!=string.Empty && cbo_gender.SelectedValue.ToString()!=string.Empty && 
                    txt_Name.Text.ToString()!=string.Empty&& txt_Number.Text.ToString()!=string.Empty&& txt_Address.Text.ToString()!=string.Empty&& 
                    txt_idCar.Text.ToString()!=string.Empty && dtp_Birthday.Text.ToString()!=string.Empty&& dtp_EnterDate.Text.ToString()!=string.Empty &&
                    dtp_LeaveDate.Text.ToString()!=string.Empty)
                {
                    //获取页面的数据
                    int intEmployee_type_id = Convert.ToInt32(cbo_StaffType.SelectedValue);
                    int intWork_status_id = Convert.ToInt32(cbo_Work.SelectedValue);
                    int intBranch_id = Convert.ToInt32(cbo_Post.SelectedValue);
                    string strStaff_name = txt_Name.Text.ToString();
                    string strStaff_number = txt_Number.Text.ToString();
                    int intGender_id = Convert.ToInt32(cbo_gender.SelectedValue);
                    string strAge = txt_Age.Text.ToString();
                    string strId_card = txt_idCar.Text.ToString();
                    DateTime DateBirth = Convert.ToDateTime(dtp_Birthday.Text.ToString());
                    string strPhone_number = txt_PhoneNumber.Text.ToString();
                    string strAddress = txt_Address.Text.ToString();
                    string strE_mail = txt_Email.Text.ToString();
                    DateTime DateEntry_date = Convert.ToDateTime(dtp_EnterDate.Text.ToString());
                    DateTime DateDeparture_date = Convert.ToDateTime(dtp_LeaveDate.Text.ToString());
                    bool blOperator_no = (bool)chk_operator.IsChecked;           
                    //获取checkbox
                    string strNote = txt_Note.Text.ToString();
                   //调用服务端的新增方法
                   int count = MyYongHuGuanLiClient.btn_Affirm_Click_Insert(intEmployee_type_id, intWork_status_id,       intBranch_id, strStaff_name,
                      strStaff_number, intGender_id, strAge, strId_card, DateBirth,
                      strPhone_number, strAddress, strE_mail, DateEntry_date, DateDeparture_date, blOperator_no,
                       bytePicture, strNote);
                    //判断是否返回数据
                        if (count > 0)
                        {
                            MessageBoxResult dr = MessageBox.Show("新增成功!", "系统提示", MessageBoxButton.OKCancel, MessageBoxImage.Asterisk);
                            if (dr == MessageBoxResult.OK)
                            {
                                //关闭当前窗口
                                this.Close();
                            }
                        }      
                }
                else
                {
                    MessageBox.Show("新增失败,请填写完整的选项");
                }
            }
            catch (Exception )
            {

                MessageBox.Show("新增失败");
            }
        }

你可能感兴趣的:(wpf)