Пример #1
0
 private void SaveSound()
 {
     try
     {
         var sound = GetSoundData();
         if (dlg != null && !string.IsNullOrEmpty(dlg.FileName))
         {
             string f        = dlg.FileName;
             string fullPath = Application.StartupPath + @"\Sound\" + txtPath.Text;
             File.Copy(f, fullPath);
         }
         var result = BLLSound.CreateOrUpdate(sound);
         if (result.IsSuccess)
         {
             ResetForm();
             LoadDataToGridView();
         }
         else
         {
             MessageBox.Show(result.Messages[0].msg, result.Messages[0].Title);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #2
0
 private void GetCBLine()
 {
     cbLine.DataSource    = null;
     cbLine.DataSource    = BLLSound.GetLinesHaveReadSoundConfig();
     cbLine.ValueMember   = "Data";
     cbLine.DisplayMember = "Name";
 }
Пример #3
0
 private void LoadDataToGridView()
 {
     try
     {
         dgListSound.DataSource = null;
         dgListSound.DataSource = BLLSound.Gets();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #4
0
        private void butCopy_Click(object sender, EventArgs e)
        {
            var model = (ModelSelectItem)cbLine.SelectedItem;

            if (model != null)
            {
                BLLSound.CopyReadSoundConfig(lineId, model.Data);
            }
            else
            {
                MessageBox.Show("Vui lòng chọn cấu hình của chuyền cần sao chép.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #5
0
 private void butDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (soundId > 0)
         {
             if (MessageBox.Show("Bạn có muốn xoá?", "Xoá file", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
             {
                 BLLSound.Delete(soundId);
                 ResetForm();
                 LoadDataToGridView();
             }
         }
         else
         {
             MessageBox.Show("Lỗi: Bạn chưa chọn đối tượng để xoá.");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Lỗi: " + ex.Message);
     }
 }
Пример #6
0
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            try
            {
                var result = MessageBox.Show("Chương trình sẽ xóa bỏ tất cả các tệp Âm thanh cũ và tạo lại danh sách Tệp Âm thanh mới như trong Thư mục bạn chỉ định.\n Bạn có muốn thực muốn thực hiện thao tác này không ?", "Thông Báo", MessageBoxButtons.YesNoCancel);
                if (result == DialogResult.Yes)
                {
                    var folderResult = folderBrowserDialog1.ShowDialog();
                    if (folderResult == DialogResult.OK)
                    {
                        var filterStr = "*.wav,*.mp3";
                        //   dbclass.listAppConfig = appConfigDAO.GetListAppConfig(AppId);
                        //  if (dbclass.listAppConfig != null && dbclass.listAppConfig.Count > 0)
                        //  {
                        //       var cf = dbclass.listAppConfig.FirstOrDefault(x => x.Name.Trim().ToUpper().Equals(eAppConfigName.SoundFileExtentions));
                        //  filterStr = cf != null ? cf.Value.Trim() : "*.wav,*.mp3";
                        filterStr = "*.wav ";
                        //    }

                        var files = Directory.GetFiles(folderBrowserDialog1.SelectedPath, "*.*", SearchOption.AllDirectories).Where(x => filterStr.Contains(System.IO.Path.GetExtension(x).ToLower()));
                        if (files.Count() > 0)
                        {
                            var oldSounds = BLLSound.Gets();
                            if (oldSounds.Count > 0)
                            {
                                foreach (var item in oldSounds)
                                {
                                    BLLSound.Delete(item.Id);
                                    if (!string.IsNullOrEmpty(item.Path))
                                    {
                                        item.Path = Application.StartupPath + @"\Sound\" + item.Path;
                                        if (File.Exists(item.Path))
                                        {
                                            File.Delete(item.Path);
                                        }
                                    }
                                }
                            }

                            var dtime = DateTime.Now;
                            int count = 0;
                            foreach (string f in files)
                            {
                                try
                                {
                                    var      sound   = new PMS.Data.SOUND();
                                    var      fi      = new FileInfo(f);
                                    string[] xxx     = f.Split('\\');
                                    string   tenFile = xxx[xxx.Length - 1];
                                    sound.Name = tenFile;
                                    string[] yyy  = tenFile.Split('.');
                                    string   type = yyy[yyy.Length - 1];
                                    tenFile    = tenFile.Replace("." + type, "");
                                    sound.Code = tenFile;
                                    var shortPath = (tenFile.Length > 17 ? tenFile.Substring(0, 17) : tenFile) + "_" + dtime.ToString("yyMMddhhmmss") + "." + type;
                                    shortPath = convertToUnSign(shortPath);

                                    string fullPath = Application.StartupPath + @"\Sound\" + shortPath;
                                    File.Copy(f, fullPath);

                                    sound.Description = "Tệp được Thêm tự động";
                                    sound.Path        = shortPath;
                                    sound.IsActive    = true;
                                    sound.IsDeleted   = false;
                                    BLLSound.CreateOrUpdate(sound);
                                    count++;
                                }
                                catch (Exception)
                                {
                                }
                            }
                            LoadDataToGridView();
                            MessageBox.Show("Đã thêm " + count + " Tệp âm thanh thành công.", "Thông Báo");
                        }
                        else
                        {
                            MessageBox.Show("Không tìm thấy tệp Âm Thanh trong thư mục bạn vừa chọn.", "Thông Báo");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }