protected void gvClinetInv_RowUpdating(object sender, GridViewUpdateEventArgs e) { // Create object from dal and fetching data after updating in gridview and send it to update. ClientsInvoicesDAL clientsInvoicesDAL = new ClientsInvoicesDAL(); clientsInvoicesDAL.ConnectionString = ConfigurationManager.ConnectionStrings["MySQLConn"].ToString(); Clients_Invoices com = new Clients_Invoices(); com.OrderNo = (gvClinetInv.Rows[e.RowIndex].FindControl("lblOrderNo") as Label).Text; com.EmployeeID = (gvClinetInv.Rows[e.RowIndex].FindControl("lblEmployeeID") as Label).Text; com.FirstName = (gvClinetInv.Rows[e.RowIndex].FindControl("lblFirstName") as Label).Text; com.LastName = (gvClinetInv.Rows[e.RowIndex].FindControl("lblLastName") as Label).Text; com.CatalogName = (gvClinetInv.Rows[e.RowIndex].FindControl("lblCatalogName") as Label).Text; com.Quantity = Convert.ToInt32((gvClinetInv.Rows[e.RowIndex].FindControl("lblQuantity") as Label).Text); com.OrderDate = Convert.ToDateTime((gvClinetInv.Rows[e.RowIndex].FindControl("lblOrderDate") as Label).Text); com.LocalCost = Convert.ToDouble((gvClinetInv.Rows[e.RowIndex].FindControl("lblLocalCost") as Label).Text); com.USDCost = Convert.ToDouble((gvClinetInv.Rows[e.RowIndex].FindControl("lblUSDCost") as Label).Text); com.TotalLocalCost = Convert.ToDouble(gvClinetInv.DataKeys[e.RowIndex].Values["TotalLocalCost"].ToString()); com.RedemptionPoints = (gvClinetInv.Rows[e.RowIndex].FindControl("lblRedemptionPoints") as Label).Text; // com.ReasonofReturen = gvClinetInv.DataKeys[e.RowIndex].Values["ReasonofReturen"].ToString(); com.ReasonofReturen = (gvClinetInv.Rows[e.RowIndex].FindControl("ddlReasonofReturen") as DropDownList).SelectedValue; //int company = Convert.ToInt32(CompanyDDL.SelectedValue); com.Country = gvClinetInv.DataKeys[e.RowIndex].Values[2].ToString(); clientsInvoicesDAL.InsertClientsInvoices(com); gvClinetInv.EditIndex = -1; GetClinetInvoice(search, search, company, sdate, edate); }
private void ReadWriteCSVFile() { string date = System.DateTime.Now.ToString("ddMMyyhhmmss"); if (File.Exists(Server.MapPath(uppath))) { //Start Stream Reading and Writing StreamReader sr = new StreamReader(Server.MapPath(uppath)); StreamWriter write = new StreamWriter(Server.MapPath(output)); //Create objects to read CSV file. CsvReader csvread = new CsvReader(sr); CsvWriter csw = new CsvWriter(write); IEnumerable <Clients_Invoices> record = csvread.GetRecords <Clients_Invoices>(); csvread.Configuration.PrepareHeaderForMatch = header => header.Replace(" ", "").Replace("/", string.Empty).Replace("#", string.Empty).Replace(".", string.Empty); //csvread.Configuration.HeaderValidated = null; foreach (var rec in record) // Each record will be fetched and printed on the screen { csw.WriteRecord <Clients_Invoices>(rec); csw.NextRecord(); ClientsInvoicesDAL clientInvoice = new ClientsInvoicesDAL(); clientInvoice.ConnectionString = ConfigurationManager.ConnectionStrings["MySQLConn"].ToString(); clientInvoice.InsertClientsInvoices(rec); } sr.Close(); write.Close();//close file streams if (File.Exists(Server.MapPath(uppath))) { File.Delete(Server.MapPath(uppath)); } } }
protected void ButtonSearch_Click(object sender, EventArgs e) { //choosing search criteria sdate = Convert.ToDateTime(tbSDate.Text); edate = Convert.ToDateTime(tbEDate.Text); ClientsInvoicesDAL clientsInvoicesDAL = new ClientsInvoicesDAL(); clientsInvoicesDAL.ConnectionString = ConfigurationManager.ConnectionStrings["MySQLConn"].ToString(); if (tbSearchEmpID.Text != "") { search = tbSearchEmpID.Text; GetClinetInvoice(null, search, 0, sdate, edate); } else if (tbSearchOrderNo.Text != "") { search = tbSearchOrderNo.Text; GetClinetInvoice(search, null, 0, sdate, edate); } else if (CompanyDDL.SelectedValue != "0") { company = Convert.ToInt32(CompanyDDL.SelectedValue); GetClinetInvoice(null, null, company, sdate, edate); } else if (CompanyDDL.SelectedValue == "") { GetClinetInvoice(null, null, 0, sdate, edate); } else { GetClinetInvoice(search, search, company, sdate, edate); } }
protected void gvClinetInv_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "DeleteOrder") { //Deleting recored that Needed ClientsInvoicesDAL clientInvoice = new ClientsInvoicesDAL(); clientInvoice.ConnectionString = ConfigurationManager.ConnectionStrings["MySQLConn"].ToString(); clientInvoice.DeleteClientsInvoices(e.CommandArgument.ToString()); //GetClinetInvoice(null, null, 0, DateTime.MinValue, DateTime.MinValue); } }
// This method needed to pass parameters to get data from Client Invice Table private void GetClinetInvoice(string OrederNo, string empID, int company, DateTime sdate, DateTime edate) { // Creating object from DAl Class to call methods ClientsInvoicesDAL clientsInvoicesDAL = new ClientsInvoicesDAL(); //sending Connection String information. clientsInvoicesDAL.ConnectionString = ConfigurationManager.ConnectionStrings["MySQLConn"].ToString(); sdate = Convert.ToDateTime(tbSDate.Text); // retrieving list of data List <Clients_Invoices> ClientInvoiceList = clientsInvoicesDAL.GetClientsInvoices(OrederNo, empID, sdate, edate, company); //Binding GridView with data gvClinetInv.DataSource = ClientInvoiceList; gvClinetInv.DataBind(); }
protected void BtnExport_Click(object sender, EventArgs e) { //exporting a csv file int company = Convert.ToInt32(CompanyDDL.SelectedValue); DateTime sdate = Convert.ToDateTime(tbSDate.Text); DateTime edate = Convert.ToDateTime(tbEDate.Text); ClientsInvoicesDAL clientInvoice = new ClientsInvoicesDAL(); clientInvoice.ConnectionString = ConfigurationManager.ConnectionStrings["MySQLConn"].ToString(); List <Clients_Invoices> clientInvoiceList = clientInvoice.GetClientsInvoices(null, null, sdate, edate, company); List <Clients_Invoices> TotalInvoicesList = clientInvoice.GetInvoiceTotal(null, null, sdate, edate, company); //string aa = TotalInvoicesList.TotalLocalCost; foreach (var val in TotalInvoicesList) { TotalLocalCost = Convert.ToDouble(val.TotalLocalCost); TotalUSDCost = Convert.ToDouble(val.TotalUSDCost); } var mem = new MemoryStream(); var writer = new StreamWriter(mem, Encoding.UTF8, 1024, true); var csvWriter = new CsvWriter(writer); csvWriter.Configuration.Delimiter = ","; csvWriter.WriteField("OrderNo"); csvWriter.WriteField("EmployeeID"); csvWriter.WriteField("FirstName"); csvWriter.WriteField("LastName"); csvWriter.WriteField("CatalogName"); csvWriter.WriteField("Quantity"); csvWriter.WriteField("OrderDate"); csvWriter.WriteField("RedemptionPoints"); csvWriter.WriteField("LocalCost"); csvWriter.WriteField("USDCost"); csvWriter.WriteField("TotalUSDCost"); csvWriter.WriteField("TotalLocalCost"); csvWriter.NextRecord(); int lenght = clientInvoiceList.Count - 1; for (int i = 0; i <= lenght; i++) { csvWriter.WriteField(clientInvoiceList[i].OrderNo); csvWriter.WriteField(clientInvoiceList[i].EmployeeID); csvWriter.WriteField(clientInvoiceList[i].FirstName); csvWriter.WriteField(clientInvoiceList[i].LastName); csvWriter.WriteField(clientInvoiceList[i].CatalogName); csvWriter.WriteField(clientInvoiceList[i].Quantity); csvWriter.WriteField(clientInvoiceList[i].OrderDate); csvWriter.WriteField(clientInvoiceList[i].RedemptionPoints); csvWriter.WriteField(clientInvoiceList[i].LocalCost); csvWriter.WriteField(clientInvoiceList[i].USDCost); csvWriter.WriteField(TotalLocalCost); csvWriter.WriteField(TotalUSDCost); csvWriter.NextRecord(); } writer.Flush(); var data = Encoding.UTF8.GetString(mem.ToArray()); Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=ClientInvoice.csv"); Response.Charset = ""; Response.ContentType = "text/csv"; Response.Write(data.ToString()); Response.End(); }
protected void BtnExport_Click(object sender, EventArgs e) { //DateTime sdate = Convert.ToDateTime(tbSDate.Text); //DateTime edate = Convert.ToDateTime(tbEDate.Text); ClientsInvoicesDAL clientInvoice = new ClientsInvoicesDAL(); GiftCardsInvoiceDAL GCIDAL = new GiftCardsInvoiceDAL(); GCIDAL.ConnectionString = ConfigurationManager.ConnectionStrings["MySQLConn"].ToString(); List <Gift_Cards_Invoice> GCList = GCIDAL.GetGiftCardsInvoice(null, null, sdate, edate); List <Gift_Cards_Invoice> TotalInvoicesList = GCIDAL.GetGCTotal(sdate, edate); foreach (var val in TotalInvoicesList) { TotalLocalCost = Convert.ToDouble(val.TotalLocalCost); TotalUSDCost = Convert.ToDouble(val.TotalUSDCost); } var mem = new MemoryStream(); var writer = new StreamWriter(mem, Encoding.UTF8, 1024, true); var csvWriter = new CsvWriter(writer); csvWriter.Configuration.Delimiter = ","; csvWriter.WriteField("OrderId"); csvWriter.WriteField("EmployeeID"); csvWriter.WriteField("LineNumber"); csvWriter.WriteField("RewardName"); csvWriter.WriteField("OrderDate"); csvWriter.WriteField("Quantity"); csvWriter.WriteField("LocalCost"); csvWriter.WriteField("USDCost"); csvWriter.WriteField("TotalUSDCost"); csvWriter.WriteField("TotalLocalCost"); csvWriter.NextRecord(); int lenght = GCList.Count - 1; for (int i = 0; i <= lenght; i++) { csvWriter.WriteField(GCList[i].OrderId); csvWriter.WriteField(GCList[i].EmployeeID); csvWriter.WriteField(GCList[i].LineNumber); csvWriter.WriteField(GCList[i].RewardName); csvWriter.WriteField(GCList[i].OrderDate); csvWriter.WriteField(GCList[i].Quantity); csvWriter.WriteField(GCList[i].LocalCost); csvWriter.WriteField(GCList[i].USDCost); csvWriter.WriteField(TotalUSDCost); csvWriter.WriteField(TotalLocalCost); csvWriter.NextRecord(); } writer.Flush(); var data = Encoding.UTF8.GetString(mem.ToArray()); Response.Clear(); Response.AddHeader("content-disposition", "attachment; filename=GiftCardsInvoice.csv"); Response.Charset = ""; Response.ContentType = "text/csv"; Response.Write(data.ToString()); Response.End(); }