Пример #1
0
        internal static void UpdateDocument(Model.Archive.Document document, List <System.Data.SqlClient.SqlCommand> sqlCommands)
        {
            var dc = Model.Archive.ArchiveDataClassesDataContext.GetNewInstance();

            dc.Connection.Open();
            dc.Transaction = dc.Connection.BeginTransaction();
            try
            {
                Model.Archive.Document.Copy(dc.Documents.Where(t => t.ID == document.ID).Single(), document);
                //------------
                foreach (System.Data.SqlClient.SqlCommand sqlCommand in sqlCommands)
                {
                    sqlCommand.Connection  = dc.Connection as System.Data.SqlClient.SqlConnection;
                    sqlCommand.Transaction = dc.Transaction as System.Data.SqlClient.SqlTransaction;
                    sqlCommand.ExecuteNonQuery();
                }
                dc.SubmitChanges();
                dc.Transaction.Commit();
            }
            catch (Exception ex)
            {
                dc.Transaction.Rollback();
                throw new Exception("خطا در ثبت اطلاعات" + "\r\n\r\n" + ex.Message);
            }
            finally
            {
                dc.Connection.Close();
                dc.Dispose();
            }
        }
Пример #2
0
        public ImageView(Model.Archive.Document document, string PersonnelNumber)
        {
            this._PersonnelNumber = PersonnelNumber;
            this.document         = document;
            InitializeComponent();
            this.Size = new Size(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2);
            Image img = Controller.Archive.DocumentController.GetDocumentImage(document);

            mhR_ImageView1.OpenButton = false;
            Bitmap bm = new Bitmap(img);

            mhR_ImageView1.Image           = bm;
            this.WindowState               = System.Windows.Forms.FormWindowState.Maximized;
            mhR_ImageView1.AutoSize        = true;
            mhR_ImageView1.AutoSizeMode    = AutoSizeMode.GrowOnly;
            mhR_ImageView1.PerssonelNumber = PersonnelNumber;
            //نمایش نام و نام خانوادگی
            object obj = SqlHelper.GetArchiveFieldValue("Dossier1", "Field1", PersonnelNumber);

            if (obj != null)
            {
                mhR_ImageView1.Name = obj.ToString();
                object obj2 = SqlHelper.GetArchiveFieldValue("Dossier1", "Field2", PersonnelNumber);
                if (obj2 != null)
                {
                    mhR_ImageView1.Name += " " + obj2.ToString();
                }
            }
            Setting.User.ThisProgram.AddLog(Setting.User.UserOparatesPlaceNames.لاگیری_سند_و_پرونده, Setting.User.UserOparatesNames.مشاهده_سند, PersonnelNumber, "مشاهده سند شماره:" + document.Number);
        }
Пример #3
0
        private void LoadDocument(Model.Archive.Document document)
        {
            this.document = document;
            Image  img = Controller.Archive.DocumentController.GetDocumentImage(document);
            Bitmap bm  = new Bitmap(img);

            mhR_ImageView1.Image = bm;
        }
 internal static byte[] GetDocumentData(int archiveDocumentID)
 {
     Model.Archive.Document doc = Controller.Archive.DocumentController.GetDocument(archiveDocumentID);
     using (var dc = Model.ArchiveDocument.DocumentDataClassesDataContext.GetNewInstance(doc.Dossier.FilesPathOrDatabaseName))
     {
         return(dc.Documents.Where(t => t.ArchiveDocumentID == archiveDocumentID).Single().Data.ToArray());
     }
 }
Пример #5
0
 internal static byte[] GetDocumentImageBytes(Model.Archive.Document doc)
 {
     using (var dc = Model.Archive.ArchiveDataClassesDataContext.GetNewInstance())
     {
         if (Setting.Archive.ThisProgram.LoadedArchiveSettings.UseDatabase)
         {
             string fileExtension = System.IO.Path.GetExtension(doc.FileName).ToLower();
             switch (fileExtension)
             {
             case ".bmp":
             case ".jpg":
             case ".jpeg":
             case ".png":
             case ".gif":
             case ".tif":
             case ".tiff":
                 var documentDc = Model.ArchiveDocument.DocumentDataClassesDataContext.GetNewInstance(doc.Dossier.FilesPathOrDatabaseName);
                 var query      = documentDc.Documents.Where(t => t.ArchiveDocumentID == doc.ID);
                 if (query.Count() != 1)
                 {
                     return(null);
                 }
                 return(query.Single().Data.ToArray());
             }
             return(null);
         }
         else
         {
             Njit.Common.SystemUtility sysUtil;
             sysUtil = Njit.Program.Options.GetSystemUtility(dc.Connection as SqlConnection, Setting.Program.ThisProgram.NetworkName, Setting.Program.ThisProgram.NetworkPort);
             string fileExtension = System.IO.Path.GetExtension(doc.FileName).ToLower();
             string path          = Path.Combine(doc.Dossier.FilesPathOrDatabaseName, System.IO.Path.GetFileName(doc.FileName));
             if (!sysUtil.DirectoryExists(doc.Dossier.FilesPathOrDatabaseName))
             {
                 throw new Exception("مسیر ذخیره فایل ها وجود ندارد");
             }
             if (!sysUtil.FileExists(path))
             {
                 throw new Exception("فایل سند پیدا نشد");
             }
             switch (fileExtension)
             {
             case ".bmp":
             case ".jpg":
             case ".jpeg":
             case ".png":
             case ".gif":
             case ".tif":
             case ".tiff":
                 return(sysUtil.ReadFileBytes(path));
             }
             return(null);
         }
     }
 }
