Example #1
0
        public ActionResult AddCertificate(string id) //在修改时传递的为contractid
        {
            if (id == "-1")                           //-1为添加
            {
                return(View());
            }
            else//否则为修改
            {
                V_HR_Certificate item = (from o in entities.V_HR_Certificate
                                         where o.ID == id
                                         select o).First();


                return(View(item));
            }
        }
Example #2
0
        public ActionResult AddOrEditCertificate(V_HR_Certificate re)
        {
            FileUploadField upload = this.GetCmp <FileUploadField>("Userimage");
            HttpPostedFile  UserImageFile;
            string          UserImage = "", UserImageSavePath = "", UserImageFileType, path = "";

            UserImageFile = upload.PostedFile;

            if (UserImageFile.ContentLength <= 20971520)
            {
                DirectResult     r        = new DirectResult();
                T_HR_Certificate reupdate = entities.T_HR_Certificate.Find(re.ID);

                if (upload.HasFile)
                {
                    UserImage = string.Format("~/AttachFile/HR/Certificate/{0}/{1}{2}", re.StaffID, Guid.NewGuid().ToString(),
                                              Path.GetExtension(UserImageFile.FileName));
                    UserImageSavePath =
                        Server.MapPath(UserImage);
                    UserImageFileType = UserImageFile.ContentType;
                }

                if (UserImageSavePath != "" && Path.GetDirectoryName(UserImageSavePath) != null)
                {
                    if (Directory.Exists(Path.GetDirectoryName(UserImageSavePath)) == false)
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(UserImageSavePath));
                    }

                    UserImageFile.SaveAs(UserImageSavePath);
                }

                if (reupdate == null)//为空为添加
                {
                    T_HR_Certificate readd = new T_HR_Certificate();
                    readd.ID              = Guid.NewGuid().ToString();
                    readd.StaffID         = re.StaffID;
                    readd.CertificateName = re.CertificateName;
                    readd.CertificateNum  = re.CertificateNum;
                    readd.Startdate       = re.Startdate;
                    readd.Deadline        = re.Deadline;
                    readd.State           = re.State;
                    if (UserImage != "")
                    {
                        readd.CerImage = UserImage;
                    }
                    readd.Remark      = re.Remark;
                    readd.Valid       = true;
                    readd.CreaterName = new LoginUser().EmployeeId;
                    readd.CreateTime  = DateTime.Now;

                    entities.T_HR_Certificate.Add(readd);
                    try
                    {
                        entities.SaveChanges();
                        r.Success = true;
                        X.Msg.Alert("提示", "保存成功!", new JFunction {
                            Fn = "closewindow"
                        }).Show();
                    }
                    catch (Exception e)
                    {
                        X.Msg.Alert("警告", "数据保存失败!<br /> note:" + e.Message, new JFunction {
                            Fn = "closewindow"
                        }).Show();
                        r.Success = false;
                    }
                }
                else//否则为修改
                {
                    reupdate.StaffID         = re.StaffID;
                    reupdate.CertificateName = re.CertificateName;
                    reupdate.CertificateNum  = re.CertificateNum;
                    reupdate.Startdate       = re.Startdate;
                    reupdate.Deadline        = re.Deadline;
                    reupdate.State           = re.State;
                    if (UserImage != "")
                    {
                        if (reupdate.CerImage != null)
                        {
                            path = Server.MapPath(reupdate.CerImage);
                        }
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                        reupdate.CerImage = UserImage;
                    }
                    reupdate.Remark     = re.Remark;
                    reupdate.Valid      = true;
                    reupdate.EditorName = new LoginUser().EmployeeId;
                    reupdate.EditeTime  = DateTime.Now;

                    try
                    {
                        entities.SaveChanges();
                        r.Success = true;
                        X.Msg.Alert("提示", "保存成功!", new JFunction {
                            Fn = "closewindow"
                        }).Show();
                    }
                    catch (Exception e)
                    {
                        X.Msg.Alert("警告", "数据保存失败!<br /> note:" + e.Message, new JFunction {
                            Fn = "closewindow"
                        }).Show();
                        r.Success = false;
                    }
                }

                return(r);
            }
            else
            {
                X.Msg.Alert("警告", "图片需要小于20M!").Show();
                return(this.Direct());
            }
        }