Example #1
0
        /// <summary>
        /// Справочник единиц измерений(догвора)
        /// </summary>
        /// <returns></returns>
        public static List <EMP_Ref_PriceType> GetPriceType()
        {
            ncelsEntities entities  = UserHelper.GetCn();
            var           priceType = entities.EMP_Ref_PriceType.ToList();

            return(priceType);
        }
Example #2
0
        /// <summary>
        /// Справочник тип услуги(заявки по ParentId)(договора)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static List <EMP_Ref_ServiceType> GetServiceTypeParentId(Guid id)
        {
            ncelsEntities entities    = UserHelper.GetCn();
            var           serviceType = entities.EMP_Ref_ServiceType.Where(e => e.ParentId == id && !e.IsDeleted).ToList();

            return(serviceType);
        }
Example #3
0
        /// <summary>
        /// Справчоник прайс лист калькулятор (договора)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static List <EMP_Ref_PriceList> GetPriceList(Guid id)
        {
            ncelsEntities entities  = UserHelper.GetCn();
            var           priceList = entities.EMP_Ref_PriceList.Where(e => e.ServiceTypeId == id).ToList();

            return(priceList);
        }
Example #4
0
        /// <summary>
        /// Справочник тип изменения(договора)
        /// </summary>
        /// <returns></returns>
        public static List <EMP_Ref_ChangeType> GetChangeType()
        {
            ncelsEntities entities   = UserHelper.GetCn();
            var           changeType = entities.EMP_Ref_ChangeType.ToList();

            return(changeType);
        }
Example #5
0
        /// <summary>
        /// Справочник банков, возвращает даже не подвержденные
        /// </summary>
        /// <returns></returns>
        public static List <EMP_Ref_Bank> GetBanks()
        {
            ncelsEntities entities = UserHelper.GetCn();
            var           banks    = entities.EMP_Ref_Bank.Where(e => !e.IsDeleted).ToList();

            return(banks);
        }
Example #6
0
        public static Dictionary GetDicItemByCode(string type, string code)
        {
            ncelsEntities db  = UserHelper.GetCn();
            var           dic = db.Dictionaries.AsNoTracking().FirstOrDefault(m => m.Type == type && m.Code == code);

            return(dic);
        }
Example #7
0
        /// <summary>
        /// Справочник единиц измерений(догвора)
        /// </summary>
        /// <returns></returns>
        public static List <EMP_Ref_PriceType> GetPriceType(IEnumerable <Guid> priceLists)
        {
            ncelsEntities entities  = UserHelper.GetCn();
            var           priceType = entities.EMP_Ref_PriceType.Where(e => priceLists.Contains(e.Id)).ToList();

            return(priceType);
        }
Example #8
0
        public static void Write(LogPlace place, Guid?employeeId, string text, string additionalText = null)
        {
            ncelsEntities context = UserHelper.GetCn();

            Write(context, place, employeeId, text, additionalText);
            context.SaveChanges();
        }
Example #9
0
        public static Guid GetDictionaryIdFirst(string type)
        {
            ncelsEntities entities = UserHelper.GetCn();
            var           dic      = entities.Dictionaries.FirstOrDefault(m => m.Type == type);

            return(dic?.Id ?? Guid.Empty);
        }
Example #10
0
        public static void WriteExt(string text, string additionalText = null)
        {
            ncelsEntities context = UserHelper.GetCn();

            WriteExt(context, text, additionalText);
            context.SaveChanges();
        }
Example #11
0
        /// <summary>
        /// Конвертирование во внутренний документ
        /// </summary>
        /// <param name="objectContext"></param>
        /// <param name="project"></param>
        /// <param name="currentEmployee"></param>
        /// <param name="singInfo">Информация о подписывающем</param>
        public static void ConvertInCorrespondentDocument(Document document, Document project, Employee currentEmployee,
                                                          string singInfo)
        {
            ncelsEntities context  = UserHelper.GetCn();
            Template      template = context.Templates.First(o => o.Id == project.TemplateId);

            document.QrCode = GetQrCode(GetTextQRcode(singInfo, !string.IsNullOrEmpty(project.Digest)));
            //Template convTemplate = context.Templates.First(o => o.Id == template.ConvertDictionaryTypeId);
            //document.DocumentDictionaryTypeId = convTemplate.DictionaryTypeId;
            //document.DocumentDictionaryTypeValue = convTemplate.DictionaryTypeValue;
            document.MainTaskId       = project.MainTaskId;
            document.MainDocumentId   = project.MainDocumentId;
            document.SourceId         = project.Id.ToString();
            document.SourceValue      = project.DisplayName;
            document.RegistratorValue = currentEmployee.DisplayName;
            document.RegistratorId    = currentEmployee.Id.ToString();
            document.DocumentType     = 5;
            document.TemplateId       = context.Templates.First().Id;

            document.IsDeleted     = false;
            document.DocumentDate  = document.CreatedDate = document.ModifiedDate = DateTime.Now;
            document.ExecutionDate = document.ExecutionDate.HasValue ? document.ExecutionDate : DateTime.Now.AddDays(15);
            document.IsAttachments = false;
            document.AttachPath    = FileHelper.GetObjectPathRoot();

            if (document.ApplicantType == 0)
            {
                document.StateType = 2;
                Registrator.SetNumber(document);
                context.Activities.Add(GetNewActivity(document));
                CopyFile(project.AttachPath.ToString(), document.AttachPath.ToString());
                ReplaceText(document.AttachPath.ToString(), "Проект.docx", "DocumentNumber", document.Number);
                ReplaceText(document.AttachPath.ToString(), "Проект.docx", "DocumentDate",
                            document.DocumentDate.Value.ToString("dd.MM.yyyy"));
            }
            else
            {
                var items = DictionaryHelper.GetItems(document.ExecutorsId, document.ExecutorsValue).Select(o => new Guid(o.Id)).ToList();

                var employes = context.Employees.Where(o => items.Contains(o.Id)).ToList();
                var orgId    = new Guid("8F0B91F3-AF29-4D3C-96D6-019CBBDFC8BE");
                if (employes.Select(o => o.OrganizationId).Contains(orgId))
                {
                    document.OrganizationId = orgId;
                }


                CopyFile(project.AttachPath.ToString(), document.AttachPath.ToString());
                document.StateType = 0;
                document.Number    = null;
            }

            project.DestinationId    = document.Id.ToString();
            project.DestinationValue = document.Number;

            context.Documents.Add(document);
            context.SaveChanges();
        }
Example #12
0
        public static Guid GetDicIdByCode(string type, string code)
        {
            ncelsEntities db  = UserHelper.GetCn();
            var           dic = db.Dictionaries.FirstOrDefault(m => m.Type == type && m.Code == code);

            if (dic != null)
            {
                return(dic.Id);
            }
            return(Guid.Empty);
        }
Example #13
0
        public static void DeleteFile(string id, string name)
        {
            FileHelper.DeleteFile(id, name);
            ncelsEntities service  = UserHelper.GetCn();
            Document      document = service.Documents.FirstOrDefault(o => o.AttachPath == id);

            if (document != null && document.IsAttachments)
            {
                document.IsAttachments = FileHelper.GetFiles(id, false).Count > 0;
                service.SaveChanges();
            }
        }
Example #14
0
        public static void UploadReplace(byte[] file, string name, string id, List <ReplaceItem> items)
        {
            FileHelper.BuildPreview(file, id.ToString(), name, items);
            ncelsEntities service  = UserHelper.GetCn();
            Document      document = service.Documents.FirstOrDefault(o => o.AttachPath == id);

            if (document != null && document.IsAttachments == false)
            {
                document.IsAttachments = true;
                service.SaveChanges();
            }
        }
