Esempio n. 1
0
        protected void UpdateData()
        {
            try
            {
                //Detect Empty Text
                if (this.txtProductName.Text == "")
                {
                    this.lblError.Text    = Localization.GetString("errEmptyName.Text", this.LocalResourceFile);
                    this.lblError.Visible = true;
                    return;
                }

                string strLead         = txtLead.Text;
                string strCode         = txtCode.Text;
                string strSummary      = txtSummary.Text;
                string straddRichInfo1 = txtaddRichInfo1.Text;
                string straddRichInfo2 = txtaddRichInfo2.Text;
                string straddRichInfo3 = txtaddRichInfo3.Text;
                string strWeight       = txtWeight.Text;
                double fWeight         = -1;
                if (!double.TryParse(strWeight, out fWeight))
                {
                    this.lblError.Text    = Localization.GetString("errFormatWeight.Text", this.LocalResourceFile);
                    this.lblError.Visible = true;
                    return;
                }
                int    iPrice   = -1;
                string strPrice = txtPrice.Text;
                if (!int.TryParse(strPrice, out iPrice))
                {
                    this.lblError.Text    = Localization.GetString("errFormatPrice.Text", this.LocalResourceFile);
                    this.lblError.Visible = true;
                    return;
                }
                int    iPriceOld   = -1;
                string strPriceOld = txtPriceOld.Text;
                if (!int.TryParse(strPriceOld, out iPriceOld))
                {
                    this.lblError.Text    = Localization.GetString("errFormatPriceOld.Text", this.LocalResourceFile);
                    this.lblError.Visible = true;
                    return;
                }
                int    iOrder   = -1;
                string strOrder = txtOrder.Text;
                if (!int.TryParse(strOrder, out iOrder))
                {
                    this.lblError.Text    = Localization.GetString("errFormatOrder.Text", this.LocalResourceFile);
                    this.lblError.Visible = true;
                    return;
                }

                string strStatusProduct = txtStatusProduct.Text;
                string straddInfo1      = txtaddInfo1.Text;
                string straddInfo2      = txtaddInfo2.Text;
                string straddInfo3      = txtaddInfo3.Text;
                string straddInfo4      = txtaddInfo4.Text;
                string straddInfo5      = txtaddInfo5.Text;
                string straddInfo6      = txtaddInfo6.Text;
                //Detect Role
                if (!((m_objRole.HasRole((int)Connection.UtilsProvider.CoreRole.Create) && m_ProductId == -1) || ((m_objRole.HasRole((int)Connection.UtilsProvider.CoreRole.EditAfter) || m_objRole.HasRole((int)Connection.UtilsProvider.CoreRole.EditAll)) && m_ProductId != -1)))
                {
                    this.lblError.Text = Localization.GetString("errNoRole.Text", this.LocalResourceFile);
                    //this.lblError.Text = m_objRole.HasRole((int)THCore.CoreRole.Create).ToString();
                    this.lblError.Visible = true;
                    return;
                }

                string strSmallimage = "";
                string strLargeimage = "";

                string strImageAdd1 = "";
                string strImageAdd2 = "";
                string strImageAdd3 = "";

                string strFolderName = m_strCategories;

                strSmallimage = DNNRelatedProvider.GetFilePath(urlSmallImage.Url, this.PortalId);
                strLargeimage = DNNRelatedProvider.GetFilePath(urlLargeImage.Url, this.PortalId);
                strImageAdd1  = DNNRelatedProvider.GetFilePath(urlSmallImageImgAdd1.Url, this.PortalId);
                strImageAdd2  = DNNRelatedProvider.GetFilePath(urlSmallImageImgAdd2.Url, this.PortalId);
                strImageAdd3  = DNNRelatedProvider.GetFilePath(urlSmallImageImgAdd3.Url, this.PortalId);

                /*
                 * strFolderName = CategoryProvider.GetDefaultFolderPath(TH.Utils.UIProvider.GetListBoxSelectedItems(",", chkCategoryList), this.PortalId);
                 * if (strFolderName == "" || strFolderName == null || strFolderName.Length == 0)
                 * {
                 *  strFolderName = "Folder";
                 * }
                 * string strFolderPath = string.Format("{0}{1}", PortalSettings.HomeDirectoryMapPath, strFolderName);
                 * if (!System.IO.Directory.Exists(strFolderPath))
                 *  strFolderName = m_strFolderName;
                 #region
                 * if (txtSmallimage.PostedFile.FileName.Length != 0) //&& chkUseImage.Checked
                 * {
                 *  string strFileName = txtSmallimage.PostedFile.FileName.Substring(txtSmallimage.PostedFile.FileName.LastIndexOf(@"\") + 1);
                 *  strSmallimage = string.Format("{0}{1}", strFolderName, strFileName);
                 *  string strParentFolder = string.Format("{0}{1}", PortalSettings.HomeDirectoryMapPath, strFolderName);
                 *  FileSystemUtils.UploadFile(strParentFolder.Replace("/", @"\"), txtSmallimage.PostedFile, false);
                 *
                 * }
                 * if (strSmallimage == "")
                 *  strSmallimage = txtSmallimageOld.Text;
                 #endregion
                 #region
                 * if (txtLargeimage.PostedFile.FileName.Length != 0) //&& chkUseImage.Checked
                 * {
                 *  string strFileName = txtLargeimage.PostedFile.FileName.Substring(txtLargeimage.PostedFile.FileName.LastIndexOf(@"\") + 1);
                 *  strLargeimage = string.Format("{0}{1}", strFolderName, strFileName);
                 *  string strParentFolder = string.Format("{0}{1}", PortalSettings.HomeDirectoryMapPath, strFolderName);
                 *  FileSystemUtils.UploadFile(strParentFolder.Replace("/", @"\"), txtLargeimage.PostedFile, false);
                 * }
                 *
                 * if (strLargeimage == "")
                 *  strLargeimage = txtLargeimageOld.Text;
                 #endregion
                 #region imageAdd1
                 *
                 * if (txtAddImage1.PostedFile.FileName.Length != 0) //&& chkUseImage.Checked
                 * {
                 *  string strFileName = txtAddImage1.PostedFile.FileName.Substring(txtAddImage1.PostedFile.FileName.LastIndexOf(@"\") + 1);
                 *  strImageAdd1 = string.Format("{0}{1}", strFolderName, strFileName);
                 *  string strParentFolder = string.Format("{0}{1}", PortalSettings.HomeDirectoryMapPath, strFolderName);
                 *  FileSystemUtils.UploadFile(strParentFolder.Replace("/", @"\"), txtAddImage1.PostedFile, false);
                 * }
                 *
                 * if (strImageAdd1 == "")
                 *  strImageAdd1 = txtImageAdd1Old.Text;
                 #endregion
                 #region imageAdd2
                 *
                 * if (txtAddImage2.PostedFile.FileName.Length != 0) //&& chkUseImage.Checked
                 * {
                 *  string strFileName = txtAddImage2.PostedFile.FileName.Substring(txtAddImage2.PostedFile.FileName.LastIndexOf(@"\") + 1);
                 *  strImageAdd2 = string.Format("{0}{1}", strFolderName, strFileName);
                 *  string strParentFolder = string.Format("{0}{1}", PortalSettings.HomeDirectoryMapPath, strFolderName);
                 *  FileSystemUtils.UploadFile(strParentFolder.Replace("/", @"\"), txtAddImage2.PostedFile, false);
                 * }
                 *
                 * if (strImageAdd2 == "")
                 *  strImageAdd2 = txtImageAdd2Old.Text;
                 #endregion
                 #region imageAdd3
                 *
                 * if (txtAddImage3.PostedFile.FileName.Length != 0) //&& chkUseImage.Checked
                 * {
                 *  string strFileName = txtAddImage3.PostedFile.FileName.Substring(txtAddImage3.PostedFile.FileName.LastIndexOf(@"\") + 1);
                 *  strImageAdd3 = string.Format("{0}{1}", strFolderName, strFileName);
                 *  string strParentFolder = string.Format("{0}{1}", PortalSettings.HomeDirectoryMapPath, strFolderName);
                 *  FileSystemUtils.UploadFile(strParentFolder.Replace("/", @"\"), txtAddImage3.PostedFile, false);
                 * }
                 *
                 * if (strImageAdd3 == "")
                 *  strImageAdd3 = txtImageAdd3Old.Text;
                 #endregion
                 */
                DateTime ProducedDate;

                ProducedDate = DateTime.ParseExact(txtProducedDate.Text, "dd/MM/yyyy", null);

                DateTime ExpiredDate;
                ExpiredDate = DateTime.ParseExact(txtExpiredDate.Text, "dd/MM/yyyy", null);


                DateTime DisplayDate;
                if (txtDisplayDate.Text == "")
                {
                    DisplayDate = DateTime.Today;
                }
                else
                {
                    DisplayDate = DateTime.ParseExact(txtDisplayDate.Text, "dd/MM/yyyy", null);
                }
                DisplayDate.AddHours(DateTime.Now.Hour);
                DisplayDate.AddMinutes(DateTime.Now.Minute);
                DisplayDate.AddSeconds(DateTime.Now.Second);
                // Get Hot Period
                int intPeriod;
                if (!int.TryParse(this.txtHotPeriod.Text, out intPeriod))
                {
                    intPeriod = 0;
                }
                // DyncmicForm
                string strExtendedSettings = GetValueDynamic(strFolderName);

                m_strCategories = UIProvider.GetListBoxSelectedItems(",", chkCategoryList);
                m_strTags       = UIProvider.GetListBoxSelectedItems(",", chkTags);
                if (m_strCategories.Equals(""))
                {
                    this.lblError.Text    = "Chưa chọn chuyên mục";
                    this.lblError.Visible = true;
                    return;
                }

                //Going into action.
                int result = 1;

                if (m_ProductId == -1)
                {
                    string realProductName = "";
                    realProductName = DataProcessingProvider.RemoveTags(this.txtProductName.Text);
                    result          = ProductProvider.InsertProduct(realProductName, strLead, DataProcessingProvider.RemoveTags(strSummary), strSmallimage, strLargeimage, fWeight, DateTime.Now, ExpiredDate, DateTime.Now, ProducedDate, true, false, chkIsHot.Checked, intPeriod, this.UserId, this.PortalId, false, iPrice, iPriceOld, strStatusProduct, strExtendedSettings, iOrder, m_strCategories, strCode, strImageAdd1, strImageAdd2, strImageAdd3, DisplayDate, straddInfo1, straddInfo2, straddInfo3, straddInfo4, straddInfo5, straddInfo6, DataProcessingProvider.RemoveTags(straddRichInfo1), DataProcessingProvider.RemoveTags(straddRichInfo2), DataProcessingProvider.RemoveTags(straddRichInfo3), m_strTags, 1);

                    if (result > 0)
                    {
                        #region danh dau them moi


                        try
                        {
                            File.WriteAllText(Server.MapPath("/DesktopModules/TH.NUCE.Utils/Configuration/ResetCache.txt"), "1");
                            File.WriteAllText(Server.MapPath("/DesktopModules/TH.NUCE.Utils/Configuration/ResetCache_" + this.PortalId + ".txt"), "1");
                        }
                        catch (Exception ex)
                        {
                        }


                        #endregion

                        LogProvider.InsertLogAction(result, ProductProvider.TypeId, "", this.PortalId, (int)Connection.UtilsProvider.LogAction.Create, this.UserInfo.Username, this.UserId, this.txtProductName.Text, true, m_strCategories);
                    }
                }
                else
                {
                    DateTime CreateDate = DateTime.Parse(txtCreatedDateOld.Text);
                    string   realTitle  = "";
                    realTitle = DataProcessingProvider.RemoveTags(this.txtProductName.Text);
                    ProductProvider.UpdateProduct(m_ProductId, realTitle, strLead, DataProcessingProvider.RemoveTags(strSummary), strSmallimage, strLargeimage, fWeight, CreateDate, ExpiredDate, DateTime.Now, ProducedDate, true, false, chkIsHot.Checked, intPeriod, this.UserId, this.PortalId, false, iPrice, iPriceOld, strStatusProduct, iOrder, strExtendedSettings, m_strCategories, strCode, strImageAdd1, strImageAdd2, strImageAdd3, DisplayDate, straddInfo1, straddInfo2, straddInfo3, straddInfo4, straddInfo5, straddInfo6, DataProcessingProvider.RemoveTags(straddRichInfo1), DataProcessingProvider.RemoveTags(straddRichInfo2), DataProcessingProvider.RemoveTags(straddRichInfo3), m_strTags, 1);
                    result = m_ProductId;
                    if (result > 0)
                    {
                        #region danh dau them moi


                        try
                        {
                            File.WriteAllText(Server.MapPath("/DesktopModules/TH.NUCE.Utils/Configuration/ResetCache.txt"), "1");
                            File.WriteAllText(Server.MapPath("/DesktopModules/TH.NUCE.Utils/Configuration/ResetCache_" + this.PortalId + ".txt"), "1");
                        }
                        catch (Exception ex)
                        {
                        }


                        #endregion

                        LogProvider.InsertLogAction(result, ProductProvider.TypeId, "", this.PortalId, (int)Connection.UtilsProvider.LogAction.Update, this.UserInfo.Username, this.UserId, this.txtProductName.Text, true, m_strCategories);
                    }
                }


                if (result == -2)
                {
                    this.lblError.Text    = Localization.GetString("errSameName.Text", this.LocalResourceFile);
                    this.lblError.Visible = true;
                }
                else if (result <= 0)
                {
                    this.lblError.Text    = Localization.GetString("errSomeError.Text", this.LocalResourceFile);
                    this.lblError.Visible = true;
                }
                else
                {
                    JumpBack(false, result);
                }
            }
            catch (Exception ex)
            {
                //this.lblError.Text = ex.GetType().ToString();
                this.lblError.Text    = ex.ToString();
                this.lblError.Visible = true;
            }
        }
