コード例 #1
0
ファイル: MainForm.cs プロジェクト: iluxa1810/DictService
        private async void btnAddDict_Click(object sender, EventArgs e)
        {
            DictionaryInfo dictInfo;
            string         path;

            using (var form = new AddDictForm(cbCategory))
            {
                form.ShowDialog(this);
                if (form.DialogResult != DialogResult.OK)
                {
                    return;
                }
                dictInfo = form.GetUploadData();
                var mdbPath = form.GetFilePath();
                try
                {
                    AccessHelper.CheckExistPrimaryKey(AccessHelper.CreateMdbConnectionString(mdbPath));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
                path = ZipHelper.CreateZipDictionary(mdbPath, FileHelper.GetTemporaryDirectory());
            }
            var id = StartTask(this,
                               new TaskEventArgs()
            {
                Name = $"Добавление {dictInfo.FriendlyName}", Status = "Started"
            });

            try
            {
                using (var client = new FileUploadClient())
                {
                    using (Stream file = new FileStream(path, FileMode.Open))
                    {
                        await client.UploadAsync(dictInfo, file);
                    }
                }
                RefreshTaskStatus(this, new TaskEventArgs()
                {
                    Status = "Complete", Taskid = id
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                FileHelper.DeleteFolder(Path.GetDirectoryName(path));
            }
        }
コード例 #2
0
 private async void resfreshBtn_Click(object sender, EventArgs e)
 {
     if (uploadChkBx.Checked)
     {
         using (var client = new FileUploadClient())
         {
             try
             {
                 string path;
                 path = ZipHelper.CreateZipDictionary(tbFilePath.Text);
                 DictionaryInfo dictInfo = new DictionaryInfo()
                 {
                     Dictionary_id = Convert.ToInt32(tbDictionaryId.Text)
                     , SenderLogin = AccountHelper.GetAccount(), Action = ActionEnum.EditDict
                 };
                 Stream file = new FileStream(path, FileMode.Open);
                 await client.UploadAsync(dictInfo, file);
             }
             catch (Exception)
             {
             }
         }
     }
     using (var client = new DataClient())
     {
         var dictInfo = new DictionaryData()
         {
             Dictionary_id = Convert.ToInt32(tbDictionaryId.Text),
             Category_id   = ((CategoryData)categoryCb.SelectedItem).Category_id,
             FriendlyName  = FrendlyNameTb.Text,
             Description   = DescriptionRtb.Text
         };
         client.ChangeDictionaryInfo(dictInfo);
         client.ChangeDictionaryStatus(Convert.ToInt32(tbDictionaryId.Text), DictionaryStateEnum.Available);
     }
 }