Beispiel #1
0
 //ɾ������
 protected void DeleteAttach()
 {
     string[] strArray = AttachItemID.Value.Split(',');
     LabMS.BLL.AttachmentItem attIte = new LabMS.BLL.AttachmentItem();
     if (AttachItemID.Value!="")
     {
         for (int i = 0; i < strArray.Length; i++)
         {
             attIte.Delete(int.Parse(strArray[i]));
         }
     }
 }
        protected bool AttachmentItemSave(LabMS.Model.OpentProject openprojectmodel)
        {
            if (openprojectmodel != null)
            {
                int Attach_ID = 0;
                if (openprojectmodel.Attachment != null)
                {
                    Attach_ID = openprojectmodel.Attachment.Value;
                    string[] array = itemIDs.Value.Split(',');
                    if (array[0] != "")
                    {
                        for (int n = 0; n < array.Length; n++)
                        {
                            if (array[n] != "0")
                            {
                                LabMS.BLL.AttachmentItem Attach = new LabMS.BLL.AttachmentItem();
                                int itemID = 0;
                                if (int.TryParse(array[n], out itemID))
                                {
                                    try
                                    {
                                        Attach.Delete(itemID);
                                    }
                                    catch
                                    {

                                    }
                                }
                            }
                        }
                    }
                }
                else
                {

                    ///有上传文件
                    if (HttpContext.Current.Request.Files.Count - 1 > 0)
                    {
                        LabMS.BLL.Attachment Attach = new LabMS.BLL.Attachment();
                        LabMS.Model.Attachment attamentmodel = new LabMS.Model.Attachment();
                        LabMS.BLL.OpentProject OpenProject = new LabMS.BLL.OpentProject();
                        try
                        {
                            Attach_ID = Attach.Add(attamentmodel);
                            openprojectmodel.Attachment = Attach_ID;
                            OpenProject.Update(openprojectmodel);

                        }
                        catch
                        {
                            lb_Error.Text = "保存上传文件错误";
                        }
                    }

                }
                if (Attach_ID != 0)
                {
                    return SaveItem(Attach_ID);
                }
                else
                {
                    return false;
                }

            }
            return false;
        }
Beispiel #3
0
        protected bool SaveItem(LabMS.Model.ProjectApp applicationmodel)
        {
            bool save = false;
            if (applicationmodel != null)
            {
                int Attach_ID = 0;
                if (applicationmodel.App_Attachment == null)
                {
                    if (HttpContext.Current.Request.Files.Count - 1 > 0)
                    {
                        LabMS.Model.Attachment attachmodel = new LabMS.Model.Attachment();
                        LabMS.BLL.Attachment Attach = new LabMS.BLL.Attachment();
                        applicationmodel.App_Attachment = Attach.Add(attachmodel);
                    }
                }
                else
                {
                    Attach_ID = applicationmodel.App_Attachment.Value;
                }

                if (Attach_ID != 0)
                {
                    //ɾ��
                    try
                    {
                        LabMS.BLL.AttachmentItem AttachItem = new LabMS.BLL.AttachmentItem();
                        List<LabMS.Model.AttachmentItem> ls = new List<LabMS.Model.AttachmentItem>();
                        ls = AttachItem.GetModelList("Item_Type='1' and  Attach_ID=" + Attach_ID);
                        string[] array1 = itemIDs.Value.Split(',');
                        if (array1[0] != "")
                        {
                            for (int i = 0; i < array1.Length; i++)
                            {
                                int itemid = 0;
                                if (int.TryParse(array1[i], out itemid))
                                {
                                    AttachItem.Delete(itemid);
                                }
                            }
                        }
                    }
                    catch(Exception ex)
                    {
                        lb_Error.Text = ex.Message;
                    }
                    //���

                    if (HttpContext.Current.Request.Files.Count-1 > 0)
                    {
                        try
                        {
                            LabMS.BLL.AttachmentItem AttachItem = new LabMS.BLL.AttachmentItem();
                            LabMS.Model.AttachmentItem itemmodel;
                            HttpFileCollection Files = HttpContext.Current.Request.Files;
                            string savePath = Request.MapPath(@"../Content/UpLoadFile/");
                            List<string> fileNames = LabMS.Common.FileUpload.SaveFiles(Files, savePath);

                            for (int n = 0; n < fileNames.Count; n++)
                            {
                                itemmodel = new LabMS.Model.AttachmentItem();
                                itemmodel.Item_Address = "Content/UpLoadFile/" + fileNames[n].Trim();
                                int index = fileNames[n].LastIndexOf("_");
                                itemmodel.Item_Name = fileNames[n].Substring(0, fileNames[n].LastIndexOf("_"));
                                itemmodel.Attach_ID = Attach_ID;
                                itemmodel.Item_Type = "1";
                                AttachItem.Add(itemmodel);
                            }
                            save = true;
                        }
                        catch
                        {
                            save = false;
                        }
                    }
                }

            }

            return save;
        }
Beispiel #4
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(itemIDs.Value))
            {
                string[] array1 = itemIDs.Value.Split(',');
                for (int m = 0; m < array1.Length; m++)
                {
                    if (array1[m] != "0"||array1[m]!="")
                    {
                        LabMS.BLL.AttachmentItem AttachItem = new LabMS.BLL.AttachmentItem();
                        AttachItem.Delete(Convert.ToInt32(array1[m]));
                    }
                }
            }
            int attachID = 0;
            if ((HttpContext.Current.Request.Files.Count - 1) > 0)
            {
                bool Result = false;
                try
                {
                    LabMS.BLL.ProjectApp Application = new LabMS.BLL.ProjectApp();
                    LabMS.Model.ProjectApp model = new LabMS.Model.ProjectApp();
                    model = Application.GetModel(QueryString);
                    if (model.App_Attachment == null)
                    {
                        attachID = 0;
                    }
                    else
                    {
                        attachID = model.App_Attachment.Value;
                    }

                    int count = HttpContext.Current.Request.Files.Count;
                    HttpFileCollection Files = HttpContext.Current.Request.Files;
                    string savePath = HttpContext.Current.Request.MapPath(@"../Content/UpLoadFile/");
                    List<string> fileNames = LabMS.Common.FileUpload.SaveFiles(Files, savePath);

                    if (attachID == 0)
                    {
                        LabMS.BLL.Attachment Attach = new LabMS.BLL.Attachment();
                        LabMS.Model.Attachment attachmodel = new LabMS.Model.Attachment();
                        attachID = Attach.Add(attachmodel);
                        model.App_Attachment = attachID;

                    }

                    LabMS.BLL.AttachmentItem AttachItem = new LabMS.BLL.AttachmentItem();
                    LabMS.Model.AttachmentItem itemmodel;

                    for (int n = 0; n < fileNames.Count; n++)
                    {
                        if (fileNames[n].Trim() != "")
                        {
                            itemmodel = new LabMS.Model.AttachmentItem();
                            itemmodel.Item_Address = "Content/UpLoadFile/" + fileNames[n].Trim();
                            itemmodel.Item_Name = fileNames[n].Substring(0, fileNames[n].LastIndexOf("_"));
                            itemmodel.Attach_ID = attachID;
                            itemmodel.Item_Type = "2";
                            AttachItem.Add(itemmodel);
                        }
                    }
                    Result = true;

                    Application.Update(model);
                }
                catch
                {
                    Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('�ϴ��ļ�ʱ��������ϵ����Ա��');window.location.href=window.location.href; </script>");
                    return;
                }

                if (Result)
                {
                    Build.Visible = true;
                }
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>alert('û�������飬��ѡ����������ϴ���'); </script>");
                return;
            }
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "script", "<script type='text/javascript'>if(window.confirm('���������ɹ����Ƿ񷵻��б�')){ window.location.href='AppTaskList.aspx';}else{window.location.href=window.location.href;}</script>");
            return;
        }