Пример #6
0
 internal static void Update(Model.Archive.ArchiveDataClassesDataContext dc, Model.Archive.Document document)
 {
     try
     {
         Model.Archive.Document.Copy(dc.Documents.Where(t => t.ID == document.ID).Single(), document);
         dc.SubmitChanges();
     }
     catch (Exception ex)
     {
         throw new Exception("خطا در ثبت اطلاعات" + "\r\n\r\n" + ex.Message);
     }
 }
Пример #7
0
        internal static bool DocumentIsPdf(Model.Archive.Document doc)
        {
            string fileExtension = System.IO.Path.GetExtension(doc.FileName).ToLower();

            switch (fileExtension)
            {
            case ".pdf":
                return(true);

            default:
                return(false);
            }
        }
Пример #8
0
        internal static void Delete(Model.Archive.ArchiveDataClassesDataContext dc, int id)
        {
            Model.Archive.Document doc     = dc.Documents.Where(t => t.ID == id).Single();
            Model.Archive.Dossier  dossier = dc.Dossiers.Where(t => t.PersonnelNumber == doc.PersonnelNumber).Single();

            int childCount = dc.Documents.Where(t => t.ParentDocumentID == id).Count();

            if (childCount > 0)
            {
                throw new Exception("تعداد " + childCount.ToString() + " سند به عنوان ضمیمه به سند شماره " + doc.Index + " افزوده شده است" + "\r\n" + "برای حذف سند شماره " + doc.Index + " ابتدا باید سندهای ضمیمه را حذف کنید");
            }
            dc.Documents.DeleteOnSubmit(doc);
            dc.SubmitChanges();

            if (Setting.Archive.ThisProgram.LoadedArchiveSettings.UseDatabase)
            {
                try
                {
                    Model.ArchiveDocument.DocumentDataClassesDataContext documentsDc = Model.ArchiveDocument.DocumentDataClassesDataContext.GetNewInstance(dossier.FilesPathOrDatabaseName);
                    documentsDc.Documents.DeleteAllOnSubmit(documentsDc.Documents.Where(t => t.ArchiveDocumentID == id));
                    documentsDc.SubmitChanges();
                }
                catch (Exception ex)
                {
                    throw new Exception("خطا در حذف فایل سند شماره " + doc.Index + "\r\n" + ex.Message);
                }
            }
            else
            {
                Njit.Common.SystemUtility sysUtil;
                try
                {
                    sysUtil = Njit.Program.Options.GetSystemUtility(dc.Connection as SqlConnection, Setting.Program.ThisProgram.NetworkName, Setting.Program.ThisProgram.NetworkPort);
                }
                catch (Exception ex)
                {
                    throw new Exception("خطا در اتصال به سرور" + "\r\n" + ex.Message);
                }
                if (sysUtil.FileExists(Path.Combine(dossier.FilesPathOrDatabaseName, doc.FileName)))
                {
                    try
                    {
                        //sysUtil.DeleteFile(Path.Combine(dossier.FilesPathOrDatabaseName, doc.FileName));
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("خطا در حذف فایل سند شماره " + doc.Index + "\r\n" + ex.Message);
                    }
                }
            }
        }
Пример #9
0
 public DocumentView(Model.Archive.Document document)
 {
     InitializeComponent();
     this.document              = document;
     this.DoubleBuffered        = true;
     this.Size                  = new Size(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2);
     this.BackgroundImageLayout = ImageLayout.Stretch;
     this.BackgroundImage       = Controller.Archive.DocumentController.GetDocumentThumb(document, this.Size);
     if (this.BackgroundImage != null)
     {
         this.Size = this.BackgroundImage.Size;
     }
     this.ResizeRedraw = true;
 }
Пример #10
0
        internal static bool DocumentIsImage(Model.Archive.Document doc)
        {
            string fileExtension = System.IO.Path.GetExtension(doc.FileName).ToLower();

            switch (fileExtension)
            {
            case ".bmp":
            case ".jpg":
            case ".jpeg":
            case ".png":
            case ".gif":
            case ".tif":
            case ".tiff":
                return(true);

            default:
                return(false);
            }
        }
Пример #11
0
        public static void LoadArchiveTabDataToControls(System.Windows.Forms.Control control, Model.Archive.ArchiveTab archiveTab, Model.Archive.Document document)
        {
            if (archiveTab.IsNullOrEmpty())
            {
                return;
            }
            if (archiveTab.ArchiveFields.Count == 0)
            {
                return;
            }
            System.Data.DataTable             tempDataTable = SqlHelper.GetDocuments(archiveTab.Name, document);
            List <Model.Archive.ArchiveField> fields        = Controller.Archive.ArchiveFieldController.GetArchiveFields(archiveTab);

            foreach (Model.Archive.ArchiveField field in fields)
            {
                if (field.BoxTypeCode == (int)Enums.BoxTypes.کادر_ورود_اطلاعات_گروهی)
                {
                    System.Data.DataTable DataTableSubGroup = SqlHelper.GetDocuments(field.FieldName, document);
                    Njit.Program.Controls.DataGridViewExtended subGroupDataGridView = control.Controls[field.FieldName].Controls[field.FieldName] as Njit.Program.Controls.DataGridViewExtended;
                    subGroupDataGridView.Rows.Clear();
                    List <Model.Archive.ArchiveSubGroupField> SubGroupFields = Controller.Archive.DossierCacheController.GetSubGroupFields(field.ID);
                    foreach (System.Data.DataRow row in DataTableSubGroup.Rows)
                    {
                        subGroupDataGridView.Rows.Add();
                        int CurrentRowIndex = subGroupDataGridView.RowCount - 2;
                        foreach (Model.Archive.ArchiveSubGroupField SubGroupField in SubGroupFields)
                        {
                            subGroupDataGridView.Rows[CurrentRowIndex].Cells[SubGroupField.FieldName].Value = row[SubGroupField.FieldName].ToString();
                        }
                    }
                    subGroupDataGridView.BestFitColumns();
                }
                else if (tempDataTable.Rows.Count > 0)
                {
                    if (field.FieldName != "Field4" && field.FieldName != "Field5" && field.FieldName != "Field6")
                    {
                        control.Controls[field.FieldName].Text = tempDataTable.Rows[0][field.FieldName].ToString();
                    }
                }
            }
        }
