示例#1
0
        private void SaveVideo()
        {
            try
            {
                if (dlg != null && !string.IsNullOrEmpty(dlg.FileName))
                {
                    var      dtime = DateTime.Now;
                    var      f = dlg.FileName;
                    var      video = new P_VideoLibrary();
                    var      fi = new FileInfo(f);
                    string[] xxx = f.Split('\\');
                    string   tenFile = xxx[xxx.Length - 1], fullPath = "";

                    string[] yyy  = tenFile.Split('.');
                    string   type = yyy[yyy.Length - 1];
                    tenFile = tenFile.Replace("." + type, "");

                    var shortPath = (tenFile.Length > 17 ? tenFile.Substring(0, 17) : tenFile) + "_" + dtime.ToString("yyMMddhhmmss") + "." + type;
                    shortPath = convertToUnSign(shortPath);

                    if (!Directory.Exists(UrlSaveMediaFile))
                    {
                        Directory.CreateDirectory(UrlSaveMediaFile);
                    }
                    fullPath = UrlSaveMediaFile + shortPath;

                    File.Copy(f, fullPath);

                    video.Name      = txtName_v.Text;
                    video.Type      = fi.Extension;
                    video.Length    = 0;
                    video.Size      = fi.Length;
                    video.Path      = shortPath;
                    video.IsDeleted = false;
                    var result = BLLVideoLibrary.CreateOrUpdate(video);


                    //var video = new P_VideoLibrary();
                    //var fi = new FileInfo(f);
                    //string[] xxx = f.Split('\\');
                    //string tenFile = xxx[xxx.Length - 1];
                    //video.Name = tenFile;
                    //string[] yyy = tenFile.Split('.');
                    //string type = yyy[yyy.Length - 1];
                    //tenFile = tenFile.Replace("." + type, "");
                    //video.Type = fi.Extension;
                    //video.Length = 0;
                    //video.Size = fi.Length;

                    //var shortPath = (tenFile.Length > 17 ? tenFile.Substring(0, 17) : tenFile) + "_" + dtime.ToString("yyMMddhhmmss") + "." + type;
                    //shortPath = convertToUnSign(shortPath);

                    //if (!Directory.Exists(UrlSaveMediaFile))
                    //    Directory.CreateDirectory(UrlSaveMediaFile);
                    //fullPath = UrlSaveMediaFile + shortPath;

                    //File.Copy(f, fullPath);

                    //video.Path = shortPath;
                    //video.IsDeleted = false;
                    //BLLVideoLibrary.CreateOrUpdate(video);


                    if (result.IsSuccess)
                    {
                        ResetVideoForm();
                        LoadVideoToGridView();
                    }
                    else
                    {
                        MessageBox.Show(result.Messages[0].msg, result.Messages[0].Title);
                    }
                }
                else
                {
                    MessageBox.Show("Vui lòng chọn tệp!.", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        private void btnAddMulti_v_Click(object sender, EventArgs e)
        {
            try
            {
                openVideoFileDialog.Filter      = "Video (*.mp4;*.MP4)" + "All files (*.*)|*.*";
                openVideoFileDialog.Multiselect = true;
                var folderResult = openVideoFileDialog.ShowDialog();
                if (folderResult == DialogResult.OK)
                {
                    var filterStr = "*.mp4,*.mp3";
                    var files     = openVideoFileDialog.FileNames;
                    if (files.Count() > 0)
                    {
                        var dtime = DateTime.Now;
                        int count = 0;
                        foreach (string f in files)
                        {
                            string fullPath = string.Empty;
                            try
                            {
                                var      video   = new P_VideoLibrary();
                                var      fi      = new FileInfo(f);
                                string[] xxx     = f.Split('\\');
                                string   tenFile = xxx[xxx.Length - 1];
                                video.Name = tenFile;
                                string[] yyy  = tenFile.Split('.');
                                string   type = yyy[yyy.Length - 1];
                                tenFile      = tenFile.Replace("." + type, "");
                                video.Type   = fi.Extension;
                                video.Length = 0;
                                video.Size   = fi.Length;

                                var shortPath = (tenFile.Length > 17 ? tenFile.Substring(0, 17) : tenFile) + "_" + dtime.ToString("yyMMddhhmmss") + "." + type;
                                shortPath = convertToUnSign(shortPath);

                                //if (!Directory.Exists(Application.StartupPath + @"\Media"))
                                //    Directory.CreateDirectory(Application.StartupPath + @"\Media");
                                //string fullPath = Application.StartupPath + @"\Media\" + shortPath;

                                if (!Directory.Exists(UrlSaveMediaFile))
                                {
                                    Directory.CreateDirectory(UrlSaveMediaFile);
                                }
                                fullPath = UrlSaveMediaFile + shortPath;

                                File.Copy(f, fullPath);

                                video.Path      = shortPath;
                                video.IsDeleted = false;
                                BLLVideoLibrary.CreateOrUpdate(video);
                                count++;
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message + "/n path: " + fullPath + " : " + UrlSaveMediaFile);
                            }
                        }
                        LoadVideoToGridView();
                        MessageBox.Show("Đã thêm " + count + " Tệp video thành công.", "Thông Báo");
                    }
                    else
                    {
                        MessageBox.Show("Không tìm thấy tệp video trong thư mục bạn vừa chọn.", "Thông Báo");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }