예제 #1
0
        void addFile(bool allFile)
        {
            DocUtils.InitFTPTK();
            OpenFileDialog ofd = new OpenFileDialog();

            if (!allFile)
            {
                ofd.Filter = "Image files (*.jpg, *.jpeg, *.png,*.gif) | *.jpg; *.jpeg; *.png; *.gif";
            }
            ofd.Multiselect = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang up file lên server!"))
                {
                    foreach (string filePath in ofd.FileNames)
                    {
                        ProcessTransaction pt = new ProcessTransaction();
                        pt.OpenConnection();
                        pt.BeginTransaction();
                        try
                        {
                            ProjectProblemImageModel problemImageModel;
                            bool isAdd = true;
                            if (!ProjectProblemImageBO.Instance.CheckExist("FileName", Path.GetFileName(filePath)))
                            {
                                problemImageModel = new ProjectProblemImageModel();
                            }
                            else
                            {
                                problemImageModel = (ProjectProblemImageModel)ProjectProblemImageBO.Instance.FindByAttribute("FileName", Path.GetFileName(filePath))[0];
                                isAdd             = false;
                            }

                            FileInfo fInfo = new FileInfo(filePath);

                            string ftpFolderPath = "ProjectProblem\\" + ProjectProblem.ID;

                            problemImageModel.DateCreated      = TextUtils.GetSystemDate();
                            problemImageModel.FileName         = Path.GetFileName(filePath);
                            problemImageModel.Size             = fInfo.Length;
                            problemImageModel.FilePath         = ftpFolderPath + "\\" + problemImageModel.FileName;
                            problemImageModel.ProjectProblemID = ProjectProblem.ID;

                            if (isAdd)
                            {
                                problemImageModel.ID = (int)pt.Insert(problemImageModel);
                            }
                            else
                            {
                                pt.Update(problemImageModel);
                            }

                            if (!DocUtils.CheckExits(ftpFolderPath))
                            {
                                DocUtils.MakeDir(ftpFolderPath);
                            }
                            DocUtils.UploadFile(filePath, ftpFolderPath);

                            pt.CommitTransaction();
                        }
                        catch (Exception)
                        {
                        }
                        finally
                        {
                            pt.CloseConnection();
                        }
                    }

                    loadImage();
                }
            }
        }
예제 #2
0
 protected ProjectProblemImageFacade(ProjectProblemImageModel model) : base(model)
 {
 }