// Update mới thông tin một News... private void Update() { try { int intProductID = int.Parse(txtID.Text.Trim()); int TypeProduct = int.Parse(CboTypeProduct.SelectedValue); string NameProduct = CommonClass.StringValidator.GetSafeString(txtNameProduct.Text.Trim()); string NameProductEL = CommonClass.StringValidator.GetSafeString(txtNameProductEL.Text.Trim()); string ShortDescription = txtShortDescription.Text.Trim(); string ShortDescriptionEL = txtShortDescriptionEL.Text.Trim(); string Description = txtContent.Text.Trim(); string strPathImages = txtPathImages.Text.Trim(); int intPrice = int.Parse(txtPrice.Text.Trim()); int intPriceNew = int.Parse(txtPriceNew.Text.Trim()); string strStatus = txtStatus.Text.Trim(); string strStatusEL = txtStatusEL.Text.Trim(); //Khi Admin tiến hành đổi hình ảnh if (FileUpload1.Visible == true) { strPathImages = "~/Images/ImgNews/defaultimage.GIF"; if (!string.IsNullOrEmpty(FileUpload1.FileName) && CheckExtention(FileUpload1) == true) { Sycomore.UploadFile Upload = new Sycomore.UploadFile(); Upload.StrFileName = FileUpload1.FileName; Upload.StrFolder = Server.MapPath("~/Images/ImgNews/"); Upload.Upload(FileUpload1); strPathImages = "~/Images/ImgNews/" + Upload.StrFileName; } } string strPathImages1 = txtPathImages1.Text.Trim(); //Khi Admin tiến hành đổi hình ảnh if (FileUpload2.Visible == true) { strPathImages1 = "~/Images/ImgNews/defaultimage.GIF"; if (!string.IsNullOrEmpty(FileUpload2.FileName) && CheckExtention(FileUpload2) == true) { Sycomore.UploadFile Upload = new Sycomore.UploadFile(); Upload.StrFileName = FileUpload2.FileName; Upload.StrFolder = Server.MapPath("~/Images/ImgNews/"); Upload.Upload(FileUpload2); strPathImages1 = "~/Images/ImgNews/" + Upload.StrFileName; } } DB.DB_Object.ClassProduct objClassData = new DB.DB_Object.ClassProduct(); if (objClassData.UpdateProduct(intProductID, TypeProduct, NameProduct, ShortDescription, Description, strPathImages, intPrice, intPriceNew, strStatus, strPathImages1, NameProductEL, ShortDescriptionEL, strStatusEL) == true) { Response.Redirect("~/Amincp/ManagerProduct.aspx"); } else { CommonClass.MessageBox.Show("Lỗi kết nối đến Server. Vui lòng kiểm tra hệ thống mạng!"); } } catch (Exception e) { SetErrorMessage(e.Message); } }
private void LoadOrtherProduct() { DB.DB_Object.ClassProduct objClassData = new DB.DB_Object.ClassProduct(); DataTable dt = objClassData.getDataProduct(); //Khởi tạo DataTable DataTable dtNew = new DataTable(); // create column DataColumn productId = new DataColumn("productId", Type.GetType("System.String")); DataColumn NameProduct = new DataColumn("NameProduct", Type.GetType("System.String")); DataColumn Price = new DataColumn("Price", Type.GetType("System.String")); DataColumn Images = new DataColumn("Images", Type.GetType("System.String")); // add cloumn to table dtNew.Columns.Add(productId); dtNew.Columns.Add(NameProduct); dtNew.Columns.Add(Price); dtNew.Columns.Add(Images); int values = 0; int intFlag = 0; if (dt.Rows.Count > 0) { for (int w = 0; w < 6; w++) { Random rnd = new Random(); for (int i = 0; i <= dt.Rows.Count; i++) { values = rnd.Next(i); } if (dt.Rows.Count - values > 0) { for (int g = values; g < dt.Rows.Count; g++) { if (intFlag < 6) { AddRowsToDataTable(dt.Rows[g], dtNew); intFlag++; } } } else { for (int g = 0; g < 6; g++) { if (!string.IsNullOrEmpty(dt.Rows[g]["ProductID"].ToString())) { AddRowsToDataTable(dt.Rows[g], dtNew); } } } if (intFlag < 6) { for (int g = 0; g < 6; g++) { if (!string.IsNullOrEmpty(dt.Rows[g]["ProductID"].ToString())) { if (intFlag < 6) { AddRowsToDataTable(dt.Rows[g], dtNew); intFlag++; } } } } } } if (dtNew.Rows.Count > 0) { rptOrtherProduct.DataSource = dtNew; rptOrtherProduct.DataBind(); } }