Example #15
0
        public static void CreateIncomingDocs(Document document)
        {
            ncelsEntities context   = UserHelper.GetCn();
            List <Item>   items     = DictionaryHelper.GetItems(document.CorrespondentsId, document.CorrespondentsValue);
            List <string> listEmail = new List <string>();

            if (items.Count > 0)
            {
                foreach (var item in items)
                {
                    Unit unit = context.Units.Find(new Guid(item.Id));

                    if (unit.Type == 0)
                    {
                        Document doc = context.Documents.FirstOrDefault(x => x.OrganizationId == unit.Id && x.SourceId == document.Id.ToString());
                        if (doc == null)
                        {
                            Document inDoc = new Document()
                            {
                                Id                            = Guid.NewGuid(),
                                Summary                       = document.Summary,
                                OutgoingDate                  = document.DocumentDate,
                                OutgoingNumber                = document.Number,
                                DocumentDate                  = DateTime.Now,
                                MonitoringType                = document.MonitoringType,
                                CorrespondentsId              = UserHelper.GetCurrentEmployee().OrganizationId.ToString(),
                                CorrespondentsValue           = UserHelper.GetCurrentEmployee().Organization.Name,
                                CorrespondentsInfo            = document.SignerValue,
                                ApplicantName                 = document.CreatedUserValue,
                                ApplicantEmail                = UserHelper.GetCurrentEmployee().Organization.Email,
                                ExecutionDate                 = document.ExecutionDate,
                                DocumentKindDictionaryId      = document.DocumentKindDictionaryId,
                                DocumentKindDictionaryValue   = document.DocumentKindDictionaryValue,
                                QuestionDesignDictionaryId    = document.QuestionDesignDictionaryId,
                                QuestionDesignDictionaryValue = document.QuestionDesignDictionaryValue,
                                Counters                      = document.Counters,
                                PageCount                     = document.PageCount,
                                CopiesCount                   = document.CopiesCount,
                                LanguageDictionaryId          = document.LanguageDictionaryId,
                                LanguageDictionaryValue       = document.LanguageDictionaryValue,
                                OrganizationId                = unit.Id,
                                SourceId                      = document.Id.ToString(),
                                SourceValue                   = document.DisplayName,
                                AttachPath                    = FileHelper.GetObjectPathRoot()
                            };
                            context.Documents.Add(inDoc);
                            CopyFile(document.AttachPath.ToString(), inDoc.AttachPath.ToString());
                        }
                    }
                    context.SaveChanges();
                }
            }
        }
Example #16
0
        public static List <DictionaryInfo> GetNomenclatureList()
        {
            ncelsEntities entities = UserHelper.GetCn();
            var           items    = entities.Dictionaries.Where(o => o.Type == "Nomenclature").GroupBy(o => o.Year);

            return(items.Select(o => new DictionaryInfo()
            {
                NameRu = o.Key,
                TypeRu = o.Key,
                NameKz = o.Key,
                TypeKz = o.Key
            }).OrderBy(o => o.NameRu).ToList());
        }
Example #17
0
        public static void Upload(byte[] file, string name, Guid id)
        {
            FileHelper.BuildPreview(file, id.ToString(), name);

            ncelsEntities service  = UserHelper.GetCn();
            Document      document = service.Documents.FirstOrDefault(o => o.Id == id);

            if (document != null && document.IsAttachments == false)
            {
                document.IsAttachments = true;
                service.SaveChanges();
            }
        }
Example #18
0
        public static void Upload(Stream fileInput, string name, string id)
        {
            var file = FileHelper.ReadFully(fileInput);

            FileHelper.BuildPreview(file, id.ToString(), name);

            ncelsEntities service  = UserHelper.GetCn();
            Document      document = service.Documents.FirstOrDefault(o => o.AttachPath == id);

            if (document != null && document.IsAttachments == false)
            {
                document.IsAttachments = true;
                service.SaveChanges();
            }
        }
Example #19
0
 private static void GetEmployeePermissionIfEmpty()
 {
     if (_employeePermissions == null)
     {
         ncelsEntities ncelsEntities = UserHelper.GetCn();
         var           permissions   = ncelsEntities.EmployeePermissionRoles.Join(ncelsEntities.PermissionRoleKeys, x => x.PermissionRoleId, x => x.PermissionRoleId,
                                                                                  (epr, prk) => new EmployeePermission
         {
             EmployeeId      = epr.EmployeeId,
             PermissionKey   = prk.PermissionKey,
             PermissionValue = prk.PermissionValue
         });
         _employeePermissions = permissions.ToList();
     }
 }
Example #20
0
        public static void ConvertInAdminDocument(Document document, Document project, Employee currentEmployee,
                                                  string singInfo)
        {
            ncelsEntities context  = UserHelper.GetCn();
            Template      template = context.Templates.First(o => o.Id == project.TemplateId);

            document.QrCode = GetQrCode(GetTextQRcode(singInfo, !string.IsNullOrEmpty(project.Digest)));
            //Template convTemplate = context.Templates.First(o => o.Id == template.ConvertDictionaryTypeId);
            //document.DocumentDictionaryTypeId = convTemplate.DictionaryTypeId;
            //document.DocumentDictionaryTypeValue = convTemplate.DictionaryTypeValue;
            document.MainTaskId       = project.MainTaskId;
            document.MainDocumentId   = project.MainDocumentId;
            document.SourceId         = project.Id.ToString();
            document.SourceValue      = project.DisplayName;
            document.RegistratorValue = currentEmployee.DisplayName;
            document.RegistratorId    = currentEmployee.Id.ToString();
            document.DocumentType     = 3;
            document.TemplateId       = context.Templates.First().Id;

            document.IsDeleted     = false;
            document.DocumentDate  = document.CreatedDate = document.ModifiedDate = DateTime.Now;
            document.ExecutionDate = document.ExecutionDate.HasValue ? document.ExecutionDate : DateTime.Now.AddDays(15);
            document.IsAttachments = false;
            document.AttachPath    = FileHelper.GetObjectPathRoot();

            CopyFile(project.AttachPath.ToString(), document.AttachPath.ToString());

            if (document.ProjectType == 4)
            {
                document.StateType = 2;
                Registrator.SetNumber(document);
                context.Activities.Add(GetNewActivity(document));
                ReplaceText(document.AttachPath.ToString(), "Проект.docx", "DocumentNumber", document.Number);
                ReplaceText(document.AttachPath.ToString(), "Проект.docx", "DocumentDate", document.DocumentDate.Value.ToString("dd.MM.yyyy"));
            }
            if (document.ProjectType == 3)
            {
                document.Number    = null;
                document.StateType = 0;
            }
            if (document.ProjectType == 6)
            {
                document.Number    = null;
                document.StateType = 0;
            }
            context.Documents.Add(document);
            context.SaveChanges();
        }
Example #21
0
        public static List <DictionaryInfo> GetCorRefTypeList()
        {
            ncelsEntities entities = UserHelper.GetCn();
            var           items    = entities.Dictionaries.Where(o => o.Type == "DepartmentTypeDictionary").ToList();
            var           data     = items.Select(o => new DictionaryInfo()
            {
                NameRu = o.Name,
                NameKz = o.NameKz,
                TypeRu = o.Id.ToString(),
                TypeKz = o.Id.ToString(),
            }).OrderBy(o => o.NameRu).ToList();

            data.Insert(0, new DictionaryInfo()
            {
                NameRu = Messages.Property_Все_394__00, NameKz = Messages.Property_Все_394__00, TypeKz = null, TypeRu = null
            });
            return(data);
        }
Example #22
0
        /// <summary>
        /// Регистрация повторных документов
        /// </summary>
        /// <param name="document"></param>
        public static void SetRepeaterNumber(Document document)
        {
            ncelsEntities context   = UserHelper.GetCn();
            int           number    = 0;
            string        strNumber = string.Empty;

            if (document.RepeaterId.HasValue)
            {
                Document repeatDocument = context.Documents.FirstOrDefault(x => x.Id == document.RepeaterId);
                int      repeatCount    =
                    context.Documents.Count(
                        x => x.RepeaterId == document.RepeaterId.Value && x.Id != document.Id && x.IsDeleted == false) + 1;
                if (repeatDocument != null &&
                    (repeatDocument.DocumentType != 3 || (repeatDocument.DocumentType == 3 && repeatDocument.ProjectType == 3)))
                {
                    strNumber = string.Format("{0},{1}", repeatDocument.Number, repeatCount + 1);
                    number    = repeatDocument.SortNumber;
                }
                if (repeatDocument != null && repeatDocument.DocumentType == 3 && repeatDocument.ProjectType == 4)
                {
                    string tempNumber = repeatDocument.Number;
                    int    tempIndex  = tempNumber.IndexOf(",", StringComparison.CurrentCulture);

                    if (tempIndex < tempNumber.Length)
                    {
                        tempNumber  = tempNumber.Substring(0, tempIndex);
                        repeatCount = repeatCount + 1;
                    }

                    strNumber = string.Format("{0},{1}", tempNumber, repeatCount);
                    number    = repeatDocument.SortNumber;
                }
                document.Number        = strNumber;
                document.DocumentDate  = DateTime.Now;
                document.SortNumber    = number;
                document.SortingNumber = BuildFormattedNumber(strNumber);
                document.DisplayName   = BuildDisplayName(document);
            }
        }
