private ProductFileModel[] ConvertFiles(IProductType productType, IEnumerable <PropertyInfo> properties)
        {
            var productFileProperties = properties.Where(p => p.PropertyType == typeof(ProductFile)).ToArray();
            var fileModels            = new ProductFileModel[productFileProperties.Length];

            for (int i = 0; i < fileModels.Length; i++)
            {
                var value = (ProductFile)productFileProperties[i].GetValue(productType);
                fileModels[i] = new ProductFileModel()
                {
                    PropertyName = productFileProperties[i].Name,
                    FileName     = value?.Name,
                    FileHash     = value?.FileHash,
                    FilePath     = value?.FilePath,
                    MimeType     = value?.MimeType
                };
            }
            return(fileModels);
        }
Beispiel #2
0
        void createProductVersion(ProductsModel product, string reason)
        {
            ProcessTransaction pt = new ProcessTransaction();

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

            try
            {
                #region Tạo phiên bản san phẩm
                ProductVersionModel versionModel = new ProductVersionModel();
                versionModel.ProductID = product.ID;
                versionModel.Reason    = reason;
                versionModel.Version   = product.Version + 1;
                versionModel.ID        = (int)pt.Insert(versionModel);
                #endregion

                #region Tạo phiên bản bài thực hành của sản phẩm
                ArrayList lisBaiThucHanh = ProductBaiThucHanhLinkBO.Instance.FindByAttribute("ProductID", product.ID);
                if (lisBaiThucHanh.Count > 0)
                {
                    foreach (var item in lisBaiThucHanh)
                    {
                        ProductBaiThucHanhLinkModel thisBTH = (ProductBaiThucHanhLinkModel)item;

                        ProductBaiThucHanhLinkVersionModel bthVersion = new ProductBaiThucHanhLinkVersionModel();
                        bthVersion.ProductVersionID = versionModel.ID;
                        bthVersion.BaiThucHanhID    = thisBTH.BaiThucHanhID;
                        bthVersion.ID = (int)pt.Insert(bthVersion);
                    }
                }
                #endregion

                #region Tạo các phiên bản module sản phẩm
                ArrayList lisModules = ProductModuleLinkBO.Instance.FindByAttribute("ProductID", product.ID);
                if (lisModules.Count > 0)
                {
                    foreach (var item in lisModules)
                    {
                        ProductModuleLinkModel thisModule = (ProductModuleLinkModel)item;

                        ProductModuleLinkVersionModel moduleVersion = new ProductModuleLinkVersionModel();
                        moduleVersion.ProductVersionID = 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    = ProductFileBO.Instance.FindByExpression(new Expression("ProductID", product.ID)
                                                                                     .And(new Expression("Version", product.Version)));

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

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

                    ProductFileModel file = new ProductFileModel();
                    file.ProductID = product.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

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

                pt.CommitTransaction();

                MessageBox.Show("Tạo phiên bản bài thực hành thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);

                foreach (string filePath in listFilePath)
                {
                    if (!DocUtils.CheckExits(ftpFolderPath))
                    {
                        DocUtils.MakeDir(ftpFolderPath);
                    }
                    DocUtils.UploadFile(filePath, ftpFolderPath);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                pt.CloseConnection();
            }
        }
Beispiel #3
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();
            }
        }
        public List <ProductFileModel> GetProductFiles(int orderItemID, string stateId, string pType, int ccId, string webPlatform = "NOP")
        {
            var environment = getEnvironment();
            List <ProductFileModel> productFiles = new List <ProductFileModel>();

            webPlatform = webPlatform.ToUpper();
            switch (webPlatform)
            {
            case "NOP":
            {
                Dictionary <string, Object> paramDicEx = new Dictionary <string, Object>();
                paramDicEx.Add("@nopOrderItemID", orderItemID);

                DBManager manager = new DBManager();
                string    select  = "EXEC usp_getTblNOPProductionFiles_byOrderItemId @nopOrderItemID";
                DataView  result  = manager.GetParameterizedDataView(select, paramDicEx);

                if (result.Count > 0)
                {
                    foreach (DataRowView row in result)
                    {
                        ProductFileModel file = new ProductFileModel();
                        file.product.productType        = (string)row["ProductType"];
                        file.product.productionFileName = (string)row["FileName"];
                        if (pType == file.product.productType)
                        {
                            productFiles.Add(file);
                        }
                    }
                    var     design    = _ccService.GetDesign(ccId);
                    dynamic hiResUrls = JsonConvert.DeserializeObject <Object>(design.DownloadUrlsJson);
                    foreach (ProductFileModel productFile in productFiles.ToList())
                    {
                        //rules will change per product type
                        switch (productFile.product.productType)
                        {
                        case "notecard":
                            if (pType != "notecard")
                            {
                                productFiles.Remove(productFile);
                                break;
                            }
                            foreach (string url in hiResUrls)
                            {
                                var urlStateId = url.Split('/')[url.Split('/').Count() - 2];
                                if (urlStateId != stateId)
                                {
                                    continue;
                                }
                                var index      = url.Split('/').Last <string>().Split('_').First <string>();
                                var fileMiddle = productFile.product.productionFileName.Split('-')[1];
                                switch (index)
                                {
                                case "0":
                                    //front
                                    if (fileMiddle.StartsWith("CF"))
                                    {
                                        productFile.product.hiResPDFURL = url;
                                    }
                                    break;

                                case "1":
                                    //greeting
                                    if (fileMiddle.StartsWith("G"))
                                    {
                                        productFile.product.hiResPDFURL = url;
                                    }
                                    break;

                                case "2":
                                    //back
                                    if (fileMiddle.StartsWith("CB"))
                                    {
                                        productFile.product.hiResPDFURL = url;
                                    }
                                    break;
                                }
                            }
                            break;

                        case "envelope":
                            if (pType != "envelope")
                            {
                                productFiles.Remove(productFile);
                                break;
                            }
                            foreach (string url in hiResUrls)
                            {
                                var urlStateId = url.Split('/')[url.Split('/').Count() - 2];
                                if (urlStateId != stateId)
                                {
                                    continue;
                                }
                                var index      = url.Split('/').Last <string>().Split('_').First <string>();
                                var fileMiddle = productFile.product.productionFileName.Split('-')[1];
                                if (fileMiddle[0] != 'E')
                                {
                                    continue;
                                }
                                switch (index)
                                {
                                case "0":
                                    //front
                                    if (fileMiddle[2] == 'F')
                                    {
                                        productFile.product.hiResPDFURL = url;
                                    }
                                    break;

                                case "1":
                                    //back
                                    if (fileMiddle[2] == 'B')
                                    {
                                        productFile.product.hiResPDFURL = url;
                                    }
                                    break;
                                }
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
                else
                {
                    throw new Exception("Can't find production files for order item - " + orderItemID);
                }
                break;
            }

            default:
            {
                Dictionary <string, Object> paramDicEx = new Dictionary <string, Object>();
                paramDicEx.Add("@OPID", orderItemID);

                DBManager manager         = new DBManager(_gbsOrderSettings.HOMConnectionString);
                string    select          = "EXEC usp_getCanvasStateFileInfo @OPID";
                DataView  orderItemResult = manager.GetParameterizedDataView(select, paramDicEx);
                if (orderItemResult.Count > 0)
                {
                    foreach (DataRowView row in orderItemResult)
                    {
                        ProductFileModel file = new ProductFileModel();
                        file.product.productionFileName = (string)row["frontFile"];
                        if (row["hiResUrlFront"] != System.DBNull.Value)
                        {
                            var ub = new UriBuilder(new Uri((string)row["hiResUrlFront"]));
                            ub.Scheme = "https";
                            file.product.hiResPDFURL = ub.Uri.AbsoluteUri;
                        }
                        if (file.product.productionFileName != "not saved")
                        {
                            productFiles.Add(file);
                        }
                        ;
                        file = new ProductFileModel();
                        file.product.productionFileName = (string)row["backFile"];
                        if (row["hiResUrlBack"] != System.DBNull.Value)
                        {
                            var ub = new UriBuilder(new Uri((string)row["hiResUrlBack"]));
                            ub.Scheme = "https";
                            file.product.hiResPDFURL = ub.Uri.AbsoluteUri;
                        }
                        if (file.product.productionFileName != "not saved")
                        {
                            productFiles.Add(file);
                        }
                        ;
                    }
                }
                else
                {
                    throw new Exception("Can't find order item - " + orderItemID);
                }

                break;
            }
            }
            return(productFiles);
        }
Beispiel #5
0
 protected ProductFileFacade(ProductFileModel model) : base(model)
 {
 }