Esempio n. 1
0
        public ActionResult JSDeleteCertificate(SubmitHandler handler)//删除响应
        {
            var    s = X.GetCmp <Store>("CertificateStore");
            string id, path = "";

            Dictionary <string, string>[] values = JSON.Deserialize <Dictionary <string, string>[]>(handler.Json.ToString());

            if (values.Length > 0)//js代码已经处理过,此处判断无用,可删
            {
                foreach (Dictionary <string, string> row in values)
                {
                    id = row["ID"];
                    T_HR_Certificate de = entities.T_HR_Certificate.Find(id);
                    if (de != null)
                    {
                        if (de.CerImage != null)
                        {
                            path = Server.MapPath(de.CerImage);
                        }
                        de.Valid = false;
                        //entities.T_HR_Certificate.Remove(de);
                        try
                        {
                            entities.SaveChanges();
                            if (System.IO.File.Exists(path))
                            {
                                System.IO.File.Delete(path);
                            }
                            s.Remove(id);
                        }
                        catch (Exception e)
                        {
                            X.Msg.Alert("警告", "数据删除失败!<br /> note:" + e.Message).Show();
                        }
                    }
                }
            }
            else
            {
                X.Msg.Alert("提示", "未选择任何列!").Show();
            }
            return(this.Direct());
        }
Esempio n. 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());
            }
        }