Esempio n. 1
0
        //списать
        private void btnDeduct_Click(object sender, RoutedEventArgs e)
        {
            CheckDeduct();
            if (itemDeduct.Count != 0)
            {
                MessageBoxResult result = MessageBox.Show("Вы уверены, что хотите списать эти записи?",
                                                          "Потверждение", MessageBoxButton.YesNo,
                                                          MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    string           pathDocument = System.IO.Path.GetFullPath(@"..\..\") + "\\doc2.docx";
                    Word.Application wordApp      = new Word.Application();
                    wordApp.Visible = true;

                    Word.Document document = wordApp.Documents.OpenNoRepairDialog(pathDocument);
                    document.Activate();

                    Word.Table table = document.Tables[1];
                    int        k     = 3;
                    itemDeduct.ForEach(it =>
                    {
                        table.Rows.Add();
                        table.Cell(k, 1).Range.Text = (k - 2).ToString();
                        table.Cell(k, 2).Range.Text = it.TypeDeduct + it.GroupName;
                        table.Cell(k, 3).Range.Text = it.Deadline;
                        table.Cell(k, 4).Range.Text = it.ShelfLife;
                        table.Cell(k, 5).Range.Text = it.Count.ToString();

                        k++;
                    });

                    ReplaceWord(wordApp, "numbers", itemDeduct.Sum(x => x.Count).ToString());
                    ReplaceWord(wordApp, "start_number", "1");
                    ReplaceWord(wordApp, "end_number", itemDeduct.Count.ToString());


                    db.SaveChanges();
                    Load();
                    itemDeduct.Clear();
                }
            }
            else
            {
                MessageBox.Show("Не выбрано не одной записи");
            }


            itemDeduct.Clear();
        }
Esempio n. 2
0
        public MainProcessor(string connectionString, IDictionary <string, VaultDetails> vaultDetails,
                             string thumbnailsUrlPattern, string brsTermsUrlPattern, string leoTermsUrlPattern, CountriesClient countries,
                             ConferencesClient conferences, bool deleteNotInList)
        {
            ConnectionString     = connectionString;
            VaultDetails         = vaultDetails;
            Countries            = countries;
            Conferences          = conferences;
            ThumbnailsUrlPattern = thumbnailsUrlPattern;
            BrsTermsUrlPattern   = brsTermsUrlPattern;
            LeoTermsUrlPattern   = leoTermsUrlPattern;
            DeleteNotInList      = deleteNotInList;

            _ctx = new DocumentsContext(connectionString);
            _ctx.Database.CreateIfNotExists();
            var connectionForDisplay = _ctx.Database.Connection.ConnectionString.Split(';')[0];

            ClassLogger.Info($"Connection string {connectionForDisplay}");


            foreach (var type in ListPropertyTypesNames.Names)
            {
                if (_ctx.ValueTypes.FirstOrDefault(x => x.Name == type) == null)
                {
                    _ctx.ValueTypes.Add(new ListPropertyType {
                        ListPropertyTypeId = Guid.NewGuid(), Name = type
                    });
                }
            }
            _ctx.SaveChanges();
        }
Esempio n. 3
0
        public void ProcessListProperty(PropertyListType lst)
        {
            if (lst.Type == "meeting")
            {
                ProcessCrmMeetings(lst);
            }
            else if (lst.Type == "term")
            {
                ProcessCrmTerms(lst);
            }
            else
            {
                ProcessList(lst);
            }


            using (var trans = _ctx.Database.BeginTransaction())
            {
                try
                {
                    _ctx.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();

                    ClassLogger.Error($"ProcessListProperty {ex.Message} {lst.Type}");
                    throw;
                }
            }
        }
Esempio n. 4
0
 private void deleteRowVKR(object sender, RoutedEventArgs e)
 {
     Model.Practical itemFocus = practicalGrid.SelectedValue as Model.Practical;
     itemFocus.DateDeleted = DateTime.Now;
     db.SaveChanges();
     LoadPractical();
     FindCount();
 }
Esempio n. 5
0
 private void deleteRowVKR(object sender, RoutedEventArgs e)
 {
     Model.Theses itemFocus = thesesGrid.SelectedValue as Model.Theses;
     itemFocus.DateDeleted = DateTime.Now;
     db.SaveChanges();
     LoadTheses();
     FindCount();
 }
Esempio n. 6
0
        public static bool UpdateMaster(DocumentsContext ctx, MFilesDocument targetDoc, ObjectVersionWrapper sourceDoc,
                                        IDictionary <string, VaultDetails> vaultDetails, CountriesClient countries)
        {
            targetDoc.Guid         = sourceDoc.Guid;
            targetDoc.CreatedDate  = sourceDoc.CreatedDate;
            targetDoc.ModifiedDate = sourceDoc.ModifiedDate;

            var masterDoc = targetDoc.Document;

            masterDoc.MFilesDocument = targetDoc;
            masterDoc.UnNumber       = string.IsNullOrEmpty(sourceDoc.UnNumber)?sourceDoc.Name:sourceDoc.UnNumber;
            masterDoc.Convention     = vaultDetails[sourceDoc.VaultName].NameInDb ?? sourceDoc.VaultName.ToLower();
            var authorAndType = GetAuthor(sourceDoc, countries);

            if (authorAndType != null)
            {
                masterDoc.Author     = authorAndType.Item1;
                masterDoc.AuthorType = authorAndType.Item2 ? "organization" : "person";
            }
            masterDoc.CountryFull = countries.GetCountryIsoCode2(sourceDoc.Country) != null ? sourceDoc.Country: null;
            masterDoc.Country     = countries.GetCountryIsoCode2(masterDoc.CountryFull);
            masterDoc.Copyright   = sourceDoc.Copyright;
            var period = sourceDoc.GetPeriod();

            if (period != null)
            {
                masterDoc.PeriodStartDate = period.Item1;
                masterDoc.PeriodEndDate   = period.Item2;
            }
            masterDoc.PublicationDate = sourceDoc.PublicationDate;

            lock ("Process") {
                ProcessDocumentTypes(ctx, masterDoc, sourceDoc);
                ProcessMeetings(ctx, masterDoc, sourceDoc);
                ProcessMeetingTypes(ctx, masterDoc, sourceDoc);
                ProcessChemicals(ctx, masterDoc, sourceDoc);
                ProcessPrograms(ctx, masterDoc, sourceDoc);
                ProcessTerms(ctx, masterDoc, sourceDoc);
                ProcessTags(ctx, masterDoc, sourceDoc);

                using (var trans = ctx.Database.BeginTransaction())
                {
                    try
                    {
                        ctx.SaveChanges();
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        ClassLogger.Error("SQL exception " + ex);
                        throw;
                    }
                }
            }
            return(true);
        }
        public void updateDocument(Document model)
        {
            var executedquery = from document in db.Document
                                where document.documentId == model.documentId
                                select document;

            executedquery.First().categoryId = model.categoryId;
            executedquery.First().content    = model.content;
            executedquery.First().url        = model.url;
            db.SaveChanges();
        }
Esempio n. 8
0
        public async Task <HttpResponseMessage> UploadFile()
        {
            Dictionary <string, byte[]> files      = new Dictionary <string, byte[]>();
            Dictionary <string, string> attributes = new Dictionary <string, string>();

            CloudBlobContainer container = getContainer(ConfigurationManager.AppSettings["TestContainerName"]);

            container.CreateIfNotExists();

            var streamProvider = new MultipartMemoryStreamProvider();
            await Request.Content.ReadAsMultipartAsync(streamProvider);

            String category     = HttpContext.Current.Request.Params.Get("Category");
            String lastReviewed = HttpContext.Current.Request.Params.Get("LastReviewed");
            String filename     = "";

            foreach (var file in streamProvider.Contents)
            {
                if (file.Headers.ContentDisposition.FileName != null)
                {
                    filename = file.Headers.ContentDisposition.FileName.Trim('\"');
                    var buffer = await file.ReadAsByteArrayAsync();

                    files.Add(filename, buffer);
                }
            }

            try {
                string blobName = "philipJonas_blob_" + Guid.NewGuid().ToString();
                Stream stream   = new MemoryStream(files.First().Value);

                CloudBlockBlob blockBlob = container.GetBlockBlobReference(blobName);

                blockBlob.UploadFromStream(stream);

                Document document = new Document();
                document.Category           = category;
                document.LastReviewed       = lastReviewed;
                document.DocumentFileName   = filename;
                document.AzureFileReference = blobName;
                db.Documents.Add(document);
                db.SaveChanges();

                return(new HttpResponseMessage {
                    Content = new StringContent(document.DocumentId.ToString())
                });
            }
            catch (Exception e) {
                return(new HttpResponseMessage {
                    Content = new StringContent(e.Message)
                });
            }
        }
Esempio n. 9
0
 private void Registration()
 {
     db.Add(new User()
     {
         Surname  = textBoxSurname.Text,
         Login    = textBoxLogin.Text,
         Email    = textBoxEmail.Text,
         Password = textBoxPassword.Password,
         Name     = textBoxName.Text,
         Role     = 1
     });
     db.SaveChanges();
 }
Esempio n. 10
0
        public static void Delete(DocumentsContext ctx, MFilesDocument targetDocument)
        {
            if (targetDocument == null)
            {
                return;
            }
            var doc = targetDocument;

            Debug.Assert(doc != null);
            if (doc.Title != null)
            {
                ClassLogger.Info($"Delete document '{doc.Title.Value}'");
            }
            else
            {
                ClassLogger.Warn($"Delete document {doc.Guid}");
            }

            var documents = from x in ctx.Documents where x.DocumentId == doc.Guid select x;

            ctx.Documents.RemoveRange(documents.ToList());

            var titles = from x in ctx.Titles where x.TitleId == doc.Guid select x;

            ctx.Titles.RemoveRange(titles.ToList());

            var descriptions = (from x in ctx.Descriptions where x.DescriptionId == doc.Guid select x).ToList();

            ctx.Descriptions.RemoveRange(descriptions.ToList());

            var files = (from x in ctx.Files where x.FileId == doc.Guid select x).ToList();

            ctx.Files.RemoveRange(files.ToList());

            ctx.MFilesDocuments.Remove(doc);

            using (var trans = ctx.Database.BeginTransaction())
            {
                try
                {
                    ctx.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    ClassLogger.Error($"Delete document {ex.Message}");
                    throw;
                }
            }
        }
Esempio n. 11
0
 private void AddVkr_Click(object sender, RoutedEventArgs e)
 {
     if (Validate())
     {
         if (vkr != null)
         {
             if (vkr.Id != 0)
             {
                 InitVkr();
                 db.SaveChanges();
                 this.Close();
             }
             else
             {
                 InitVkr();
                 db.Vkr.Add(vkr);
                 db.SaveChanges();
                 this.Close();
             }
         }
     }
     if (theses != null)
     {
         if (theses.Id != 0)
         {
             InitTheses();
             db.SaveChanges();
             this.Close();
         }
         else
         {
             InitTheses();
             db.Theses.Add(theses);
             db.SaveChanges();
             this.Close();
         }
     }
 }
Esempio n. 12
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (Validate())
     {
         if (IsPassword())
         {
             db.Users.FirstOrDefault(x => x.Login.Trim() == login || x.Email.Trim() == login).Password = textBoxNewPassword.Text.Trim();
             db.SaveChanges();
             MessageBox.Show("Пароль был изменен");
             BackAutorizthion();
         }
         else
         {
             textBoxInfo.Text = "Старый пароль неверный";
         }
     }
 }
Esempio n. 13
0
        public async Task <IHttpActionResult> Post(Documents documents)
        {
            DocumentsContext context = new DocumentsContext();
            var   userId             = User.Identity.Name;
            Int16 documentStartCount = 0;
            Int16 documentEndCount   = 0;



            if (documents.DocumentType != null)
            {
                if (userId == "*****@*****.**")
                {
                    documents.UserId = "BSK123";
                }
                else
                {
                    documents.UserId = "BAP123";
                }

                if (documents.ImagePath != null)
                {
                    documents.ImagePath = documents.ImagePath.Replace("C:\\fakepath\\", "");
                }

                documentStartCount = Convert.ToInt16(context.Documents.Count());

                context.Documents.Add(documents);

                context.SaveChanges();


                documentEndCount = Convert.ToInt16(context.Documents.Count());
            }
            if (documentEndCount > documentStartCount)
            {
                //return RedirectToRoute("Home/Index","");
                return(this.Ok(true));
            }
            else
            {
                return(this.Ok(false));
            }
        }
Esempio n. 14
0
        public static MFilesDocument UpdateSlave(DocumentsContext ctx, MFilesDocument masterDoc, MFilesDocument targetDoc, ObjectVersionWrapper sourceDoc, IDictionary <string, VaultDetails> vaultDetails, string thumbnailsUrlPattern)
        {
            if (sourceDoc.Guid != masterDoc.Guid)
            {
                targetDoc.Guid         = sourceDoc.Guid;
                targetDoc.ModifiedDate = sourceDoc.ModifiedDate;
                targetDoc.CreatedDate  = sourceDoc.CreatedDate;
            }
            else
            {
                targetDoc = masterDoc;
            }

            var doc = masterDoc.Document;

            Debug.Assert(doc != null);

            string languageCode;

            // TODO: should be in configuration or don't use CultureUtils
            // or we need to update language in M-Files
            if (sourceDoc.Language == "Portugese")
            {
                languageCode = "pt";
            }
            else if (sourceDoc.Language == "Azeri")
            {
                languageCode = "az";
            }
            else
            {
                languageCode = CultureUtils.GetLangTwoLetterCode(sourceDoc.Language);
            }

            if (languageCode == null)
            {
                ClassLogger.Warn(
                    $"Could not find language code for  {sourceDoc.Language} (Document {sourceDoc.UnNumber})");
                return(null);
            }

            var title = doc.Titles.FirstOrDefault(t => t.Language == languageCode && t.Document == doc);

            if (title == null || title.MFilesDocument == targetDoc)
            {
                if (title == null)
                {
                    title = new Title {
                        MFilesDocument = targetDoc
                    };
                    doc.Titles.Add(title);
                }

                title.Document       = doc;
                title.Language       = languageCode;
                title.LanguageFull   = sourceDoc.Language;
                title.MFilesDocument = targetDoc;
                title.Value          = sourceDoc.Title;
            }

            var descirpiton = doc.Descriptions.FirstOrDefault(t => t.Language == languageCode && t.Document == doc);

            if (descirpiton == null || descirpiton.MFilesDocument == targetDoc)
            {
                if (descirpiton == null)
                {
                    descirpiton = new Description();
                    doc.Descriptions.Add(descirpiton);
                }
                descirpiton.Document       = doc;
                descirpiton.Language       = languageCode;
                descirpiton.LanguageFull   = sourceDoc.Language;
                descirpiton.MFilesDocument = targetDoc;
                descirpiton.Value          = sourceDoc.Description;
            }


            var file          = sourceDoc.File;
            var repositoryUrl = vaultDetails[sourceDoc.VaultName].Url ?? "";


            var targetFile = ctx.Files.FirstOrDefault(f => f.FileId == targetDoc.Guid);

            if (targetFile == null)
            {
                targetFile = new File();
                doc.Files.Add(targetFile);
            }
            targetFile.Document       = doc;
            targetFile.MFilesDocument = targetDoc;
            targetFile.Language       = languageCode;
            targetFile.LanguageFull   = sourceDoc.Language;
            targetFile.Name           = file.Name;
            targetFile.Extension      = file.Extension.ToLower();
            targetFile.Size           = file.Size;
            targetFile.MimeType       = Mime.Lookup(file.Name + "." + file.Extension.ToLower());
            targetFile.Url            = file.GetUrl(repositoryUrl);
            targetFile.ThumbnailUrl   = thumbnailsUrlPattern.Replace("{vault}", sourceDoc.VaultName)
                                        .Replace("{file}", $"{targetFile.Name}.{targetFile.Extension}");


            using (var trans = ctx.Database.BeginTransaction())
            {
                try
                {
                    ctx.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    ClassLogger.Error(ex);
                    throw;
                }
            }

            return(targetDoc);
        }