Пример #12
0
        internal static Document AddDocument(string personnelNumber, string file, int?parentDocumentID, bool attachToDossier, Njit.Program.ComponentOne.Enums.SaveFormats imageFormat, Njit.Program.ComponentOne.Enums.CompressionTypes imageCompression, ArchiveTab archivetab)
        {
            System.IO.FileInfo fileInfo = new FileInfo(file);
            if (Setting.Archive.ThisProgram.LoadedArchiveSettings.MaxDocumentsSize > 0)
            {
                if (fileInfo.Length / 1024 > Setting.Archive.ThisProgram.LoadedArchiveSettings.MaxDocumentsSize)
                {
                    throw new Exception(string.Format("حجم فایل نباید از {0} کیلوبایت بیشتر باشد\r\nحجم این فایل {1} کیلوبایت است", Setting.Archive.ThisProgram.LoadedArchiveSettings.MaxDocumentsSize, fileInfo.Length / 1024));
                }
            }
            long   number        = Controller.Archive.DocumentController.GetNewDocumentNumber(personnelNumber);
            string fileExtension = Path.GetExtension(file).ToLower();

            Model.Archive.Dossier dossier = Controller.Archive.DossierController.Select(personnelNumber);
            if (imageExtensions.Contains(fileExtension))
            {
                switch (imageFormat)
                {
                case Njit.Program.ComponentOne.Enums.SaveFormats.None:
                    break;

                case Njit.Program.ComponentOne.Enums.SaveFormats.OnePdf:
                    if (fileExtension != ".pdf")
                    {
                        fileExtension = ".pdf";
                        string newfile = GetUniqFileName(fileExtension);
                        Image  image   = Image.FromFile(file);
                        Njit.Pdf.CreatePDF.FromImages(new Image[] { image }, newfile, 0, Njit.Pdf.CreatePDF.PageOrientation.عمودی, Njit.Pdf.CreatePDF.PageSize.OriginalSize);
                        image.Dispose();
                        file = newfile;
                    }
                    break;

                case Njit.Program.ComponentOne.Enums.SaveFormats.Pdf:
                    if (fileExtension != ".pdf")
                    {
                        fileExtension = ".pdf";
                        string newfile = GetUniqFileName(fileExtension);
                        Image  image   = Image.FromFile(file);
                        Njit.Pdf.CreatePDF.FromImages(new Image[] { image }, newfile, 0, Njit.Pdf.CreatePDF.PageOrientation.عمودی, Njit.Pdf.CreatePDF.PageSize.OriginalSize);
                        image.Dispose();
                        file = newfile;
                    }
                    break;

                case Njit.Program.ComponentOne.Enums.SaveFormats.OneMultiTiff:
                    if (fileExtension != ".tiff" && fileExtension != ".tif")
                    {
                        fileExtension = ".tiff";
                        string newfile = GetUniqFileName(fileExtension);
                        Image  image   = Image.FromFile(file);
                        Njit.Common.Helpers.ImageHelper.ConvertImage(image, System.Drawing.Imaging.ImageFormat.Tiff, GetImageCompression(imageCompression), newfile);
                        image.Dispose();
                        file = newfile;
                    }
                    break;

                case Njit.Program.ComponentOne.Enums.SaveFormats.Tiff:
                    if (fileExtension != ".tiff" && fileExtension != ".tif")
                    {
                        fileExtension = ".tiff";
                        string newfile = GetUniqFileName(fileExtension);
                        Image  image   = Image.FromFile(file);
                        Njit.Common.Helpers.ImageHelper.ConvertImage(image, System.Drawing.Imaging.ImageFormat.Tiff, GetImageCompression(imageCompression), newfile);
                        image.Dispose();
                        file = newfile;
                    }
                    break;

                case Njit.Program.ComponentOne.Enums.SaveFormats.JPEG:
                    if (fileExtension != ".jpg" && fileExtension != ".jpeg")
                    {
                        fileExtension = ".jpg";
                        string newfile = GetUniqFileName(fileExtension);
                        Image  image   = Image.FromFile(file);
                        Njit.Common.Helpers.ImageHelper.ConvertImage(image, System.Drawing.Imaging.ImageFormat.Jpeg, GetImageCompression(imageCompression), newfile);
                        image.Dispose();
                        file = newfile;
                    }
                    break;

                case Njit.Program.ComponentOne.Enums.SaveFormats.PNG:
                    if (fileExtension != ".png")
                    {
                        fileExtension = ".png";
                        string newfile = GetUniqFileName(fileExtension);
                        Image  image   = Image.FromFile(file);
                        Njit.Common.Helpers.ImageHelper.ConvertImage(image, System.Drawing.Imaging.ImageFormat.Png, GetImageCompression(imageCompression), newfile);
                        image.Dispose();
                        file = newfile;
                    }
                    break;

                case Njit.Program.ComponentOne.Enums.SaveFormats.BMP:
                    if (fileExtension != ".bmp")
                    {
                        fileExtension = ".bmp";
                        string newfile = GetUniqFileName(fileExtension);
                        Image  image   = Image.FromFile(file);
                        Njit.Common.Helpers.ImageHelper.ConvertImage(image, System.Drawing.Imaging.ImageFormat.Bmp, GetImageCompression(imageCompression), newfile);
                        image.Dispose();
                        file = newfile;
                    }
                    break;

                default:
                    throw new Exception();
                }
            }
            string fileNameToSaveInDatabase = Njit.Common.PublicMethods.ReplaceInvalidPathAndFileNameChars(personnelNumber, "-") + "-" + number.ToString() + fileExtension;
            string destinationFile          = null;

            if (Setting.Archive.ThisProgram.LoadedArchiveSettings.UseDatabase == false)
            {
                destinationFile = Path.Combine(dossier.FilesPathOrDatabaseName, fileNameToSaveInDatabase);
                Njit.Common.SystemUtility sysUtility = Njit.Program.Options.GetSystemUtility(DataAccess.ArchiveDataAccess.GetNewInstance().Connection, Setting.Program.ThisProgram.NetworkName, Setting.Program.ThisProgram.NetworkPort);
                int i = 1;
                while (sysUtility.FileExists(destinationFile))
                {
                    fileNameToSaveInDatabase = Njit.Common.PublicMethods.ReplaceInvalidPathAndFileNameChars(personnelNumber, "-") + "-" + number.ToString() + " (" + i.ToString() + ")" + fileExtension;
                    destinationFile          = Path.Combine(dossier.FilesPathOrDatabaseName, fileNameToSaveInDatabase);
                    i++;
                }
            }

            Model.Archive.Document document = Model.Archive.Document.GetNewInstance(personnelNumber, number.ToString(), fileNameToSaveInDatabase, archivetab.ID, attachToDossier, parentDocumentID, Controller.Archive.DocumentController.GetMaxDocumentIndex(personnelNumber) + 1);

            var archiveDc = Model.Archive.ArchiveDataClassesDataContext.GetNewInstance();

            Model.ArchiveDocument.DocumentDataClassesDataContext documentDc = null;
            if (Setting.Archive.ThisProgram.LoadedArchiveSettings.UseDatabase)
            {
                documentDc = Model.ArchiveDocument.DocumentDataClassesDataContext.GetNewInstance(Setting.Archive.ThisProgram.LoadedArchiveSettings.DocumentsPathOrDatabaseName);
            }

            archiveDc.Connection.Open();
            archiveDc.Transaction = archiveDc.Connection.BeginTransaction();
            if (documentDc != null)
            {
                documentDc.Connection.Open();
                documentDc.Transaction = documentDc.Connection.BeginTransaction();
            }
            try
            {
                archiveDc.Documents.InsertOnSubmit(document);
                archiveDc.SubmitChanges();
                archiveDc.Transaction.Commit();
                if (documentDc != null)
                {
                    Model.ArchiveDocument.Document doc = Model.ArchiveDocument.Document.GetNewInstance(document.ID, new System.Data.Linq.Binary(System.IO.File.ReadAllBytes(file)));
                    documentDc.Documents.InsertOnSubmit(doc);
                    documentDc.SubmitChanges();
                    documentDc.Transaction.Commit();
                }
            }
            catch (Exception ex)
            {
                archiveDc.Transaction.Rollback();
                if (documentDc != null)
                {
                    documentDc.Transaction.Rollback();
                }
                throw new Exception("خطا در ثبت اطلاعات" + "\r\n\r\n" + ex.Message);
            }
            finally
            {
                archiveDc.Connection.Close();
                if (documentDc != null)
                {
                    documentDc.Connection.Close();
                }
            }
            if (Setting.Archive.ThisProgram.LoadedArchiveSettings.UseDatabase == false)
            {
                FileStream serverFileStream = null;
                FileStream clientFileStream = null;
                try
                {
                    Njit.Common.SystemUtility sysUtility = Njit.Program.Options.GetSystemUtility(DataAccess.ArchiveDataAccess.GetNewInstance().Connection, Setting.Program.ThisProgram.NetworkName, Setting.Program.ThisProgram.NetworkPort);
                    if (!sysUtility.DirectoryExists(dossier.FilesPathOrDatabaseName))
                    {
                        sysUtility.CreateDirectory(dossier.FilesPathOrDatabaseName);
                    }
                    serverFileStream = sysUtility.CreateFile(destinationFile);
                    clientFileStream = File.OpenRead(file);
                    byte[] buffre    = new byte[1 * 1024 * 1024];
                    int    readCount = 0;
                    do
                    {
                        readCount = clientFileStream.Read(buffre, 0, buffre.Length);
                        serverFileStream.Write(buffre, 0, readCount);
                    }while (readCount > 0);
                    clientFileStream.Close();
                    serverFileStream.Close();
                    clientFileStream.Dispose();
                    serverFileStream.Dispose();
                }
                catch (Exception ex)
                {
                    if (clientFileStream != null)
                    {
                        clientFileStream.Dispose();
                    }
                    if (serverFileStream != null)
                    {
                        serverFileStream.Dispose();
                    }
                    throw new Exception("خطا در ذخیره فایل" + "\r\n" + file + "\r\n\r\n" + ex.Message);
                }
            }
            return(document);
        }
