private void ReadWriteCSVFile() { string date = System.DateTime.Now.ToString("ddMMyyhhmmss"); if (File.Exists(Server.MapPath(uppath))) { StreamReader sr = new StreamReader(Server.MapPath(uppath)); StreamWriter write = new StreamWriter(Server.MapPath(output)); CsvReader csvread = new CsvReader(sr); CsvWriter csw = new CsvWriter(write); IEnumerable <Gift_Cards_Invoice> record = csvread.GetRecords <Gift_Cards_Invoice>(); foreach (var rec in record) // Each record will be fetched and printed on the screen { csw.WriteRecord <Gift_Cards_Invoice>(rec); csw.NextRecord(); GiftCardsInvoiceDAL GCI = new GiftCardsInvoiceDAL(); GCI.ConnectionString = ConfigurationManager.ConnectionStrings["MySQLConn"].ToString(); GCI.InsertGiftCardsInvoice(rec); } sr.Close(); write.Close();//close file streams if (File.Exists(Server.MapPath(uppath))) { File.Delete(Server.MapPath(uppath)); } } }
protected void gvGCI_RowUpdating(object sender, GridViewUpdateEventArgs e) { GiftCardsInvoiceDAL GCIDAL = new GiftCardsInvoiceDAL(); GCIDAL.ConnectionString = ConfigurationManager.ConnectionStrings["MySQLConn"].ToString(); Gift_Cards_Invoice com = new Gift_Cards_Invoice(); com.OrderId = (gvGCI.Rows[e.RowIndex].FindControl("lblOrderId") as Label).Text; com.EmployeeID = (gvGCI.Rows[e.RowIndex].FindControl("lblEmployeeID") as Label).Text; com.LineNumber = (gvGCI.Rows[e.RowIndex].FindControl("tbLineNumber") as Label).Text; com.RewardName = (gvGCI.Rows[e.RowIndex].FindControl("lblRewardName") as Label).Text; com.OrderDate = Convert.ToDateTime((gvGCI.Rows[e.RowIndex].FindControl("lblOrderDate") as Label).Text); com.LocalCost = (gvGCI.Rows[e.RowIndex].FindControl("lblLocalCost") as Label).Text; com.Quantity = Convert.ToInt32((gvGCI.Rows[e.RowIndex].FindControl("lblQuantity") as Label).Text); //com.ReasonofReturen = gvGCI.DataKeys[e.RowIndex].Values[1].ToString(); com.ReasonofReturen = (gvGCI.Rows[e.RowIndex].FindControl("ddlReasonofReturen") as DropDownList).SelectedValue; com.Country = gvGCI.DataKeys[e.RowIndex].Values["Country"].ToString(); com.SKU = gvGCI.DataKeys[e.RowIndex].Values["SKU"].ToString(); GCIDAL.InsertGiftCardsInvoice(com); gvGCI.EditIndex = -1; GetGiftCardsInvoice(searcho, searche, sdate, edate); }