示例#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();
            }
        }
示例#2
0
 protected BaiThucHanhModuleFacade(BaiThucHanhModuleModel model) : base(model)
 {
 }
示例#3
0
        void save(bool close)
        {
            bool isAdd            = false;
            ProcessTransaction pt = new ProcessTransaction();

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

            try
            {
                if (!ValidateForm())
                {
                    return;
                }

                BaiThucHanh.GroupID = TextUtils.ToInt(cboGroup.EditValue);

                BaiThucHanh.Name        = txtName.Text.Trim().ToUpper();
                BaiThucHanh.Code        = txtCode.Text.Trim().ToUpper();
                BaiThucHanh.Description = txtDescription.Text.Trim();

                BaiThucHanh.Time = TextUtils.ToDecimal(txtTime.Text.Trim());

                BaiThucHanh.RealPrice  = TextUtils.ToDecimal(txtRealPrice.Text.Trim());
                BaiThucHanh.TradePrice = TextUtils.ToDecimal(txtTradePrice.Text.Trim());
                BaiThucHanh.UserPrice  = TextUtils.ToDecimal(txtUserPrice.Text.Trim());

                if (BaiThucHanh.ID == 0)
                {
                    isAdd = true;
                    BaiThucHanh.Version = 0;
                    BaiThucHanh.ID      = (int)pt.Insert(BaiThucHanh);
                }
                else
                {
                    DialogResult result = MessageBox.Show("Bạn có muốn tạo phiên bản cho bài thực hành này trước khi ghi?", TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        string           reason = "";
                        frmVersionReason frm    = new frmVersionReason();
                        if (frm.ShowDialog() == DialogResult.OK)
                        {
                            reason = frm.Reason;
                            CreateVersion(BaiThucHanh, reason);
                        }
                    }
                    pt.Update(BaiThucHanh);
                }

                #region Module chính
                for (int i = 0; i < grvModule.RowCount; i++)
                {
                    int id = TextUtils.ToInt(grvModule.GetRowCellValue(i, colMID));
                    BaiThucHanhModuleModel link;
                    if (id == 0)
                    {
                        link = new BaiThucHanhModuleModel();
                    }
                    else
                    {
                        link = (BaiThucHanhModuleModel)BaiThucHanhModuleBO.Instance.FindByPK(id);
                    }

                    link.BaiThucHanhID = BaiThucHanh.ID;
                    link.Hang          = grvModule.GetRowCellValue(i, colMHang).ToString();
                    link.Code          = grvModule.GetRowCellValue(i, colMCode).ToString();
                    link.Name          = grvModule.GetRowCellValue(i, colMName).ToString();
                    link.Qty           = TextUtils.ToInt(grvModule.GetRowCellValue(i, colMQty));
                    link.Type          = 0;
                    link.CVersion      = TextUtils.ToInt(grvModule.GetRowCellValue(i, colMCVersion));

                    if (id == 0)
                    {
                        link.ID = (int)pt.Insert(link);
                    }
                    else
                    {
                        pt.Update(link);
                    }
                }
                #endregion

                #region Vật tư phụ
                for (int i = 0; i < grvVT.RowCount; i++)
                {
                    int id = TextUtils.ToInt(grvVT.GetRowCellValue(i, colMaID));
                    BaiThucHanhModuleModel link;
                    if (id == 0)
                    {
                        link = new BaiThucHanhModuleModel();
                    }
                    else
                    {
                        link = (BaiThucHanhModuleModel)BaiThucHanhModuleBO.Instance.FindByPK(id);
                    }

                    link.BaiThucHanhID = BaiThucHanh.ID;
                    link.Hang          = grvVT.GetRowCellValue(i, colMaHang).ToString();
                    link.Code          = grvVT.GetRowCellValue(i, colMaCode).ToString();
                    link.Name          = grvVT.GetRowCellValue(i, colMaName).ToString();
                    link.Qty           = TextUtils.ToInt(grvVT.GetRowCellValue(i, colMaQty));
                    link.Type          = 1;
                    link.CVersion      = TextUtils.ToInt(grvVT.GetRowCellValue(i, colMaCVersion));

                    if (id == 0)
                    {
                        pt.Insert(link);
                    }
                    else
                    {
                        pt.Update(link);
                    }
                }
                #endregion

                #region File
                string ftpFolderPath = "BieuMau\\BaiThucHanh\\" + BaiThucHanh.Code + "\\" + BaiThucHanh.Version;
                if (!DocUtils.CheckExits(Path.GetDirectoryName(ftpFolderPath)))
                {
                    DocUtils.MakeDir(Path.GetDirectoryName(ftpFolderPath));
                }
                List <string> listFilePath = new List <string>();
                for (int i = 0; i < grvFile.RowCount; i++)
                {
                    int id = TextUtils.ToInt(grvFile.GetRowCellValue(i, colFileID));
                    if (id == 0)
                    {
                        BaiThucHanhFileModel file = new BaiThucHanhFileModel();
                        file.BaiThucHanhID = BaiThucHanh.ID;
                        file.Name          = grvFile.GetRowCellValue(i, colFileName).ToString();
                        file.Length        = TextUtils.ToDecimal(grvFile.GetRowCellValue(i, colFileSize).ToString());
                        file.LocalPath     = grvFile.GetRowCellValue(i, colFileLocalPath).ToString();
                        file.Path          = ftpFolderPath + "\\" + Path.GetFileName(file.LocalPath);
                        file.Version       = BaiThucHanh.Version;

                        pt.Insert(file);

                        listFilePath.Add(file.LocalPath);
                    }
                }
                #endregion

                pt.CommitTransaction();

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

                //if (isAdd)
                //{
                //    CreateVersion(BaiThucHanh);
                //}

                _isSaved = true;
                if (close)
                {
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    loadGridMaterial();
                    loadGridModule();
                    loadGridFile();
                    MessageBox.Show("Lưu trữ 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();
            }
        }
示例#4
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();
            }
        }