Esempio n. 1
0
        /// <summary>
        /// 删除
        /// </summary>
        public void DeleteData(string id)
        {
            var msg = new ModJsonResult();

            try
            {
                BllSysFileAttach Back = new BllSysFileAttach();
                var Model             = Back.LoadData(id);
                if (Model != null)
                {
                    string path       = Model.FilePath; //文件路径
                    string savepath   = System.Web.HttpContext.Current.Server.MapPath(path);
                    string ContractId = Model.KeyId;    //关联合同ID
                    string code       = Model.ModelCode;

                    int result = Back.Delete(id);
                    if (result > 0)
                    {
                        msg.success = true;
                        if (System.IO.File.Exists(savepath))
                        {
                            System.IO.File.Delete(savepath);//删除文件
                        }

                        switch (code)
                        {
                        case "InCome":    //收入合同
                        case "OutCome":   //支付合同
                            var list = Back.QueryToAll().Where(p => p.KeyId == ContractId).ToList();
                            if (list.Count == 0)
                            {
                                var temp = new BllContractInOut().LoadData(ContractId);
                                if (temp != null)
                                {
                                    temp.HasFileAttach = false;
                                    new BllContractInOut().Update(temp);
                                }
                            }
                            break;
                        }
                    }
                    else
                    {
                        msg.success = false;
                        msg.msg     = "操作失败";
                    }
                }
            }
            catch (Exception ex)
            {
                msg.msg = "操作失败:" + ex.Message;
            }
            WriteJsonToPage(msg.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// 删除
        /// </summary>
        public void DeleteData(string id)
        {
            var msg = new ModJsonResult();

            try
            {
                var SysDir = new BllSysDirc();
                //判断字典类型是否被引用
                var model = SysDir.LoadData(id);
                int count = 0;
                var flag  = false;
                if (model != null)
                {
                    switch (model.Type)
                    {
                    case 0:    //仓库类别
                        flag = new BllContractInOut().Exists("H_OrderIn", " and StoreId='" + id + "' and Status!=" + (int)StatusEnum.除, out count);
                        if (flag == false)
                        {
                            flag = new BllContractInOut().Exists("H_Purchase", " and StoreId='" + id + "' and Status!=" + (int)StatusEnum.除, out count);
                        }
                        break;

                    case 1:    //供应商类别
                        flag = new BllContractInOut().Exists("Sys_Company", " and Type='" + id + "' and Status!=" + (int)StatusEnum.除, out count);
                        break;
                    }
                }
                if (count > 0)
                {
                    msg.success = false;
                    msg.msg     = "该字典项已被引用,不能直接进行删除。";
                }
                else
                {
                    int result = new BllSysDirc().DeleteStatus(id);
                    if (result > 0)
                    {
                        msg.success = true;
                    }
                    else
                    {
                        msg.success = false;
                        msg.msg     = "删除失败.";
                    }
                    LogInsert(OperationTypeEnum.访问, "字典类型删除操作", "删除操作成功.");
                }
            }
            catch (Exception ex)
            {
                LogInsert(OperationTypeEnum.异常, "字典类型删除操作", "删除操作异常消息:" + ex.Message.ToString());
            }
            WriteJsonToPage(msg.ToString());
        }
Esempio n. 3
0
        /// <summary>
        ///   附件上传
        /// </summary>
        public void FileUpload()
        {
            var msg = new ModJsonResult();

            try
            {
                if (Request.Files.Count > 0)
                {
                    string FileAttachPath = System.Configuration.ConfigurationManager.AppSettings["FileAttach"];//文件保存路径
                    string Dirc           = "/" + DateTime.Now.ToString("yyyy") + "/" + DateTime.Now.ToString("MM");

                    string savepath = System.Web.HttpContext.Current.Server.MapPath(FileAttachPath) + Dirc;//获取保存路径

                    if (!Directory.Exists(savepath))
                    {
                        Directory.CreateDirectory(savepath);
                    }
                    for (var i = 0; i < Request.Files.Count; i++)
                    {
                        HttpPostedFileBase postedFile   = Request.Files[i];
                        string             sExtension   = postedFile.FileName.Substring(postedFile.FileName.LastIndexOf('.')); //获取拓展名
                        string             fileOldName  = postedFile.FileName.Substring(0, postedFile.FileName.LastIndexOf('.'));
                        string             sNewFileName = DateTime.Now.ToString("yyyyMMdd-" + Guid.NewGuid().ToString());      //文件新名称
                        savepath = savepath + @"/" + sNewFileName + sExtension;                                                //保存路径

                        postedFile.SaveAs(savepath);

                        System.IO.FileInfo fileInfo = new System.IO.FileInfo(savepath);


                        //添加附件到数据库
                        ModSysFileAttach model = new ModSysFileAttach();
                        model.Id        = Guid.NewGuid().ToString();
                        model.NameOld   = fileOldName;
                        model.NameNew   = sNewFileName;
                        model.FilePath  = FileAttachPath + Dirc + @"/" + sNewFileName + sExtension;
                        model.FileType  = sExtension;
                        model.Extension = sExtension;

                        model.FileSize = new FileHelper().CountSize(fileInfo.Length);

                        model.Cid        = CurrentMaster.Cid;
                        model.CreaterId  = CurrentMaster.Id;
                        model.CreateTime = DateTime.Now;
                        model.Status     = (int)StatusEnum.正常;


                        model.KeyId     = Request["KeyId"].ToString();
                        model.ModelCode = Request["ModelCode"].ToString();

                        int result = new BllSysFileAttach().Insert(model);
                    }

                    //修改主表附件信息
                    switch (Request["ModelCode"].ToString())
                    {
                    case "InCome":    //收入合同
                    case "OutCome":   //支付合同
                        var temp = new BllContractInOut().LoadData(Request["KeyId"].ToString());
                        if (temp != null)
                        {
                            temp.HasFileAttach = true;
                            new BllContractInOut().Update(temp);
                        }
                        break;
                    }
                    msg.success = true;
                }
            }
            catch (Exception ex)
            {
                msg.success = false;
                msg.msg     = "上传失败," + ex.Message;
            }
            WriteJsonToPage(msg.ToString());
        }