Example #1
0
        void CreateVersion(BaiThucHanhModel BaiThucHanh)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();

            try
            {
                // Tạo phiên bản bài thực hành
                BaiThucHanhVersionModel versionModel = new BaiThucHanhVersionModel();
                versionModel.BaiThucHanhID = BaiThucHanh.ID;
                versionModel.Reason        = "Tạo phiên bản đầu tiên";
                versionModel.Version       = BaiThucHanh.Version;
                versionModel.ID            = (int)pt.Insert(versionModel);

                //Tạo các phiên bản module bài thực hành
                ArrayList lisModules = BaiThucHanhModuleBO.Instance.FindByAttribute("BaiThucHanhID", BaiThucHanh.ID);
                if (lisModules.Count > 0)
                {
                    foreach (var item in lisModules)
                    {
                        BaiThucHanhModuleModel thisModule = (BaiThucHanhModuleModel)item;

                        BaiThucHanhModuleVersionModel moduleVersion = new BaiThucHanhModuleVersionModel();
                        moduleVersion.BTHVersionID = versionModel.ID;
                        moduleVersion.Code         = thisModule.Code;
                        moduleVersion.CVersion     = thisModule.CVersion;
                        moduleVersion.Hang         = thisModule.Hang;
                        moduleVersion.Name         = thisModule.Name;
                        moduleVersion.Qty          = thisModule.Qty;
                        moduleVersion.Type         = thisModule.Type;
                        moduleVersion.ID           = (int)pt.Insert(moduleVersion);
                    }
                }

                pt.CommitTransaction();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                pt.CloseConnection();
            }
        }
Example #2
0
 protected BaiThucHanhVersionFacade(BaiThucHanhVersionModel model) : base(model)
 {
 }
Example #3
0
        void CreateVersion(BaiThucHanhModel BaiThucHanh, string reason)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();

            try
            {
                #region Tạo phiên bản bài thực hành
                BaiThucHanhVersionModel versionModel = new BaiThucHanhVersionModel();
                versionModel.BaiThucHanhID = BaiThucHanh.ID;
                versionModel.Reason        = reason;
                versionModel.Version       = BaiThucHanh.Version + 1;
                versionModel.ID            = (int)pt.Insert(versionModel);
                #endregion

                #region Tạo các phiên bản module bài thực hành
                ArrayList lisModules = BaiThucHanhModuleBO.Instance.FindByAttribute("BaiThucHanhID", BaiThucHanh.ID);
                if (lisModules.Count > 0)
                {
                    foreach (var item in lisModules)
                    {
                        BaiThucHanhModuleModel thisModule = (BaiThucHanhModuleModel)item;

                        BaiThucHanhModuleVersionModel moduleVersion = new BaiThucHanhModuleVersionModel();
                        moduleVersion.BTHVersionID = versionModel.ID;
                        moduleVersion.Code         = thisModule.Code;
                        moduleVersion.CVersion     = thisModule.CVersion;
                        moduleVersion.Hang         = thisModule.Hang;
                        moduleVersion.Name         = thisModule.Name;
                        moduleVersion.Qty          = thisModule.Qty;
                        moduleVersion.Type         = thisModule.Type;
                        moduleVersion.ID           = (int)pt.Insert(moduleVersion);
                    }
                }
                #endregion

                #region Tạo phiên bản các file
                List <string> listFilePath = new List <string>();
                ArrayList     listFiles    = BaiThucHanhFileBO.Instance.FindByExpression(new Expression("BaiThucHanhID", BaiThucHanh.ID)
                                                                                         .And(new Expression("Version", BaiThucHanh.Version)));

                string ftpFolderPath = "BieuMau\\BaiThucHanh\\" + BaiThucHanh.Code + "\\" + versionModel.Version;
                if (!DocUtils.CheckExits(Path.GetDirectoryName(ftpFolderPath)))
                {
                    DocUtils.MakeDir(Path.GetDirectoryName(ftpFolderPath));
                }
                foreach (var item in listFiles)
                {
                    BaiThucHanhFileModel thisFile = (BaiThucHanhFileModel)item;
                    string path = Path.GetTempPath();

                    DocUtils.DownloadFile(path, Path.GetFileName(thisFile.Path), thisFile.Path);

                    BaiThucHanhFileModel file = new BaiThucHanhFileModel();
                    file.BaiThucHanhID = BaiThucHanh.ID;
                    file.Name          = thisFile.Name;
                    file.Length        = thisFile.Length;
                    file.LocalPath     = path + "\\" + Path.GetFileName(thisFile.Path);
                    file.Path          = ftpFolderPath + "\\" + file.Name;
                    file.Version       = versionModel.Version;

                    pt.Insert(file);

                    listFilePath.Add(path + "\\" + Path.GetFileName(thisFile.Path));
                }
                #endregion

                BaiThucHanh.Version += 1;
                pt.Update(BaiThucHanh);

                pt.CommitTransaction();

                foreach (string filePath in listFilePath)
                {
                    if (!DocUtils.CheckExits(ftpFolderPath))
                    {
                        DocUtils.MakeDir(ftpFolderPath);
                    }
                    DocUtils.UploadFile(filePath, ftpFolderPath);
                }

                MessageBox.Show("Tạo phiên bản bài thực hành thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                pt.CloseConnection();
            }
        }