using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Configuration; using System.Data.OleDb; using System.Text; using System.Data; public partial class DailyCCTransactionLog : 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\CCTUploads\" + date + ddlJamatkhana.SelectedItem + "_" + FileUpload1.FileName)); Label1.Text = "File name: " + FileUpload1.PostedFile.FileName + "   " + FileUpload1.PostedFile.ContentLength + " kb   " + "Content type: " + FileUpload1.PostedFile.ContentType; try { InsertDailyTransaction(); Label1.Text += "<hr/><br/><br/><b>" + "Upload Reference ID: " + Identity + "</b><br/><br/>" + "Please record the upload reference id on your daily 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 InsertDailyTransaction() { 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 CCTUpload (CCTJamatkhanaID, CCTLastTransactionDate, CCTMultipleDays, CCTTotalDeposit, CCTDepositRefNum, CCTDepositDate, CCTTransactionLogFile, CCTDateCreated, CCTCreateUser, CCTModifiedDate, CCTModifiedUser) "); sql.Append(" VALUES (@CCTJamatkhanaID, @CCTLastTransactionDate, @CCTMultipleDays, @CCTTotalDeposit, @CCTDepositRefNum, @CCTDepositDate, @CCTTransactionLogFile, @CCTDateCreated, @CCTCreateUser, @CCTModifiedDate, @CCTModifiedUser) "); OleDbCommand cmd = new OleDbCommand(sql.ToString(), oleDBConn); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@CCTJamatkhanaID", Convert.ToInt32(ddlJamatkhana.SelectedValue)); cmd.Parameters.AddWithValue("@CCTLastTransactionDate", Convert.ToDateTime(txtTransDate.Text).ToOADate()); cmd.Parameters.AddWithValue("@CCTMultipleDays", chkMultDays.Checked); cmd.Parameters.AddWithValue("@CCTTotalDeposit", Convert.ToDecimal(txtTotalDepositAmount.Text)); cmd.Parameters.AddWithValue("@CCTDepositRefNum", txtDepositSlipNumber.Text); cmd.Parameters.AddWithValue("@CCTDepositDate", Convert.ToDateTime(txtDepositDate.Text).ToOADate()); cmd.Parameters.AddWithValue("@CCTTransactionLogFile", FileUpload1.FileName); cmd.Parameters.AddWithValue("@CCTDateCreated", DateTime.Now.ToOADate()); cmd.Parameters.AddWithValue("@CCTCreateUser", userName); cmd.Parameters.AddWithValue("@CCTModifiedDate", DateTime.Now.ToOADate()); cmd.Parameters.AddWithValue("@CCTModifiedUser", userName); oleDBConn.Open(); cmd.ExecuteNonQuery(); cmd.CommandText = "Select @@Identity"; Identity = (int)cmd.ExecuteScalar(); oleDBConn.Close(); } public int Identity { get; set; } }