protected void btnSubmit_Click(object sender, EventArgs e) { if (!mvMessage.IsValid) return; if ((File.PostedFile != null) && (File.PostedFile.ContentLength > 0)) { string fn = System.IO.Path.GetFileName(File.PostedFile.FileName); string filename = DateTime.Now.ToString("yyyyMMddHHmmss") + fn; string SaveLocation = Server.MapPath("Mail") + "\\File\\" + filename; try { File.PostedFile.SaveAs(SaveLocation); UploadedFileData data = new UploadedFileData(); ITransaction tran = factory.GetInsertObject(data); data.OrgFileName = fn; data.FileName = filename; data.PathFile = SaveLocation; data.ModifiedBy = Page.User.Identity.Name; data.CreatedBy = Page.User.Identity.Name; data.Created = DateTime.Now.ToString("yyyyMMddHHmmss"); data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss"); Execute(tran); if (!HasError) { //////////////////// UploadedFileMessageMapData dataM = new UploadedFileMessageMapData(); ITransaction tranM = factory.GetInsertObject(dataM); dataM.UploadFileID = data.UploadFileId; dataM.MessageID = hidMessageId.Value; Execute(tranM); if (!HasError) { mvMessage.SetCompleteMessage("Thực Hiện Thành Công"); } else { OperationLogger.WriteError(Constants.LogOperationAlbumId, Constants.LogActionInsertId, "Tạo Mới Thông Tin Phát Sinh Lỗi", Page.User.Identity.Name); mvMessage.AddError("Tạo Mới Thông Tin Phát Sinh Lỗi"); } LoadMail(hidMessageId.Value); } else { mvMessage.AddError("Lỗi phát sinh"); return; } } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } }
protected void btnSubmit_Click(object sender, EventArgs e) { if ("1".Equals(hidReply.Value) && !String.IsNullOrEmpty(hidMessageId.Value)) { DbHelper.ExecuteNonQuery("Update UsersMessagesMapped Set isReply = 1 Where UserName = '******' and MessageId = '" + hidMessageId.Value + "'"); } mvMessage.CheckRequired(txtToCC, "Người nhận: cần nhập thông tin"); mvMessage.CheckRequired(txtSubject, "Tiêu đề: cần nhập thông tin"); string uploadFileId = ""; string[] cc = txtToCC.Text.Replace(System.Environment.NewLine, string.Empty).Split(';'); for (int i = 0; i < cc.Length; i++) { if (!String.IsNullOrEmpty(cc[i])) { int count = DbHelper.GetCount("Select count(*) from aspnet_Users where UserName = '******'"); if (count == 0) mvMessage.AddError(cc[i] + ": User này không tồn tại"); } } if (!String.IsNullOrEmpty(txtToBCC.Text)) { string[] bcc = txtToBCC.Text.Replace(System.Environment.NewLine, string.Empty).Split(';'); for (int i = 0; i < bcc.Length; i++) { if (!String.IsNullOrEmpty(bcc[i])) { int count = DbHelper.GetCount("Select count(*) from aspnet_Users where UserName = '******'"); if (count == 0) mvMessage.AddError(bcc[i] + ": User này không tồn tại"); } } } if (!mvMessage.IsValid) return; if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0)) { string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName); string filename = DateTime.Now.ToString("yyyyMMddHHmmss") + fn; string SaveLocation = Server.MapPath("Mail") + "\\File\\" + filename; try { File1.PostedFile.SaveAs(SaveLocation); UploadedFileData data = new UploadedFileData(); ITransaction tran = factory.GetInsertObject(data); data.OrgFileName = fn; data.FileName = filename; data.PathFile = SaveLocation; data.ModifiedBy = Page.User.Identity.Name; data.CreatedBy = Page.User.Identity.Name; data.Created = DateTime.Now.ToString("yyyyMMddHHmmss"); data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss"); Execute(tran); if (!HasError) { uploadFileId += ";" + data.UploadFileId; } else { mvMessage.AddError("Lỗi phát sinh"); return; } } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } if ((File2.PostedFile != null) && (File2.PostedFile.ContentLength > 0)) { string fn = System.IO.Path.GetFileName(File2.PostedFile.FileName); string filename = DateTime.Now.ToString("yyyyMMddHHmmss") + fn; string SaveLocation = Server.MapPath("Mail") + "\\File\\" + filename; try { File2.PostedFile.SaveAs(SaveLocation); UploadedFileData data = new UploadedFileData(); ITransaction tran = factory.GetInsertObject(data); data.OrgFileName = fn; data.FileName = filename; data.PathFile = SaveLocation; data.ModifiedBy = Page.User.Identity.Name; data.CreatedBy = Page.User.Identity.Name; data.Created = DateTime.Now.ToString("yyyyMMddHHmmss"); data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss"); Execute(tran); if (!HasError) { uploadFileId += ";" + data.UploadFileId; } else { mvMessage.AddError("Lỗi phát sinh"); return; } } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } if ((File3.PostedFile != null) && (File3.PostedFile.ContentLength > 0)) { string fn = System.IO.Path.GetFileName(File3.PostedFile.FileName); string filename = DateTime.Now.ToString("yyyyMMddHHmmss") + fn; string SaveLocation = Server.MapPath("Mail") + "\\File\\" + filename; try { File3.PostedFile.SaveAs(SaveLocation); UploadedFileData data = new UploadedFileData(); ITransaction tran = factory.GetInsertObject(data); data.OrgFileName = fn; data.FileName = filename; data.PathFile = SaveLocation; data.ModifiedBy = Page.User.Identity.Name; data.CreatedBy = Page.User.Identity.Name; data.Created = DateTime.Now.ToString("yyyyMMddHHmmss"); data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss"); Execute(tran); if (!HasError) { uploadFileId += ";" + data.UploadFileId; } else { mvMessage.AddError("Lỗi phát sinh"); return; } } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } if ((File4.PostedFile != null) && (File4.PostedFile.ContentLength > 0)) { string fn = System.IO.Path.GetFileName(File4.PostedFile.FileName); string filename = DateTime.Now.ToString("yyyyMMddHHmmss") + fn; string SaveLocation = Server.MapPath("Mail") + "\\File\\" + filename; try { File4.PostedFile.SaveAs(SaveLocation); UploadedFileData data = new UploadedFileData(); ITransaction tran = factory.GetInsertObject(data); data.OrgFileName = fn; data.FileName = filename; data.PathFile = SaveLocation; data.ModifiedBy = Page.User.Identity.Name; data.CreatedBy = Page.User.Identity.Name; data.Created = DateTime.Now.ToString("yyyyMMddHHmmss"); data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss"); Execute(tran); if (!HasError) { uploadFileId += ";" + data.UploadFileId; } else { mvMessage.AddError("Lỗi phát sinh"); return; } } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } if ((File5.PostedFile != null) && (File5.PostedFile.ContentLength > 0)) { string fn = System.IO.Path.GetFileName(File5.PostedFile.FileName); string filename = DateTime.Now.ToString("yyyyMMddHHmmss") + fn; string SaveLocation = Server.MapPath("Mail") + "\\File\\" + filename; try { File5.PostedFile.SaveAs(SaveLocation); UploadedFileData data = new UploadedFileData(); ITransaction tran = factory.GetInsertObject(data); data.OrgFileName = fn; data.FileName = filename; data.PathFile = SaveLocation; data.ModifiedBy = Page.User.Identity.Name; data.CreatedBy = Page.User.Identity.Name; data.Created = DateTime.Now.ToString("yyyyMMddHHmmss"); data.Modified = DateTime.Now.ToString("yyyyMMddHHmmss"); Execute(tran); if (!HasError) { uploadFileId += ";" + data.UploadFileId; } else { mvMessage.AddError("Lỗi phát sinh"); return; } } catch (Exception ex) { Response.Write("Error: " + ex.Message); } } //using (SqlConnection con = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString)) //{ // con.Open(); // SqlCommand cmd = new SqlCommand("insert into RichTextBoxData(RichTextData) values(@Richtextbox)", con); // cmd.Parameters.AddWithValue("@Richtextbox", FreeTextBox1.Text); // cmd.ExecuteNonQuery(); // con.Close(); // FreeTextBox1.Text = ""; // lbltxt.Text = "Data Inserted Successfully"; // BindGridview(); //} MessagesData dataM = new MessagesData(); ITransaction tranM = factory.GetInsertObject(dataM); dataM.Subject = txtSubject.Text.Trim(); dataM.Body = txtContent.Text; dataM.UserName = Page.User.Identity.Name; dataM.DelFlag = "0"; dataM.CcUser = txtToCC.Text; dataM.BccUser = txtToBCC.Text; dataM.FlagId = drpFlag.SelectedValue; dataM.BuildingId = Func.ParseString(Session["__BUILDINGID__"]); dataM.Updator = Page.User.Identity.Name; dataM.Creator = Page.User.Identity.Name; dataM.Created = DateTime.Now.ToString("yyyyMMddHHmmss"); dataM.Updated = DateTime.Now.ToString("yyyyMMddHHmmss"); Execute(tranM); if (!HasError) { OperationLogger.WriteInfo(Constants.LogOperationAlbumId, Constants.LogActionInsertId, "Tạo Mới Thông Tin Thành Công", Page.User.Identity.Name); string MessageId = dataM.MessageID; using (SqlConnection rConn = new SqlConnection(Gnt.Configuration.ApplicationConfiguration.ConnectionString)) { rConn.Open(); using (SqlCommand cm = new SqlCommand("sp_AddMail", rConn)) { cm.CommandType = CommandType.StoredProcedure; cm.Parameters.AddWithValue("@MessageId", MessageId); cm.Parameters.AddWithValue("@FlagId", drpFlag.SelectedValue); cm.Parameters.AddWithValue("@UploadFileId", uploadFileId); cm.Parameters.AddWithValue("@BuildingId", Func.ParseString(Session["__BUILDINGID__"])); cm.Parameters.AddWithValue("@UserNames", txtToCC.Text.Replace(System.Environment.NewLine, string.Empty) + ";" + txtToBCC.Text.Replace(System.Environment.NewLine, string.Empty)); cm.Parameters.AddWithValue("@Created", DateTime.Now.ToString("yyyyMMddHHmmss")); cm.Parameters.AddWithValue("@CreatedBy", Page.User.Identity.Name); cm.ExecuteNonQuery(); } rConn.Close(); mvMessage.SetCompleteMessage("Thực Hiện Thành Công"); } } else { OperationLogger.WriteError(Constants.LogOperationAlbumId, Constants.LogActionInsertId, "Tạo Mới Thông Tin Phát Sinh Lỗi", Page.User.Identity.Name); mvMessage.AddError("Tạo Mới Thông Tin Phát Sinh Lỗi"); } ShowData("1", ""); }