public bool SaveImagesAttachAll() { T_Anh objimage = new T_Anh(); AnhDAL _dalanh = new AnhDAL(); int _ID = 0; if (dgrListImages.Items.Count > 0) { foreach (DataListItem m_Item in dgrListImages.Items) { _ID = Convert.ToInt32(dgrListImages.DataKeys[m_Item.ItemIndex].ToString()); TextBox txtTacgia = m_Item.FindControl("txtTacgia") as TextBox; TextBox hdnValueTacGiaAnh = m_Item.FindControl("hdnValueTacGiaAnh") as TextBox; TextBox txtChuthich = m_Item.FindControl("txtChuthich") as TextBox; if (_ID != 0) { objimage = _dalanh.GetOneFromT_AnhByID(_ID); string _chuthich = ""; string _tacgia = ""; int _tacgiaID = 0; if (txtChuthich.Text != Global.RM.GetString("Nhapchuthichanh")) { _chuthich = UltilFunc.RemoveEnterCode(txtChuthich.Text.Trim().Replace("'", "''")); } if (objimage != null && objimage.Ma_Nguoichup != 0) { _tacgia = txtTacgia.Text.Replace(" -- ", "|").Split('|')[0]; _tacgiaID = objimage.Ma_Nguoichup; } if (!String.IsNullOrEmpty(hdnValueTacGiaAnh.Text)) { _tacgia = txtTacgia.Text.Replace(" -- ", "|").Split('|')[0]; _tacgiaID = int.Parse(hdnValueTacGiaAnh.Text.ToString()); } if (txtChuthich.Text == Global.RM.GetString("Nhapchuthichanh")) { FuncAlert.AlertJS(this, "bạn chưa nhập chú thích ảnh"); return(false); } if (_tacgiaID == 0) { FuncAlert.AlertJS(this, "bạn chưa nhập tác giả ảnh"); return(false); } string SqlUpdate = ""; SqlUpdate = "update T_Anh set Chuthich=N'" + _chuthich + "',NguoiChup=N'" + _tacgia + "',Ma_Nguoichup=" + _tacgiaID + " where Ma_Anh=" + _ID; Ulti.ExecSql(SqlUpdate); } } } return(true); }
public int InsertUpdateT_Anh(T_Anh _Obj) { try { return(HPCDataProvider.Instance().InsertObjectReturn(_Obj, "Sp_Insert_UpdateT_Anh")); } catch (Exception ex) { throw ex; } }
public void LoadDataImage() { string where = ""; if (Request["ID"] != null) { where = " Duyet=1 and Ma_TinBai=" + Request["ID"].ToString(); } else { where = " Duyet=1 and Ma_Anh not in (select Ma_Anh from T_Tinbai_Anh) and NguoiTao=" + _user.UserID + " and NgayTao>='" + DateTime.Now.ToString("dd/MM/yyyy") + "'"; } DataSet _ds = _daltinanh.Sp_SelectTinAnhDynamic(where, "NgayTao DESC"); this.dgrListImages.DataSource = _ds; this.dgrListImages.DataBind(); string _chuthich = string.Empty; string _tacgiaanh = string.Empty; if (dgrListImages.Items.Count > 0) { foreach (DataListItem m_Item in dgrListImages.Items) { int _ID = int.Parse(this.dgrListImages.DataKeys[m_Item.ItemIndex].ToString()); _objimg = _dalanh.GetOneFromT_AnhByID(_ID); Label _labeldesc = m_Item.FindControl("lbdesc") as Label; Label _Labellbtacgia = m_Item.FindControl("lbtacgia") as Label; TextBox txtChuthich = m_Item.FindControl("txtChuthich") as TextBox; TextBox txtTacgia = m_Item.FindControl("txtTacgia") as TextBox; ImageButton btnUpdate = m_Item.FindControl("btnUpdate") as ImageButton; ImageButton btnCancel = m_Item.FindControl("btnCancel") as ImageButton; if (_objimg.Chuthich == "") { _labeldesc.Visible = false; txtChuthich.Visible = true; btnUpdate.Visible = true; btnCancel.Visible = true; } if (_objimg.Ma_Nguoichup == 0) { _Labellbtacgia.Visible = false; txtTacgia.Visible = true; btnUpdate.Visible = true; btnCancel.Visible = true; } } } }
public void SaveImagesAttachAll() { T_Tinbai_Anh _obj = new T_Tinbai_Anh(); int _ID = 0; if (dgrListImages.Items.Count > 0) { _daltinanh.DeleteAllTinbai_AnhByMatinbai(_matinbai); foreach (DataListItem m_Item in dgrListImages.Items) { _ID = Convert.ToInt32(dgrListImages.DataKeys[m_Item.ItemIndex].ToString()); TextBox txtTacgia = m_Item.FindControl("txtTacgia") as TextBox; TextBox hdnValueTacGiaAnh = m_Item.FindControl("hdnValueTacGiaAnh") as TextBox; TextBox txtChuthich = m_Item.FindControl("txtChuthich") as TextBox; if (_ID != 0) { if (_matinbai != 0) { _obj.Ma_TinBai = _matinbai; _obj.Ma_Anh = _ID; _obj.ChuThich = ""; _daltinanh.InsertUpdateTin_Anh(_obj); } _objimg = _dalanh.GetOneFromT_AnhByID(_ID); string _chuthich = ""; string _tacgia = ""; int _tacgiaID = 0; if (txtChuthich.Text != "") { _chuthich = UltilFunc.RemoveEnterCode(txtChuthich.Text.Trim().Replace("'", "''")); } if (_objimg != null && _objimg.Ma_Nguoichup != 0) { _tacgia = txtTacgia.Text.Replace(" -- ", "|").Split('|')[0]; _tacgiaID = _objimg.Ma_Nguoichup; } if (!String.IsNullOrEmpty(hdnValueTacGiaAnh.Text)) { _tacgia = txtTacgia.Text.Replace(" -- ", "|").Split('|')[0]; _tacgiaID = int.Parse(hdnValueTacGiaAnh.Text.ToString()); } string SqlUpdate = ""; SqlUpdate = "update T_Anh set Chuthich=N'" + _chuthich + "',NguoiChup=N'" + _tacgia + "',Ma_Nguoichup=" + _tacgiaID + " where Ma_Anh=" + _ID; Ulti.ExecSql(SqlUpdate); } } } }
public void dgrListAppro_UpdateCommand(object source, DataGridCommandEventArgs e) { T_Anh objimage = new T_Anh(); AnhDAL _DAL = new AnhDAL(); int _ID = Convert.ToInt32(dgrListAppro.DataKeys[e.Item.ItemIndex].ToString()); TextBox txtTieude = e.Item.FindControl("txtTieude") as TextBox; TextBox txtChuthich = e.Item.FindControl("txtChuthich") as TextBox; TextBox txtTacgia = e.Item.FindControl("txtTacgia") as TextBox; string _tieude = ""; string _chuthich = ""; string _tacgia = ""; int _tacgiaID = 0; if (txtTieude != null) { if (!String.IsNullOrEmpty(txtTieude.Text.Trim())) { _tieude = txtTieude.Text.Trim(); } } if (txtChuthich != null) { if (!String.IsNullOrEmpty(txtChuthich.Text.Trim())) { _chuthich = txtChuthich.Text.Trim(); } } if (txtTacgia != null) { if (!String.IsNullOrEmpty(txtTacgia.Text.Trim())) { _tacgia = txtTacgia.Text; _tacgiaID = Convert.ToInt32(UltilFunc.GetTacgiaID(_tacgia).ToString()); } } objimage.Ma_Anh = _ID; objimage.TieuDe = _tieude; objimage.Chuthich = _chuthich; objimage.NguoiChup = _tacgia; objimage.Ma_Nguoichup = _tacgiaID; _DAL.InsertUpdateT_Anh(objimage); //_DAL.UpdateinfoT_Anh("TieuDe=N'" + _tieude + "',Chuthich=N'" + _chuthich + "',NguoiChup=N'" + _tacgia + "',Ma_Nguoichup=" + _tacgiaID + " WHERE Ma_Anh=" + _ID); dgrListAppro_CancelCommand(source, e); }
private T_Anh SetItem(string pathOrg, string _tenfilegoc, string _tenfileht) { T_Anh _objPhoto = new T_Anh(); _objPhoto.Ma_Anh = 0; _objPhoto.TenFile_Goc = _tenfilegoc; _objPhoto.TenFile_Hethong = _tenfileht; _objPhoto.TieuDe = ""; _objPhoto.Chuthich = ""; _objPhoto.NgayTao = DateTime.Now; _objPhoto.Duongdan_Anh = pathOrg.ToString(); _objPhoto.Nhuanbut = 0; _objPhoto.NguoiTao = user.UserID; _objPhoto.Thanhtoan = false; _objPhoto.Nguoithanhtoan = 0; _objPhoto.Nguoicham = 0; _objPhoto.TuKhoa = ""; _objPhoto.NguoiChup = ""; _objPhoto.Ma_Nguoichup = 0; _objPhoto.Duyet = true; _objPhoto.Nhanxet = ""; return(_objPhoto); }
public void dgrListImages_EditCommand(object source, DataListCommandEventArgs e) { ImageButton btnAdd = e.Item.FindControl("btnAdd") as ImageButton; ImageButton btnUpdate = e.Item.FindControl("btnUpdate") as ImageButton; ImageButton btnCancel = e.Item.FindControl("btnCancel") as ImageButton; ImageButton btndelete = e.Item.FindControl("Imagebuttondelete") as ImageButton; TextBox txtTacgia = e.Item.FindControl("txtTacgia") as TextBox; TextBox hdnValueTacGiaAnh = e.Item.FindControl("hdnValueTacGiaAnh") as TextBox; TextBox txtChuthich = e.Item.FindControl("txtChuthich") as TextBox; Label lbdesc = e.Item.FindControl("lbdesc") as Label; Label lbtacgia = e.Item.FindControl("lbtacgia") as Label; int _ID = Convert.ToInt32(dgrListImages.DataKeys[e.Item.ItemIndex].ToString()); _objimg = _dalanh.GetOneFromT_AnhByID(_ID); if (e.CommandArgument.ToString().ToLower() == "delete") { Label lbFileAttach = e.Item.FindControl("lbFileAttach") as Label; string path = HttpContext.Current.Server.MapPath("/" + System.Configuration.ConfigurationManager.AppSettings["viewimg"].ToString() + lbFileAttach.Text); System.IO.FileInfo fi = new System.IO.FileInfo(path); try { if (File.Exists(path)) { fi.Delete(); } } catch (Exception ex) { throw ex; } _dalanh.DeleteFromT_Anh(_ID); string thaotac = "Thao tác xóa ảnh đính kèm: " + _objimg.Duongdan_Anh + " tại " + Request["MaDoiTuong"].ToString() + " thuộc tin bài: " + Txt_tieude.Text.Trim(); UltilFunc.Log_Action(_user.UserID, _user.UserName, DateTime.Now, int.Parse(Request["Menu_ID"].ToString()), thaotac); LoadDataImage(); } if (e.CommandArgument.ToString().ToLower() == "editinfo") { btndelete.Visible = false; btnAdd.Visible = false; btnUpdate.Visible = true; btnCancel.Visible = true; lbdesc.Visible = false; lbtacgia.Visible = false; txtTacgia.Visible = true; txtChuthich.Visible = true; if (_objimg != null && _objimg.Ma_Nguoichup != 0) { hdnValueTacGiaAnh.Text = _objimg.Ma_Nguoichup.ToString(); } else { hdnValueTacGiaAnh.Text = ""; } if (_objimg.NguoiChup != "") { txtTacgia.Text = _objimg.NguoiChup; } else { txtTacgia.Text = ""; } if (_objimg.Chuthich.Length > 0) { txtChuthich.Text = _objimg.Chuthich; } else { txtChuthich.Text = ""; } } if (e.CommandArgument.ToString().ToLower() == "update") { string _chuthich = ""; string _tacgia = ""; int _tacgiaID = 0; if (txtChuthich.Text != "") { _chuthich = UltilFunc.RemoveEnterCode(txtChuthich.Text.Trim().Replace("'", "''")); } if (_objimg != null && _objimg.Ma_Nguoichup != 0) { _tacgia = txtTacgia.Text.Replace(" -- ", "|").Split('|')[0]; _tacgiaID = _objimg.Ma_Nguoichup; } if (!String.IsNullOrEmpty(hdnValueTacGiaAnh.Text)) { _tacgia = txtTacgia.Text.Replace(" -- ", "|").Split('|')[0]; _tacgiaID = int.Parse(hdnValueTacGiaAnh.Text.ToString()); } string SqlUpdate = ""; SqlUpdate = "update T_Anh set Chuthich=N'" + _chuthich + "',NguoiChup=N'" + _tacgia + "',Ma_Nguoichup=" + _tacgiaID + " where Ma_Anh=" + _ID; Ulti.ExecSql(SqlUpdate); LoadDataImage(); lbdesc.Text = txtChuthich.Text; lbtacgia.Text = txtTacgia.Text; btnAdd.Visible = true; btnUpdate.Visible = false; btnCancel.Visible = false; lbdesc.Visible = true; lbtacgia.Visible = true; txtChuthich.Visible = false; txtTacgia.Visible = false; } if (e.CommandArgument.ToString().ToLower() == "cancel") { btndelete.Visible = true; btnAdd.Visible = true; btnUpdate.Visible = false; btnCancel.Visible = false; lbdesc.Visible = true; lbtacgia.Visible = true; txtTacgia.Visible = false; txtChuthich.Visible = false; } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.Write("Hello World"); try { string[] sArrProdID = null; char[] sep = { '?' }; string[] sArrVkey = null; string strUserID = ""; char[] sep2 = { ',' }; sArrProdID = context.Request.QueryString["user"].ToString().Trim().Split(sep); sArrVkey = sArrProdID[0].ToString().Trim().Split(sep2); user = DAL.GetUserByUserName(sArrVkey[0].ToString()); strUserID = user.UserID.ToString(); int matinbai = 0; if (sArrVkey[1].ToString() != "") { matinbai = int.Parse(sArrVkey[1].ToString()); } HttpPostedFile postedFile = context.Request.Files["Filedata"]; string tempPath = System.Configuration.ConfigurationManager.AppSettings["UploadPath"].ToString() + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/" + DateTime.Now.Day.ToString() + "/"; //Create forder CreateFolderByUserName(tempPath); string savepath = context.Server.MapPath("/" + tempPath); string filename = postedFile.FileName; string[] sArrTenfile = null; char[] cat = { '.' }; sArrTenfile = filename.ToString().Trim().Split(cat); string _extenfile = GetDateTimeStringUnique() + "." + sArrTenfile[1].ToString(); string _tenfilegoc = UltilFunc.RemoveSign4VietnameseString(Path.GetFileNameWithoutExtension(filename)) + "." + _extenfile.ToString(); _tenfilegoc = _tenfilegoc.Replace(" ", ""); postedFile.SaveAs(savepath + @"\" + _tenfilegoc); int startchar = tempPath.Substring(1, tempPath.Length - 1).IndexOf("/"); startchar += 1; string _PathFile = tempPath.Substring(startchar, tempPath.Length - startchar); string _savePath = _PathFile + "" + _tenfilegoc; AnhDAL _DAL = new AnhDAL(); T_Anh _obj = new T_Anh(); _obj = SetItem(_savePath, _tenfilegoc, _tenfilegoc); int _MaAnhReturn = _DAL.InsertUpdateT_Anh(_obj); if (matinbai > 0 && _MaAnhReturn > 0) { TinBaiAnhDAL _daltinanh = new TinBaiAnhDAL(); T_Tinbai_Anh _objTA = new T_Tinbai_Anh(); _objTA.ID = 0; _objTA.Ma_Anh = _MaAnhReturn; _objTA.Ma_TinBai = matinbai; _objTA.ChuThich = ""; _daltinanh.InsertUpdateTin_Anh(_objTA); } context.Response.Write(tempPath + "/" + filename); context.Response.StatusCode = 200; } catch (Exception ex) { context.Response.Write("Error: " + ex.Message); } }