protected ModuleErrorImageFacade(ModuleErrorImageModel model) : base(model) { }
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 { ModuleErrorImageModel errorImageModel; bool isAdd = true; if (!ModuleErrorImageBO.Instance.CheckExist("FileName", Path.GetFileName(filePath))) { errorImageModel = new ModuleErrorImageModel(); } else { errorImageModel = (ModuleErrorImageModel)ModuleErrorImageBO.Instance.FindByAttribute("FileName", Path.GetFileName(filePath))[0]; isAdd = false; } FileInfo fInfo = new FileInfo(filePath); string ftpFolderPath = "Modules\\ErrorImage\\" + ErrorModel.Code; errorImageModel.DateCreated = TextUtils.GetSystemDate(); errorImageModel.FileName = Path.GetFileName(filePath); errorImageModel.Size = fInfo.Length; errorImageModel.FilePath = ftpFolderPath + "\\" + errorImageModel.FileName; errorImageModel.ModuleErrorID = ErrorModel.ID; if (isAdd) { errorImageModel.ID = (int)pt.Insert(errorImageModel); } else { pt.Update(errorImageModel); } if (!DocUtils.CheckExits(ftpFolderPath)) { DocUtils.MakeDir(ftpFolderPath); } DocUtils.UploadFile(filePath, ftpFolderPath); pt.CommitTransaction(); } catch (Exception) { } finally { pt.CloseConnection(); } } loadGrid(); } } }
private void grvData_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { var files = (string[])e.Data.GetData(DataFormats.FileDrop); DocUtils.InitFTPTK(); using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang up file lên server!")) { foreach (string filePath in files) { ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { ModuleErrorImageModel errorImageModel; bool isAdd = true; if (!ModuleErrorImageBO.Instance.CheckExist("FileName", Path.GetFileName(filePath))) { errorImageModel = new ModuleErrorImageModel(); } else { errorImageModel = (ModuleErrorImageModel)ModuleErrorImageBO.Instance.FindByAttribute("FileName", Path.GetFileName(filePath))[0]; isAdd = false; } FileInfo fInfo = new FileInfo(filePath); string ftpFolderPath = "Modules\\ErrorImage\\" + ErrorModel.Code; errorImageModel.DateCreated = TextUtils.GetSystemDate(); errorImageModel.FileName = Path.GetFileName(filePath); errorImageModel.Size = fInfo.Length; errorImageModel.FilePath = ftpFolderPath + "\\" + errorImageModel.FileName; errorImageModel.ModuleErrorID = ErrorModel.ID; if (isAdd) { errorImageModel.ID = (int)pt.Insert(errorImageModel); } else { pt.Update(errorImageModel); } if (!DocUtils.CheckExits(ftpFolderPath)) { DocUtils.MakeDir(ftpFolderPath); } DocUtils.UploadFile(filePath, ftpFolderPath); pt.CommitTransaction(); } catch (Exception) { } finally { pt.CloseConnection(); } } } loadGrid(); } }
/// <summary> /// Thêm ảnh lỗi cho các thiết kế /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button9_Click(object sender, EventArgs e) { DocUtils.InitFTPTK(); string path = "D:/ErrorTree"; string[] listModulePath = Directory.GetDirectories(path); foreach (string modulePath in listModulePath) { string moduleCode = Path.GetFileName(modulePath); ModulesModel thisModule = (ModulesModel)ModulesBO.Instance.FindByExpression(new Expression("Code", moduleCode))[0]; string[] listErrorPath = Directory.GetDirectories(modulePath); foreach (string errorPath in listErrorPath) { string errorCode = Path.GetFileName(errorPath); DataTable dtError = TextUtils.Select("ModuleError", new Expression("Code", errorCode)); ModuleErrorModel thisError; if (dtError.Rows.Count > 0) { thisError = (ModuleErrorModel)ModuleErrorBO.Instance.FindByPK(TextUtils.ToInt(dtError.Rows[0]["ID"])); } else { thisError = new ModuleErrorModel(); thisError.ModuleID = thisModule.ID; thisError.Code = errorCode; thisError.Status = 0; thisError.Description = "Chưa khai báo"; thisError.Author = Global.AppUserName; thisError.UserID = Global.UserID; ModuleErrorBO.Instance.Insert(thisError); } foreach (string errorFilePath in Directory.GetFiles(errorPath)) { ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { FileInfo fInfo = new FileInfo(errorFilePath); ModuleErrorImageModel errorImageModel = new ModuleErrorImageModel(); errorImageModel.DateCreated = TextUtils.GetSystemDate(); errorImageModel.FileName = Path.GetFileName(errorFilePath); errorImageModel.Size = fInfo.Length; errorImageModel.FilePath = "Modules\\ErrorImage\\" + errorImageModel.FileName; errorImageModel.ModuleErrorID = thisError.ID; errorImageModel.ID = (int)pt.Insert(errorImageModel); DocUtils.UploadFile(errorFilePath, "Modules\\ErrorImage"); pt.CommitTransaction(); } catch (Exception) { } finally { pt.CloseConnection(); } } } } MessageBox.Show("OK"); }