using System; using System.Data; using System.Data.OleDb; using System.Text; using System.Web.Configuration; public partial class WeeklyPostTransactionLog : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Request.IsAuthenticated == false) { Response.Redirect("~/Account/Login.aspx"); } } protected void btnUpload1_Click(object sender, EventArgs e) { if (FileUpload1.HasFile) try { string date = string.Format("{0:yyyy-MM-dd HHmmss tt }", DateTime.Now); //FileUpload1.SaveAs("C:\\Temp\\" + date + ddlJamatkhana.SelectedItem + "_" + FileUpload1.FileName); FileUpload1.SaveAs(Server.MapPath(@"App_Data\PDTUploads\" + date + ddlJamatkhana.SelectedItem + "_" + FileUpload1.FileName)); Label1.Text = "File name: " + FileUpload1.PostedFile.FileName + "   " + FileUpload1.PostedFile.ContentLength + " kb   " + "Content type: " + FileUpload1.PostedFile.ContentType; try { InsertWeeklyTransaction(); Label1.Text += "<hr/><br/><br/><b>" + "Upload Reference ID: " + Identity + "</b><br/><br/>" + "Please record the upload reference id on your weekly submission record sheet before proceeding"; } catch (Exception ex) { Response.Write(ex.Message); } } catch (Exception ex) { Label1.Text = "ERROR: " + ex.Message.ToString(); } else { Label1.Text = "You have not specified a file."; } } private void InsertWeeklyTransaction() { string userName = ((SiteMaster)(this.Master)).Username; string connectionString = WebConfigurationManager.ConnectionStrings["AccessDB"].ConnectionString; OleDbConnection oleDBConn = new OleDbConnection(connectionString); StringBuilder sql = new StringBuilder(); sql.Append("INSERT INTO PDTUpload (PDTJamatKhanaID, PDTTransactionDate, PDTTotalAmount, PDTTransactionLogFile, PDTDateCreated, PDTCreateUser, PDTModifiedDate, PDTModifiedUser) "); sql.Append(" VALUES (@PDTJamatKhanaID, @PDTTransactionDate, @PDTTotalAmount, @PDTTransactionLogFile, @PDTDateCreated, @PDTCreateUser, @PDTModifiedDate, @PDTModifiedUser) "); OleDbCommand cmd = new OleDbCommand(sql.ToString(), oleDBConn); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@PDTJamatKhanaID", Convert.ToInt32(ddlJamatkhana.SelectedValue)); cmd.Parameters.AddWithValue("@PDTTransactionDate", Convert.ToDateTime(txtTransDate.Text).ToOADate()); cmd.Parameters.AddWithValue("@PDTTotalAmount", Convert.ToDecimal(txtTotalDepositAmount.Text)); cmd.Parameters.AddWithValue("@PDTTransactionLogFile", FileUpload1.FileName); cmd.Parameters.AddWithValue("@PDTDateCreated", DateTime.Now.ToOADate()); cmd.Parameters.AddWithValue("@PDTCreateUser", userName); cmd.Parameters.AddWithValue("@PDTModifiedDate", DateTime.Now.ToOADate()); cmd.Parameters.AddWithValue("@PDTModifiedUser", userName); oleDBConn.Open(); cmd.ExecuteNonQuery(); cmd.CommandText = "Select @@Identity"; Identity = (int)cmd.ExecuteScalar(); oleDBConn.Close(); } public int Identity { get; set; } }