Пример #1
0
        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            errormsg.Text = "";
            try
            {
                CY.GFive.Core.Business.StaffTrain st = CY.GFive.Core.Business.StaffTrain.GetByCode(TrainCode.Text.Trim());

                if (st == null)
                {
                    if (TrainCode.Text.Trim() == "")
                    {
                        errormsg.Text = "人员培训编号不能为空";
                        return;
                    }
                    CY.GFive.Core.Business.StaffTrain train = new CY.GFive.Core.Business.StaffTrain();
                    CY.GFive.Core.Business.StaffTrainDetail usertrain;

                    train.Code = TrainCode.Text.Trim();
                    train.TrainName = TrainTitle.Text.Trim();
                    if (StartDate.Text.Trim() != "")
                        train.TrainStartDate = Convert.ToDateTime(StartDate.Text.Trim());

                    if (Months.Text.Trim() != "")
                        train.ConsistTime = Decimal.Parse(Months.Text.Trim());
                    train.TrainSate = ddl_TrainState.SelectedValue;
                    train.TrainCate = TrainCate.Text.Trim();
                    train.TrainDegree = TrainLevel.Text.Trim();

                    if (tb_UserIDs.Text.Trim().Equals(""))
                    {
                        Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "AddFailed!", "<script>alert('培训对象不能为空!');</script>");
                        return;
                    }
                    string[] userIdList = tb_UserIDs.Text.Split(',');

                    foreach (string item in userIdList)
                    {
                        usertrain = new CY.GFive.Core.Business.StaffTrainDetail();
                        usertrain.TrainCode = train.Code;
                        usertrain.StaffCode = (CY.GFive.Core.Business.StaffInfo.Load(int.Parse(item))).Code;
                        usertrain.Save();
                    }
                    train.Save();

                    Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "人员培训项目成功保存!", "<script>alert('保存成功!');window.location.href='TrainingList.aspx'</script>");

                }
                else
                {
                    errormsg.Text = "该人员培训已经存在,请核对培训编号";
                }
            }
            catch (Exception ex)
            {
                errormsg.Text = ex.Message;
            }
        }
Пример #2
0
        protected void BtnSubmit_Click(object sender, EventArgs e)
        {
            int id;

             if (int.TryParse(Request.QueryString["id"], out id))
             {
                 errormsg.Text = "";
                 try
                 {
                     if (TrainCode.Text.Trim() == "")
                     {
                         errormsg.Text = "人员培训编号不能为空";
                         return;
                     }
                     CY.GFive.Core.Business.StaffTrain t = CY.GFive.Core.Business.StaffTrain.GetByCode(TrainCode.Text.Trim());
                     if (t == null || t.Id == id)
                     {
                         CY.GFive.Core.Business.StaffTrain train = CY.GFive.Core.Business.StaffTrain.Load(id);
                         CY.GFive.Core.Business.StaffTrainDetail usertrain;
                         if (train != null)
                         {
                             train.Code = TrainCode.Text.Trim();
                             train.TrainName = TrainTitle.Text.Trim();
                             if (StartDate.Text.Trim() != "")
                                 train.TrainStartDate = Convert.ToDateTime(StartDate.Text.Trim());

                             if (Months.Text.Trim() != "")
                                 train.ConsistTime = Decimal.Parse(Months.Text.Trim());
                             train.TrainSate = ddl_TrainState.SelectedValue;
                             train.TrainCate = TrainCate.Text.Trim();
                             train.TrainDegree = TrainLevel.Text.Trim();

                             if (tb_UserIDs.Text.Trim().Equals(""))
                             {
                                 Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "AddFailed!", "<script>alert('培训对象不能为空!');</script>");
                                 return;
                             }

                             string[] previousUserList = preUserList.Split(',');
                             List<string> modifiedUserList = new List<string>();

                             modifiedUserList = tb_UserIDs.Text.Split(',').ToList();

                             List<string> intersectUserList = modifiedUserList.Intersect(previousUserList).ToList();
                             List<string> userListToDelete = previousUserList.Except(intersectUserList).ToList();
                             List<string> userListToAdd = modifiedUserList.Except(intersectUserList).ToList();

                             for (int i = 0; i < userListToDelete.Count(); i++)
                             {
                                 if (!userListToDelete[i].Equals(""))
                                 {
                                     string scode = (CY.GFive.Core.Business.StaffInfo.Load(int.Parse(userListToDelete[i]))).Code;
                                     string tcode = train.Code;
                                     usertrain = CY.GFive.Core.Business.StaffTrainDetail.GetByTrainAndStaff(tcode, scode);
                                     if (usertrain != null)
                                     {
                                         usertrain.DeleteOnSave();
                                         usertrain.Save();
                                     }
                                 }
                             }

                             for (int j = 0; j < userListToAdd.Count(); j++)
                             {
                                 if (!userListToAdd[j].Equals(""))
                                 {
                                     usertrain = new CY.GFive.Core.Business.StaffTrainDetail();
                                     usertrain.TrainCode = train.Code;
                                     if (CY.GFive.Core.Business.StaffInfo.Load(int.Parse(userListToAdd[j])) != null)
                                     {
                                         usertrain.StaffCode = (CY.GFive.Core.Business.StaffInfo.Load(int.Parse(userListToAdd[j]))).Code;
                                         usertrain.Save();
                                     }
                                 }
                             }
                             train.Save();

                             Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "人员培训项目成功保存!", "<script>alert('保存成功!');window.location.href='TrainingInfo.aspx?id=" + id + "'</script>");

                         }
                         else
                         {
                            errormsg.Text= "参数出错,该人员培训可能已经被删除!";
                         }
                     }
                     else
                     {
                         errormsg.Text = "该人员培训已经存在,请核对培训编号";
                     }
                 }
                 catch (Exception ex)
                 {
                     errormsg.Text = ex.Message;
                 }
             }
             else
             {
                errormsg.Text= "参数错误!";
             }
        }