Example #23
0
        public void SendMail(string email, string subject, string body, string documentId, string files, Guid docId, List <string> listEmail, MailAddress mailAddress = null)
        {
            Unit unit = UserHelper.GetCurrentEmployee().Organization;

            if (Config.EnableMail)
            {
                if (mailAddress == null)
                {
                    //mailAddress = new MailAddress(Config.MailSetting.SmtpReply, Config.MailSetting.SmtpUser);
                    mailAddress = new MailAddress(UserHelper.GetCurrentEmployee().Organization.Email, UserHelper.GetCurrentEmployee().Organization.Name, Encoding.UTF8);
                }
                MailMessage message = new MailMessage()
                {
                    Sender          = mailAddress,
                    Subject         = subject,
                    From            = new MailAddress(unit.Email),
                    ReplyTo         = new MailAddress(unit.Email),
                    BodyEncoding    = Encoding.UTF8,
                    Body            = body,
                    IsBodyHtml      = true,
                    SubjectEncoding = Encoding.UTF8,
                };
                string[] emails = email.Split(';');
                foreach (var em in emails)
                {
                    if (em.Trim() != string.Empty && !listEmail.Contains(em.Trim()))
                    {
                        message.To.Add(em.Trim());
                    }
                }


                if (files != null)
                {
                    string[] attach = files.Split(';');
                    foreach (string file in attach)
                    {
                        message.Attachments.Add(new Attachment(FileHelper.GetFileName(documentId, file)));
                    }
                }
                SmtpClient client = new SmtpClient {
                    Host = Config.MailSetting.SmtpServer,
                    Port = Config.MailSetting.SmtpPort,

                    UseDefaultCredentials = false,
                    EnableSsl             = Config.MailSetting.EnableSsl,
                    Credentials           =
                        new NetworkCredential(Config.MailSetting.SmtpUserName,
                                              Config.MailSetting.SmtpPassword),
                    DeliveryMethod = SmtpDeliveryMethod.Network
                };

                if (message.To.Count != 0)
                {
                    client.Send(message);
                }


                ncelsEntities db      = UserHelper.GetCn();
                DateTime      dt      = DateTime.Now;
                Guid          groupId = new Guid();
                foreach (string e in emails)
                {
                    db.Histories.Add(GetHistory(e, subject, body, files, dt, groupId, docId));
                }
                db.SaveChanges();
            }
        }