Пример #13
0
        internal static Image GetDocumentImage(Model.Archive.Document doc)
        {
            var dc = Model.Archive.ArchiveDataClassesDataContext.GetNewInstance();

            if (Setting.Archive.ThisProgram.LoadedArchiveSettings.UseDatabase)
            {
                try
                {
                    string fileExtension = System.IO.Path.GetExtension(doc.FileName).ToLower();
                    switch (fileExtension)
                    {
                    case ".bmp":
                    case ".jpg":
                    case ".jpeg":
                    case ".png":
                    case ".gif":
                    case ".tif":
                    case ".tiff":
                        var documentDc = Model.ArchiveDocument.DocumentDataClassesDataContext.GetNewInstance(doc.Dossier.FilesPathOrDatabaseName);
                        var query      = documentDc.Documents.Where(t => t.ArchiveDocumentID == doc.ID);
                        if (query.Count() != 1)
                        {
                            return(null);
                        }
                        MemoryStream ms  = new MemoryStream(query.Single().Data.ToArray());
                        Image        img = Image.FromStream(ms);
                        documentDc.Dispose();
                        return(img);
                    }
                    Njit.Common.RegisteredFileType.EmbeddedIconInfo _EmbeddedIconInfo = Njit.Common.RegisteredFileType.GetExtensionDefaultIcon(fileExtension);
                    if (_EmbeddedIconInfo == null)
                    {
                        return(null);
                    }
                    Icon icon = Njit.Common.RegisteredFileType.ExtractIconFromFile(_EmbeddedIconInfo, true);
                    if (icon == null)
                    {
                        return(null);
                    }
                    return((icon).ToBitmap());
                }
                catch (Exception ex)
                {
                    return(Njit.Common.Helpers.GraphicsHelper.GetErrorImage("خطا در دریافت تصویر" + "\r\n" + ex.Message, Setting.User.ThisProgram.LoadedUserSetting.ArchiveDocumentsZoom, Setting.User.ThisProgram.LoadedUserSetting.ArchiveDocumentsZoom));
                }
            }
            else
            {
                Njit.Common.SystemUtility sysUtil;
                try
                {
                    sysUtil = Njit.Program.Options.GetSystemUtility(dc.Connection as SqlConnection, Setting.Program.ThisProgram.NetworkName, Setting.Program.ThisProgram.NetworkPort);
                }
                catch (Exception ex)
                {
                    return(Njit.Common.Helpers.GraphicsHelper.GetErrorImage("خطا در دریافت تصویر" + "\r\n" + ex.Message, Setting.User.ThisProgram.LoadedUserSetting.ArchiveDocumentsZoom, Setting.User.ThisProgram.LoadedUserSetting.ArchiveDocumentsZoom));
                }
                string fileExtension = System.IO.Path.GetExtension(doc.FileName).ToLower();
                string path          = Path.Combine(doc.Dossier.FilesPathOrDatabaseName, System.IO.Path.GetFileName(doc.FileName));
                if (!sysUtil.DirectoryExists(doc.Dossier.FilesPathOrDatabaseName))
                {
                    return(Njit.Common.Helpers.GraphicsHelper.GetErrorImage("مسیر ذخیره فایل ها وجود ندارد", Setting.User.ThisProgram.LoadedUserSetting.ArchiveDocumentsZoom, Setting.User.ThisProgram.LoadedUserSetting.ArchiveDocumentsZoom));
                }
                if (!sysUtil.FileExists(path))
                {
                    return(Njit.Common.Helpers.GraphicsHelper.GetErrorImage("فایل سند پیدا نشد", Setting.User.ThisProgram.LoadedUserSetting.ArchiveDocumentsZoom, Setting.User.ThisProgram.LoadedUserSetting.ArchiveDocumentsZoom));
                }
                switch (fileExtension)
                {
                case ".bmp":
                case ".jpg":
                case ".jpeg":
                case ".png":
                case ".gif":
                case ".tif":
                case ".tiff":
                    System.IO.FileStream fileStream = null;
                    System.Drawing.Image img        = null;
                    try
                    {
                        fileStream = sysUtil.OpenFile(path);
                        img        = Image.FromStream(fileStream);
                    }
                    catch (Exception ex)
                    {
                        if (img != null)
                        {
                            img.Dispose();
                        }
                        if (fileStream != null)
                        {
                            fileStream.Dispose();
                        }
                        return(Njit.Common.Helpers.GraphicsHelper.GetErrorImage("خطا در دریافت تصویر" + "\r\n" + ex.Message, Setting.User.ThisProgram.LoadedUserSetting.ArchiveDocumentsZoom, Setting.User.ThisProgram.LoadedUserSetting.ArchiveDocumentsZoom));
                    }
                    return(img);
                }
                Icon icon = sysUtil.GetFileIcon(path);
                if (icon == null)
                {
                    return(null);
                }
                return(icon.ToBitmap());
            }
        }
