Пример #1
0
        private void btnCreateVersion_Click(object sender, EventArgs e)
        {
            int id = TextUtils.ToInt(grvData.GetFocusedRowCellValue(colID));

            if (id == 0)
            {
                return;
            }
            ProductsModel product = (ProductsModel)ProductsBO.Instance.FindByPK(id);

            DialogResult result = MessageBox.Show("Bạn có chắc muốn tạo phiên bản cho sản phẩm [" + product.Name + "] ?",
                                                  TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.No)
            {
                return;
            }

            string           reason = "";
            frmVersionReason frm    = new frmVersionReason();

            if (frm.ShowDialog() == DialogResult.OK)
            {
                reason = frm.Reason;
            }
            else
            {
                return;
            }

            createProductVersion(product, reason);

            loadGrid(true);
        }
Пример #2
0
        void save(bool close)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();
            bool isAdd = false;

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

                Product.ProductGroupID = TextUtils.ToInt(cboGroup.EditValue);

                Product.Name           = txtName.Text.Trim().ToUpper();
                Product.Code           = txtCode.Text.Trim().ToUpper();
                Product.Description    = txtDescription.Text.Trim();
                Product.Time           = TextUtils.ToDecimal(txtTime.Text.Trim());
                Product.Priod          = cboPriod.Text;
                Product.Specifications = txtThongSo.Text.Trim();

                if (Product.ID == 0)
                {
                    isAdd           = true;
                    Product.Version = 0;
                    Product.ID      = (int)pt.Insert(Product);
                }
                else
                {
                    DialogResult result = MessageBox.Show("Bạn có muốn tạo phiên bản cho sản phẩm 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;
                            createProductVersion1(Product, reason);
                        }
                    }
                    pt.Update(Product);
                }

                #region Bai thực hành
                for (int i = 0; i < grvBTH.RowCount; i++)
                {
                    if (TextUtils.ToInt(grvBTH.GetRowCellValue(i, colBID)) == 0)
                    {
                        continue;
                    }
                    try
                    {
                        int id = TextUtils.ToInt(grvBTH.GetRowCellValue(i, colID));
                        ProductBaiThucHanhLinkModel link;
                        if (id == 0)
                        {
                            link = new ProductBaiThucHanhLinkModel();
                        }
                        else
                        {
                            link = (ProductBaiThucHanhLinkModel)ProductBaiThucHanhLinkBO.Instance.FindByPK(id);
                        }

                        link.BaiThucHanhID = TextUtils.ToInt(grvBTH.GetRowCellValue(i, colBID));
                        link.ProductID     = Product.ID;

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

                #region Module
                //for (int i = 0; i < grvModule.RowCount; i++)
                //{
                //    if (TextUtils.ToInt(grvModule.GetRowCellValue(i, colModuleBTHID)) == 0) continue;
                //    try
                //    {
                //        int id = TextUtils.ToInt(grvModule.GetRowCellValue(i, colLinkID));
                //        ProductModuleLinkModel link;
                //        if (id == 0)
                //        {
                //            link = new ProductModuleLinkModel();
                //        }
                //        else
                //        {
                //            link = (ProductModuleLinkModel)ProductModuleLinkBO.Instance.FindByPK(id);
                //        }

                //        link.ProductID = Product.ID;
                //        link.BaiThucHanhID = TextUtils.ToInt(grvModule.GetRowCellValue(i, colModuleBTHID));
                //        link.ModuleCode = grvModule.GetRowCellValue(i, colModuleCode).ToString();

                //        if (id == 0)
                //        {
                //            pt.Insert(link);
                //        }
                //        else
                //        {
                //            pt.Update(link);
                //        }
                //    }
                //    catch
                //    {

                //    }
                //}
                #endregion

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

                    link.ProductID = Product.ID;
                    link.Hang      = grvModuleLink.GetRowCellValue(i, colMHang).ToString();
                    link.Code      = grvModuleLink.GetRowCellValue(i, colMCode).ToString();
                    link.Name      = grvModuleLink.GetRowCellValue(i, colMName).ToString();
                    link.Qty       = TextUtils.ToInt(grvModuleLink.GetRowCellValue(i, colMQty));
                    link.Type      = 0;
                    link.CVersion  = TextUtils.ToInt(grvModuleLink.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));
                    ProductModuleLinkModel link;
                    if (id == 0)
                    {
                        link = new ProductModuleLinkModel();
                    }
                    else
                    {
                        link = (ProductModuleLinkModel)ProductModuleLinkBO.Instance.FindByPK(id);
                    }

                    link.ProductID = Product.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 = "Product\\File\\" + Product.Code + "\\" + Product.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)
                    {
                        ProductFileModel file = new ProductFileModel();
                        file.ProductID = Product.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   = Product.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)
                //{
                //    createProductVersion(Product, "Tạo phiên bản đầu tiên");
                //}

                _isSaved = true;

                if (close)
                {
                    this.DialogResult = DialogResult.OK;
                }
                else
                {
                    loadBaiThucHanh();
                    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();
            }
        }
Пример #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();
            }
        }