Example #24
0
        /// <summary>
        /// Регистрация документов, кроме входящих (они регятся в БД)
        /// </summary>
        /// <param name="document"></param>
        public static void SetNumber(Document document)
        {
            ncelsEntities context   = UserHelper.GetCn();
            int           number    = 0;
            string        strNumber = string.Empty;

            if (document.RepeaterId.HasValue)
            {
                Document repeatDocument = context.Documents.FirstOrDefault(x => x.Id == document.RepeaterId);
                int      repeatCount    = context.Documents.Count(x => x.RepeaterId == document.RepeaterId.Value && x.Id != document.Id) + 1;
                if (repeatDocument != null &&
                    (repeatDocument.DocumentType != 3 || (repeatDocument.DocumentType == 3 && repeatDocument.ProjectType == 3)))
                {
                    strNumber = string.Format("{0},{1}", repeatDocument.Number, repeatCount + 1);
                    number    = repeatDocument.SortNumber;
                }
                if (repeatDocument != null && repeatDocument.DocumentType == 3 && repeatDocument.ProjectType == 4)
                {
                    string tempNumber = repeatDocument.Number;
                    int    tempIndex  = tempNumber.IndexOf(",", StringComparison.CurrentCulture);

                    if (tempIndex < tempNumber.Length)
                    {
                        tempNumber  = tempNumber.Substring(0, tempIndex);
                        repeatCount = repeatCount + 1;
                    }
                    strNumber = string.Format("{0},{1}", tempNumber, repeatCount);
                    number    = repeatDocument.SortNumber;
                }
                if (repeatDocument != null && repeatDocument.DocumentType == 6)
                {
                    strNumber = string.Format("{0},{1}", repeatDocument.Number, repeatCount);
                    number    = repeatDocument.SortNumber;
                }
            }
            else
            {
                number = GetNumber(document, context);
                switch (document.DocumentType)
                {
                case 0:
                    strNumber = number + String.Empty;
                    break;

                case 1:
                    Guid       id         = Guid.Parse(document.NomenclatureDictionaryId);
                    Dictionary dictionary =
                        context.Dictionaries.FirstOrDefault(o => o.Id == id);
                    string pref = string.Empty;
                    if (dictionary != null)
                    {
                        pref = dictionary.Code;
                    }
                    if (document.OutgoingType == 0)
                    {
                        strNumber = string.Format("{1}/{0}-И", number, pref);
                    }
                    else
                    {
                        strNumber = string.Format("{1}/{0}", number, pref);
                    }
                    break;

                case 2:
                    //физическое лицо
                    if (document.ApplicantType == 0)
                    {
                        if (document.ApplicantCategoryDictionaryValue == "Аноним")
                        {
                            strNumber = string.Format("Д/А-{0}", number);
                        }
                        else if (document.ApplicantCategoryDictionaryValue == "Коллектив")
                        {
                            strNumber = string.Format("ҰЖ-{0}", number);
                        }
                        else
                        {
                            strNumber = string.Format("ЖТ-{0}-{1}", GetCodeCitizenName(document.CorrespondentsInfo), number);
                        }
                    }
                    else
                    {
                        //юридические лица
                        strNumber = string.Format("ЗТ-{0}-{1}", GetCodeCitizenName(document.CorrespondentsInfo), number);
                    }
                    break;

                case 3:
                    // Приказы
                    if (document.ProjectType == 3)
                    {
                        switch (document.AdministrativeTypeDictionaryId.ToUpper())
                        {
                        case "0BB8D6CB-2BDA-483A-9258-4E951B1329C8":
                            strNumber = string.Format("{0}-ж", number);
                            break;

                        case "91E8A59D-497C-470F-ACB4-71BD13E49823":
                            strNumber = string.Format("{0}-д", number);
                            break;

                        case "6099492A-0761-4ACC-A39C-A35F1749E313":
                            strNumber = string.Format("{0}-iс", number);
                            break;

                        default:
                            strNumber = string.Format("{0}", number);
                            break;
                        }
                    }
                    // Приказы по основной деятельности
                    if (document.ProjectType == 6)
                    {
                        strNumber = string.Format("{0}", number);
                    }
                    // Протокола
                    if (document.ProjectType == 4)
                    {
                        strNumber = string.Format("{0},1", number);
                    }
                    break;

                case 4:
                    strNumber = string.Format("П-{0}", number);
                    break;

                case 5:
                    if (document.ApplicantType == 0)
                    {
                        Guid     userId    = Guid.Parse(document.CreatedUserId);
                        Employee employee  = context.Employees.Include("Position.Parent").FirstOrDefault(d => d.Id == userId);
                        string   prefInner = string.Empty;
                        if (employee?.Position?.Parent != null)
                        {
                            prefInner = employee.Position.Parent.Code;
                        }
                        strNumber = string.Format("{0}-{1}", prefInner, number);
                    }
                    if (document.ApplicantType == 1)
                    {
                        strNumber = string.Format("{0}", number);
                    }
                    break;

                case 6:
                    strNumber = string.Format("{0}", number);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("document");
                }
            }
            document.Number        = strNumber;
            document.DocumentDate  = DateTime.Now;
            document.SortNumber    = number;
            document.SortingNumber = BuildFormattedNumber(strNumber);
            document.DisplayName   = BuildDisplayName(document);
        }
Example #25
0
        public static Dictionary GetDicItemById(Guid id)
        {
            ncelsEntities db = UserHelper.GetCn();

            return(db.Dictionaries.AsNoTracking().FirstOrDefault(m => m.Id == id));
        }