Пример #14
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (Validation())
            {
                if (!Setting.User.ThisProgram.CheckUserAccessPermission(Setting.User.AccessPermissionUnits.Archive, cmArchive.SelectedValue.ToString()))
                {
                    PersianMessageBox.Show(this, string.Format("مجوز دسترسی به بایگانی '{0}' برای شما صادر نشده است", cmArchive.SelectedText));
                    return;
                }
                int thisArchive = Setting.Archive.ThisProgram.SelectedArchiveTree.Archive.ID;
                //نام و نام خانوادگی و کد ملی به همراه تمام اسناد آنرا کپی می کنیم
                string Name = "", Family = "", NN = "";
                Model.Archive.Dossier Dossier1 = Controller.Archive.DossierController.Get(txtDossier1.Text);
                if (Dossier1 != null)
                {
                    object obj = SqlHelper.GetArchiveFieldValue("Dossier1", "Field1", this.txtDossier1.Text);
                    if (obj != null)
                    {
                        Name = obj.ToString();
                        object obj2 = SqlHelper.GetArchiveFieldValue("Dossier1", "Field2", txtDossier1.Text);
                        if (obj2 != null)
                        {
                            Family = obj2.ToString();
                        }
                    }
                    //کد ملی
                    object obj3 = SqlHelper.GetArchiveFieldValue("Dossier1", "Field15", this.txtDossier1.Text);
                    if (obj3 != null)
                    {
                        NN = obj3.ToString();
                    }
                    //لیست اسناد
                    List <Model.Archive.Document> listdoc = Controller.Archive.DocumentController.GetDocuments(txtDossier1.Text).ToList();

                    //رفتن به بایگانی انتخابی
                    Setting.Archive.ThisProgram.SelectedArchiveTree.Archive = Controller.Common.ArchiveController.GetActiveArchives().Where(q => q.ID.ToString() == cmArchive.SelectedValue.ToString()).FirstOrDefault();

                    try
                    {
                        Model.Archive.Dossier dossier = new Model.Archive.Dossier();
                        dossier.PersonnelNumber         = txtDossier2.Text;
                        dossier.PersonnelImage          = Dossier1.PersonnelImage;
                        dossier.FilesPathOrDatabaseName = Dossier1.FilesPathOrDatabaseName;
                        dossier.DossierSecurityID       = Dossier1.DossierSecurityID;
                        //اضافه کردن سند جدید
                        Model.Archive.ArchiveDataClassesDataContext dc = Model.Archive.ArchiveDataClassesDataContext.GetNewInstance();
                        dc.Connection.Open();
                        dc.Transaction = dc.Connection.BeginTransaction();
                        try
                        {
                            Controller.Archive.DossierController.Insret(dossier, dc);
                            //------------

                            try
                            {
                                Setting.User.ThisProgram.AddLog(Setting.User.UserOparatesPlaceNames.پرونده, Setting.User.UserOparatesNames.ویرایش, null, "ویرایش پرونده با " + Setting.Archive.ThisProgram.LoadedArchiveSettings.PersonnelNumber_Label + " " + txtDossier2.Text);
                            }
                            catch
                            {
                                throw new Exception("خطا در ذخیره عملکرد کاربر جاری");
                            }
                            dc.Transaction.Commit();
                        }
                        catch (Exception ex)
                        {
                            dc.Transaction.Rollback();
                            throw new Exception(ex.Message);
                        }
                        finally
                        {
                            dc.Connection.Close();
                        }
                        //اضافه کردن نام  نام خانوادگی و کد ملی
                        SqlHelper.InsertDossier1(txtDossier2.Text, Name, Family, NN);
                        //اضافه کردن سند ها به پرونده جدید

                        foreach (var item in listdoc)
                        {
                            Model.Archive.Document document = item;
                            try
                            {
                                string file;
                                if (Setting.Archive.ThisProgram.LoadedArchiveSettings.UseDatabase)
                                {
                                    string tempPath = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "~Mahba");
                                    if (!System.IO.Directory.Exists(tempPath))
                                    {
                                        System.IO.Directory.CreateDirectory(tempPath);
                                    }
                                    file = System.IO.Path.Combine(tempPath, System.IO.Path.GetFileName(document.FileName));
                                    System.IO.File.WriteAllBytes(file, Controller.ArchiveDocument.ArchiveDocumentController.GetDocumentData(document.ID));
                                }
                                else
                                {
                                    file = System.IO.Path.Combine(document.Dossier.FilesPathOrDatabaseName, document.FileName);
                                }
                                Model.Archive.ArchiveTab archiveTab = Controller.Archive.ArchiveTabController.GetName("Document2");
                                Controller.Archive.DocumentController.AddDocument(txtDossier2.Text, file, null, false, (Njit.Program.ComponentOne.Enums.SaveFormats)(Setting.Archive.ThisProgram.LoadedArchiveSettings.DefaultImageFormatCode ?? ((int)Njit.Program.ComponentOne.Enums.SaveFormats.None)), (Njit.Program.ComponentOne.Enums.CompressionTypes)(Setting.Archive.ThisProgram.LoadedArchiveSettings.DefaultCompressionTypeCode ?? ((int)Njit.Program.ComponentOne.Enums.CompressionTypes.None)), archiveTab);

                                Setting.User.ThisProgram.AddLog(Setting.User.UserOparatesPlaceNames.لاگیری_سند_و_پرونده, Setting.User.UserOparatesNames.کپی_سند, txtDossier2.Text, "کپی سند شماره:" + document.Number);
                            }
                            catch (Exception ex)
                            {
                                PersianMessageBox.Show(this, "خطا در کپی سند شماره " + document.Number + "\r\n\r\n" + ex.Message);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Setting.Archive.ThisProgram.SelectedArchiveTree.Archive = Controller.Common.ArchiveController.GetActiveArchives().Where(q => q.ID == thisArchive).FirstOrDefault();
                        MessageBox.Show(ex.Message);
                    }
                }
                //برگشت به بایگانی اولیه
                Setting.Archive.ThisProgram.SelectedArchiveTree.Archive = Controller.Common.ArchiveController.GetActiveArchives().Where(q => q.ID == thisArchive).FirstOrDefault();
                MessageBox.Show("پرونده با موفقیت انتقال پیدا کرد.");
            }
        }
