protected void btnThem_Click(object sender, EventArgs e) { string tenloai = txtTenLoai.Text; string trichdan = txtTrichDan.Text; if (txtTenLoai.Text == "") { lbloi1.Text = "Tên loại không được để trống"; } if (txtTrichDan.Text == "") { lbLoi2.Text = "Phần trích dẫn không được để trống"; } if (UploadFile.HasFile) { string ext = Path.GetFileName(UploadFile.FileName); ext = ext.Split('.')[ext.Split('.').Length - 1]; string filename = DateTime.Now.ToString("yyyyMMddhhmmssffff") + "." + ext; UploadFile.SaveAs(Server.MapPath("~/Assest/img") + filename); } try { if (!new Dao_JustShop.LoaiSanPhamModel().insert(tenloai, trichdan, UploadFile.FileName)) { Label1.Text = "Thêm dữ liệu thất bạt"; } } catch { } }
protected void UploadFileBtn_Click(object sender, EventArgs e) { //File not uploaded, error message if (UploadFile.FileName.Length == 0) { UploadFileMsg.Text = "Choose a file to upload"; UploadFileMsg.ForeColor = System.Drawing.Color.Red; } string fileExt = System.IO.Path.GetExtension(UploadFile.FileName); if (fileExt != ".doc" && fileExt != ".docx") { UploadFileMsg.Text = "File extension should be doc or docx"; UploadFileMsg.ForeColor = System.Drawing.Color.Red; } else { int filesize = UploadFile.PostedFile.ContentLength; if (filesize > 80000) { UploadFileMsg.Text = "File size cannot be more than 80000 bytes."; UploadFileMsg.ForeColor = System.Drawing.Color.Red; } else { UploadFile.SaveAs(Server.MapPath("~/Resources/Uploads/" + UploadFile.FileName)); UploadFileMsg.Text = "File" + UploadFile.FileName + " is successfully uploaded."; UploadFileMsg.ForeColor = System.Drawing.Color.Green; } } }
private string UploadCellFile() { if (UploadFile.FileName != "") { //string saveDir = @"\CellTmp\"; string saveDir = @"\Upload\CellTmp\"; string appPath = Request.PhysicalApplicationPath; string savepath = appPath + saveDir + UploadFile.FileName; try { UploadFile.SaveAs(savepath); return(saveDir + UploadFile.FileName);; } catch { return(""); } } return(""); }
protected void btnSave_Click(object sender, EventArgs e) { int b = 0; if (ddlDocumentName.SelectedIndex == 0) { DisplayMessage("Select Document Name"); ddlDocumentName.Focus(); return; } if (txtFileName.Text == "") { DisplayMessage("Enter File Name"); txtFileName.Focus(); return; } if (UploadFile.HasFile == false) { DisplayMessage("Upload The File"); UploadFile.Focus(); return; } string filepath = "~/" + "HR" + "/" + HidEmpId.Value + "/" + UploadFile.FileName; UploadFile.SaveAs(Server.MapPath(filepath)); string filename = UploadFile.FileName; string ext = Path.GetExtension(filepath); string NewfileName = txtFileName.Text + "" + ext; Stream fs = UploadFile.PostedFile.InputStream; BinaryReader br = new BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); string FileTypeId = "0"; DataTable dt = ObjFile.Get_FileTransaction(strCompId, FileTypeId); dt = new DataView(dt, "File_Name='" + txtFileName.Text + "'", "", DataViewRowState.CurrentRows).ToTable(); if (dt.Rows.Count > 0) { DisplayMessage("File Name Already Exists"); txtFileName.Focus(); txtFileName.Text = ""; return; } b = ObjFile.Insert_In_FileTransaction(strCompId, ddlDirectory.SelectedValue, ddlDocumentName.SelectedValue, "0", NewfileName, DateTime.Now.ToString(), bytes, filepath, txtExpiryDate.Text, "", "0", "", "", "", false.ToString(), DateTime.Now.ToString(), true.ToString(), Session["UserId"].ToString(), DateTime.Now.ToString(), Session["UserId"].ToString(), DateTime.Now.ToString()); if (b != 0) { DisplayMessage("Record Saved"); FillGrid(); DataTable DtFile = (DataTable)Session["File"]; DtFile = new DataView(DtFile, "Directory_Id =" + ddlDirectory.SelectedValue + "", "", DataViewRowState.CurrentRows).ToTable(); gvFileMaster.DataSource = DtFile; gvFileMaster.DataBind(); Reset(); Paneladddocument.Visible = false; } else { DisplayMessage("Record Not Saved"); } }
protected void btnSave_Click(object sender, EventArgs e) { int b = 0; if (ddlDirectory.SelectedIndex == 0) { DisplayMessage("Select Directory Name"); ddlDirectory.Focus(); return; } if (ddlDocumentName.SelectedIndex == 0) { DisplayMessage("Select Document Name"); ddlDocumentName.Focus(); return; } if (txtFileName.Text == "") { DisplayMessage("Enter File Name"); txtFileName.Focus(); return; } if (UploadFile.HasFile == false) { DisplayMessage("Upload The File"); UploadFile.Focus(); return; } string filepath = "~/" + "ArcaWing" + "/" + ddlDirectory.SelectedItem + "/" + UploadFile.FileName; UploadFile.SaveAs(Server.MapPath(filepath)); string filename = UploadFile.FileName; string ext = Path.GetExtension(filepath); string NewfileName = txtFileName.Text + "" + ext; Stream fs = UploadFile.PostedFile.InputStream; BinaryReader br = new BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); if (editid.Value == "") { string FileTypeId = "0"; DataTable dt = ObjFile.Get_FileTransaction(strCompId, FileTypeId); dt = new DataView(dt, "File_Name='" + txtFileName.Text + "'", "", DataViewRowState.CurrentRows).ToTable(); if (dt.Rows.Count > 0) { DisplayMessage("File Name Already Exists"); txtFileName.Focus(); txtFileName.Text = ""; return; } //dt = new DataView(dt, "Directory_Id="+ddlDirectory.SelectedValue+" ", "", DataViewRowState.CurrentRows).ToTable(); //if (dt.Rows.Count > 0) //{ // DisplayMessage("Directory Exists"); // txtContentName.Focus(); // return; //} b = ObjFile.Insert_In_FileTransaction(strCompId, ddlDirectory.SelectedValue, ddlDocumentName.SelectedValue, "0", NewfileName, DateTime.Now.ToString(), bytes, filepath, txtExpiryDate.Text, "", "0", "", "", "", false.ToString(), DateTime.Now.ToString(), true.ToString(), Session["UserId"].ToString(), DateTime.Now.ToString(), Session["UserId"].ToString(), DateTime.Now.ToString()); if (b != 0) { DisplayMessage("Record Saved"); FillGrid(); Reset(); } else { DisplayMessage("Record Not Saved"); } } else { string FileTransactionid = "0"; DataTable dt = ObjFile.Get_FileTransaction(strCompId, FileTransactionid); string FileTransaction = string.Empty; try { FileTransaction = (new DataView(dt, "Trans_Id='" + editid.Value + "'", "", DataViewRowState.CurrentRows).ToTable()).Rows[0]["File_Name"].ToString(); } catch { FileTransaction = ""; } dt = new DataView(dt, "File_Name='" + txtFileName.Text + "' and File_Name<>'" + FileTransaction + "' ", "", DataViewRowState.CurrentRows).ToTable(); if (dt.Rows.Count > 0) { DisplayMessage("File Name Already Exists"); txtFileName.Focus(); txtFileName.Text = ""; return; } //dt = new DataView(dt, "Content_Type='" + txtContentName.Text + "' ", "", DataViewRowState.CurrentRows).ToTable(); //if (dt.Rows.Count > 0) //{ // DisplayMessage("Content Name Already Exists"); // txtContentName.Focus(); // return; //} b = ObjFile.Update_In_FileTransaction(strCompId, editid.Value, ddlDirectory.SelectedValue, ddlDocumentName.SelectedValue, ddlFiletype.SelectedValue, NewfileName, DateTime.Now.ToString(), bytes, filepath, DateTime.Now.ToString(), "", "0", "", "", "", false.ToString(), DateTime.Now.ToString(), true.ToString(), Session["UserId"].ToString(), DateTime.Now.ToString()); if (b != 0) { btnList_Click(null, null); DisplayMessage("Record Updated"); Reset(); FillGrid(); } else { DisplayMessage("Record Not Updated"); } } }