Esempio n. 2
0
        public void ProductBinding()
        {
            DataTable objTableData = ProductProvider.GetProduct(m_ProductId);

            if (objTableData.Rows.Count > 0)
            {
                lblError.Text            = "Cập nhật sản phẩm";
                this.txtProductName.Text = txtProductNameOld.Text = objTableData.Rows[0]["ProductName"].ToString();
                this.txtCode.Text        = txtProductNameOld.Text = objTableData.Rows[0]["Code"].ToString();
                string strImageAdd1 = objTableData.Rows[0]["ImageAdd1"].ToString();
                string strImageAdd2 = objTableData.Rows[0]["ImageAdd2"].ToString();
                string strImageAdd3 = objTableData.Rows[0]["ImageAdd3"].ToString();
                urlSmallImageImgAdd1.Url = strImageAdd1;
                urlSmallImageImgAdd2.Url = strImageAdd2;
                urlSmallImageImgAdd3.Url = strImageAdd3;
                txtImageAdd1Old.Text     = strImageAdd1;
                txtImageAdd2Old.Text     = strImageAdd2;
                txtImageAdd3Old.Text     = strImageAdd3;
                string strSmallImage = objTableData.Rows[0]["Smallimage"].ToString();
                txtSmallimageOld.Text = strSmallImage;
                urlSmallImage.Url     = strSmallImage;
                string strLargeimage = objTableData.Rows[0]["Largeimage"].ToString();
                txtLargeimageOld.Text  = strLargeimage;
                urlLargeImage.Url      = strLargeimage;
                txtCreatedDateOld.Text = objTableData.Rows[0]["CreatedDate"].ToString();

                //this.imgImageFile.Src = string.Format("/Portals/{0}/{1}", this.PortalId, m_strOldImagePath);
                //spImageFile.InnerHtml = m_strOldImagePath;
                if (strImageAdd1.Contains("Portals"))
                {
                    this.imgAdd1.Src = strImageAdd1;
                }
                else
                {
                    this.imgAdd1.Src = string.Format("/Portals/{0}/{1}", this.PortalId, strImageAdd1);
                }
                if (strImageAdd2.Contains("Portals"))
                {
                    this.imgAdd2.Src = strImageAdd2;
                }
                else
                {
                    this.imgAdd2.Src = string.Format("/Portals/{0}/{1}", this.PortalId, strImageAdd2);
                }
                if (strImageAdd3.Contains("Portals"))
                {
                    this.imgAdd3.Src = strImageAdd3;
                }
                else
                {
                    this.imgAdd3.Src = string.Format("/Portals/{0}/{1}", this.PortalId, strImageAdd3);
                }
                this.spImgAdd1.InnerHtml = strImageAdd1;
                this.spImgAdd2.InnerHtml = strImageAdd2;
                this.spImgAdd3.InnerHtml = strImageAdd3;
                if (strSmallImage.Contains("Portals"))
                {
                    this.imgSmallImage.Src = strSmallImage;
                }
                else
                {
                    this.imgSmallImage.Src = string.Format("/Portals/{0}/{1}", this.PortalId, strSmallImage);
                }
                this.spSmallImage.InnerHtml = strSmallImage;
                if (strLargeimage.Contains("Portals"))
                {
                    this.imgLargeimage.Src = strLargeimage;
                }
                else
                {
                    this.imgLargeimage.Src = string.Format("/Portals/{0}/{1}", this.PortalId, strLargeimage);
                }
                spLargeimage.InnerHtml = strLargeimage;

                txtLead.Text = objTableData.Rows[0]["Lead"].ToString();

                txtSummary.Text       = objTableData.Rows[0]["Summary"].ToString();
                txtWeight.Text        = objTableData.Rows[0]["Weight"].ToString();
                txtPrice.Text         = objTableData.Rows[0]["Price"].ToString();
                txtPriceOld.Text      = objTableData.Rows[0]["PriceOld"].ToString();
                txtStatusProduct.Text = objTableData.Rows[0]["StatusProduct"].ToString();
                txtaddInfo1.Text      = objTableData.Rows[0]["AddInfo1"].ToString();
                txtaddInfo2.Text      = objTableData.Rows[0]["AddInfo2"].ToString();
                txtaddInfo3.Text      = objTableData.Rows[0]["AddInfo3"].ToString();

                txtaddInfo4.Text = objTableData.Rows[0]["AddInfo4"].ToString();
                txtaddInfo5.Text = objTableData.Rows[0]["AddInfo5"].ToString();
                txtaddInfo6.Text = objTableData.Rows[0]["AddInfo6"].ToString();

                txtaddRichInfo1.Text = objTableData.Rows[0]["AddRichInfo1"].ToString();
                txtaddRichInfo2.Text = objTableData.Rows[0]["AddRichInfo2"].ToString();
                txtaddRichInfo3.Text = objTableData.Rows[0]["AddRichInfo3"].ToString();

                txtOrder.Text             = objTableData.Rows[0]["Order"].ToString();
                this.txtProducedDate.Text = DateTime.Parse(objTableData.Rows[0]["ProducedDate"].ToString()).ToString("dd/MM/yyyy");
                this.txtDisplayDate.Text  = DateTime.Parse(objTableData.Rows[0]["DisplayDate"].ToString()).ToString("dd/MM/yyyy");
                txtExpiredDate.Text       = DateTime.Parse(objTableData.Rows[0]["ExpiredDate"].ToString()).ToString("dd/MM/yyyy");

                if (objTableData.Rows[0]["IsHot"].ToString() == "False")
                {
                    this.chkIsHot.Checked = false;
                }
                else
                {
                    this.chkIsHot.Checked = true;
                }
                this.txtHotPeriod.Text = objTableData.Rows[0]["HotPeriod"].ToString();
                //Bind Dynamic Form
                string strExtendedSettings = objTableData.Rows[0]["ExtendedSettings"].ToString();
                dtValue = new DataTable();
                dtValue = XMLProvider.XmlString2DataTable(strExtendedSettings);
                try
                {
                    if (dtValue != null && dtValue.Rows.Count > 0)
                    {
                        BindingDynamicForm(dtValue);
                    }
                }
                catch (Exception ex)
                {
                    lblError.Text         = ex.Message;
                    this.lblError.Visible = true;
                }
            }
        }