Пример #15
0
 internal static System.Drawing.Image GetDocumentThumb(Model.Archive.Document doc)
 {
     return(GetDocumentThumb(doc, new Size(Setting.User.ThisProgram.LoadedUserSetting.ArchiveDocumentsZoom, Setting.User.ThisProgram.LoadedUserSetting.ArchiveDocumentsZoom)));
 }
Пример #16
0
        public override void DrawItem(Graphics g, ImageListViewItem item, ItemState state, Rectangle bounds)
        {
            if (ImageListView.View == Njit.ImageListView.View.Details)
            {
                base.DrawItem(g, item, state, bounds);
            }
            else
            {
                Size itemPadding = new Size(4, 4);
                using (Brush backColorBrush = new SolidBrush(item.BackColor))
                    g.FillRectangle(backColorBrush, bounds);
                if ((ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None)) || (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None) && ((state & ItemState.Hovered) != ItemState.None)))
                {
                    using (Brush bSelected = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.Highlight), Color.FromArgb(64, SystemColors.Highlight), LinearGradientMode.Vertical))
                        Utility.FillRoundedRectangle(g, bSelected, bounds, 4);
                }
                else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                {
                    using (Brush bGray64 = new LinearGradientBrush(bounds, Color.FromArgb(16, SystemColors.GrayText), Color.FromArgb(64, SystemColors.GrayText), LinearGradientMode.Vertical))
                        Utility.FillRoundedRectangle(g, bGray64, bounds, 4);
                }
                if ((state & ItemState.Hovered) != ItemState.None)
                {
                    using (Brush bHovered = new LinearGradientBrush(bounds, Color.FromArgb(8, SystemColors.Highlight), Color.FromArgb(32, SystemColors.Highlight), LinearGradientMode.Vertical))
                        Utility.FillRoundedRectangle(g, bHovered, bounds, 4);
                }

                Model.Archive.Document document = item.VirtualItemKey as Model.Archive.Document;

                Image img = item.ThumbnailImage;
                if (img != null)
                {
                    Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize));
                    if (!object.ReferenceEquals(img, this.ImageListView.DefaultImage) && document != null && Controller.Archive.DocumentController.GetChildDocumentsCount(document.ID) > 0)
                    {
                        pos.Width  -= 9;
                        pos.Height -= 9;

                        g.DrawImage(img, pos);
                        DrawImageBorder(g, pos);

                        g.DrawImage(img, pos.X += 3, pos.Y += 3, pos.Width, pos.Height);
                        DrawImageBorder(g, pos);

                        g.DrawImage(img, pos.X += 3, pos.Y += 3, pos.Width, pos.Height);
                        DrawImageBorder(g, pos);

                        g.DrawImage(img, pos.X += 3, pos.Y += 3, pos.Width, pos.Height);
                        DrawImageBorder(g, pos);
                    }
                    else
                    {
                        try
                        {
                            g.DrawImage(img, pos);
                            DrawImageBorder(g, pos);
                        }
                        catch { }
                    }
                }

                if (document != null)
                {
                    if (document.AttachedToDossier || document.ParentDocumentID.HasValue)
                    {
                        Rectangle pos = new Rectangle(bounds.Location + itemPadding, Properties.Resources.Paperclip.Size);
                        g.DrawImage(Properties.Resources.Paperclip, pos);
                    }
                }

                // Draw item text
                SizeF      textSize = System.Windows.Forms.TextRenderer.MeasureText(item.Text, ImageListView.Font);
                RectangleF textRectangle;
                using (StringFormat sf = new StringFormat())
                {
                    textRectangle    = new RectangleF(bounds.Left + itemPadding.Width, bounds.Top + 2 * itemPadding.Height + ImageListView.ThumbnailSize.Height, ImageListView.ThumbnailSize.Width, textSize.Height);
                    sf.Alignment     = StringAlignment.Center;
                    sf.FormatFlags   = StringFormatFlags.NoWrap;
                    sf.LineAlignment = StringAlignment.Center;
                    sf.Trimming      = StringTrimming.EllipsisCharacter;
                    if (ImageListView.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
                    {
                        sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                    }
                    using (Brush foreColorBrush = new SolidBrush(item.ForeColor))
                        g.DrawString(item.Text, ImageListView.Font, foreColorBrush, textRectangle, sf);
                }
                if (!string.IsNullOrEmpty(item.Caption))
                {
                    using (StringFormat sf = new StringFormat())
                    {
                        textRectangle    = new RectangleF(bounds.Left + itemPadding.Width, bounds.Top + itemPadding.Height, ImageListView.ThumbnailSize.Width, textSize.Height);
                        sf.Alignment     = StringAlignment.Center;
                        sf.FormatFlags   = StringFormatFlags.NoWrap;
                        sf.LineAlignment = StringAlignment.Center;
                        sf.Trimming      = StringTrimming.EllipsisCharacter;
                        if (ImageListView.RightToLeft == System.Windows.Forms.RightToLeft.Yes)
                        {
                            sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                        }
                        using (Brush foreColorBrush = new SolidBrush(item.ForeColor))
                            g.DrawString(item.Caption, ImageListView.Font, foreColorBrush, textRectangle, sf);
                    }
                }

                // Item border
                using (Pen pWhite128 = new Pen(Color.FromArgb(128, Color.White)))
                    Utility.DrawRoundedRectangle(g, pWhite128, bounds.Left + 1, bounds.Top + 1, bounds.Width - 3, bounds.Height - 3, 4);
                if (ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                {
                    using (Pen pHighlight128 = new Pen(Color.FromArgb(128, SystemColors.Highlight)))
                        Utility.DrawRoundedRectangle(g, pHighlight128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                }
                else if (!ImageListView.Focused && ((state & ItemState.Selected) != ItemState.None))
                {
                    using (Pen pGray128 = new Pen(Color.FromArgb(128, SystemColors.GrayText)))
                        Utility.DrawRoundedRectangle(g, pGray128, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                }
                else if (ImageListView.View == Njit.ImageListView.View.Thumbnails && (state & ItemState.Selected) == ItemState.None)
                {
                    using (Pen pGray64 = new Pen(Color.FromArgb(64, SystemColors.GrayText)))
                        Utility.DrawRoundedRectangle(g, pGray64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                }

                if (ImageListView.Focused && ((state & ItemState.Hovered) != ItemState.None))
                {
                    using (Pen pHighlight64 = new Pen(Color.FromArgb(64, SystemColors.Highlight)))
                        Utility.DrawRoundedRectangle(g, pHighlight64, bounds.Left, bounds.Top, bounds.Width - 1, bounds.Height - 1, 4);
                }

                if (ImageListView.Focused && ((state & ItemState.Focused) != ItemState.None))
                {
                    System.Windows.Forms.ControlPaint.DrawFocusRectangle(g, bounds);
                }
            }
        }
Пример #17
0
        internal static string CopyDocumentToTempPath(Model.Archive.Document doc)
        {
            string tempPath = Path.Combine(Path.GetTempPath(), "~Mahba");

            if (!System.IO.Directory.Exists(tempPath))
            {
                System.IO.Directory.CreateDirectory(tempPath);
            }
            string tempFile = Path.Combine(tempPath, System.IO.Path.GetFileName(doc.FileName));

            using (var dc = Model.Archive.ArchiveDataClassesDataContext.GetNewInstance())
            {
                if (Setting.Archive.ThisProgram.LoadedArchiveSettings.UseDatabase)
                {
                    try
                    {
                        var documentDc = Model.ArchiveDocument.DocumentDataClassesDataContext.GetNewInstance(doc.Dossier.FilesPathOrDatabaseName);
                        var query      = documentDc.Documents.Where(t => t.ArchiveDocumentID == doc.ID);
                        if (query.Count() != 1)
                        {
                            throw new Exception("فایل سند در پایگاه داده موجود نیست");
                        }
                        System.IO.File.WriteAllBytes(tempFile, query.Single().Data.ToArray());
                        documentDc.Dispose();
                        return(tempFile);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("خطا در دریافت فایل از پایگاه داده" + "\r\n" + ex.Message);
                    }
                }
                else
                {
                    Njit.Common.SystemUtility sysUtil;
                    try
                    {
                        sysUtil = Njit.Program.Options.GetSystemUtility(dc.Connection as SqlConnection, Setting.Program.ThisProgram.NetworkName, Setting.Program.ThisProgram.NetworkPort);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("خطا در اتصال به سرور" + "\r\n" + ex.Message);
                    }
                    string path = Path.Combine(doc.Dossier.FilesPathOrDatabaseName, System.IO.Path.GetFileName(doc.FileName));
                    if (!sysUtil.DirectoryExists(doc.Dossier.FilesPathOrDatabaseName))
                    {
                        throw new Exception("مسیر ذخیره فایل ها وجود ندارد");
                    }
                    if (!sysUtil.FileExists(path))
                    {
                        throw new Exception("فایل سند پیدا نشد");
                    }
                    System.IO.FileStream fileStream = null;
                    try
                    {
                        fileStream = sysUtil.OpenFile(path);
                    }
                    catch (Exception ex)
                    {
                        if (fileStream != null)
                        {
                            fileStream.Dispose();
                        }
                        throw new Exception("خطا در بازکردن فایل" + "\r\n" + ex.Message);
                    }
                    System.IO.FileStream newFileStream = null;
                    try
                    {
                        newFileStream = new FileStream(tempFile, FileMode.Create);
                        int    readCount = 0;
                        byte[] buffer    = new byte[32768];
                        do
                        {
                            readCount = fileStream.Read(buffer, 0, buffer.Length);
                            newFileStream.Write(buffer, 0, readCount);
                        }while (readCount > 0);
                        fileStream.Close();
                        newFileStream.Flush();
                        newFileStream.Close();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("خطا در ذخیره فایل" + "\r\n" + ex.Message);
                    }
                    finally
                    {
                        if (fileStream != null)
                        {
                            fileStream.Dispose();
                        }
                        if (newFileStream != null)
                        {
                            newFileStream.Dispose();
                        }
                    }
                    return(tempFile);
                }
            }
        }