/// <summary> /// This method is used to write into the excel report file to print. /// </summary> public void ConvertToExcel() { string home_drive = Environment.SystemDirectory; home_drive = home_drive.Substring(0, 2); string strExcelPath = home_drive + "\\Servosms_ExcelFile\\Export\\"; Directory.CreateDirectory(strExcelPath); string path = home_drive + @"\Servosms_ExcelFile\Export\PrimarySecAnalysis.xls"; StreamWriter sw = new StreamWriter(path); string[] DiffMon = { "Apr." + DropYearFrom.SelectedItem.Text, "May." + DropYearFrom.SelectedItem.Text, "Jun." + DropYearFrom.SelectedItem.Text, "Jul." + DropYearFrom.SelectedItem.Text, "Aug." + DropYearFrom.SelectedItem.Text, "Sep." + DropYearFrom.SelectedItem.Text, "Oct." + DropYearFrom.SelectedItem.Text, "Nov." + DropYearFrom.SelectedItem.Text, "Dec." + DropYearFrom.SelectedItem.Text, "Jan." + DropYearTo.SelectedItem.Text, "Feb." + DropYearTo.SelectedItem.Text, "Mar." + DropYearTo.SelectedItem.Text }; string[] SameMon = { "Jan." + DropYearFrom.SelectedItem.Text, "Feb." + DropYearFrom.SelectedItem.Text, "Mar." + DropYearFrom.SelectedItem.Text, "Apr." + DropYearFrom.SelectedItem.Text, "May." + DropYearFrom.SelectedItem.Text, "Jun." + DropYearFrom.SelectedItem.Text, "Jul." + DropYearFrom.SelectedItem.Text, "Aug." + DropYearFrom.SelectedItem.Text, "Sep." + DropYearFrom.SelectedItem.Text, "Oct." + DropYearFrom.SelectedItem.Text, "Nov." + DropYearFrom.SelectedItem.Text, "Dec." + DropYearFrom.SelectedItem.Text }; double[] TotalAmt = new double[8]; sw.WriteLine("From Year\t" + DropYearFrom.SelectedItem.Text + "\tTo Year\t" + DropYearTo.SelectedItem.Text); sw.WriteLine("Month\tPrimary Sales\t\t\t\t\t\tSecondary Sales"); sw.WriteLine("\tLube\t2T\t4T\tGrease\tGen. Oils\tTotal\tLube\t2T\t4T\tGrease\tGen. Oils\tTotal"); int k = 0; SecSales = 0; PrimarySales = 0; if (DropYearFrom.SelectedIndex == DropYearTo.SelectedIndex) { for (int i = 0; i < SameMon.Length; i++) { TotalPrimarySales = 0; TotalSecSales = 0; k = 0; sw.WriteLine(SameMon[i].ToString() + "\t" + GetPrimaryLubeSales(SameMon[i].ToString()) + "\t" + GetPrimarySales("2T", SameMon[i].ToString()) + "\t" + GetPrimarySales("4T", SameMon[i].ToString()) + "\t" + GetPrimarySales("Grease", SameMon[i].ToString()) + "\t" + GetPrimarySalesGen(SameMon[i].ToString()) + "\t" + GenUtil.strNumericFormat(TotalPrimarySales.ToString()) + "\t" + GetSecLubeSales(SameMon[i].ToString()) + "\t" + GetSecSales("2T", SameMon[i].ToString()) + "\t" + GetSecSales("4T", SameMon[i].ToString()) + "\t" + GetSecSales("Grease", SameMon[i].ToString()) + "\t" + GetSecSalesGen(SameMon[i].ToString()) + "\t" + GenUtil.strNumericFormat(TotalSecSales.ToString())); PrimarySales += TotalPrimarySales; SecSales += TotalSecSales; TotalAmt[k] += double.Parse(GetPrimarySales("2T", SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetPrimarySales("4T", SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetPrimarySales("Grease", SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetPrimarySalesGen(SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSales("2T", SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSales("4T", SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSales("Grease", SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSalesGen(SameMon[i].ToString())); } } else { for (int i = 0; i < SameMon.Length; i++) { TotalPrimarySales = 0; TotalSecSales = 0; k = 0; sw.WriteLine(DiffMon[i].ToString() + "\t" + GetPrimaryLubeSales(DiffMon[i].ToString()) + "\t" + GetPrimarySales("2T", DiffMon[i].ToString()) + "\t" + GetPrimarySales("4T", DiffMon[i].ToString()) + "\t" + GetPrimarySales("Grease", DiffMon[i].ToString()) + "\t" + GetPrimarySalesGen(DiffMon[i].ToString()) + "\t" + GenUtil.strNumericFormat(TotalPrimarySales.ToString()) + "\t" + GetSecLubeSales(DiffMon[i].ToString()) + "\t" + GetSecSales("2T", DiffMon[i].ToString()) + "\t" + GetSecSales("4T", DiffMon[i].ToString()) + "\t" + GetSecSales("Grease", DiffMon[i].ToString()) + "\t" + GetSecSalesGen(DiffMon[i].ToString()) + "\t" + GenUtil.strNumericFormat(TotalSecSales.ToString())); PrimarySales += TotalPrimarySales; SecSales += TotalSecSales; TotalAmt[k] += double.Parse(GetPrimarySales("2T", DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetPrimarySales("4T", DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetPrimarySales("Grease", DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetPrimarySalesGen(DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSales("2T", DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSales("4T", DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSales("Grease", DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSalesGen(DiffMon[i].ToString())); } } k = 0; sw.WriteLine("Total\t" + GenUtil.strNumericFormat(PrimarySales.ToString()) + "\t" + GenUtil.strNumericFormat(TotalAmt[k].ToString()) + "\t" + GenUtil.strNumericFormat(TotalAmt[++k].ToString()) + "\t" + GenUtil.strNumericFormat(TotalAmt[++k].ToString()) + "\t" + GenUtil.strNumericFormat(TotalAmt[++k].ToString()) + "\t" + GenUtil.strNumericFormat(PrimarySales.ToString()) + "\t" + GenUtil.strNumericFormat(SecSales.ToString()) + "\t" + GenUtil.strNumericFormat(TotalAmt[++k].ToString()) + "\t" + GenUtil.strNumericFormat(TotalAmt[++k].ToString()) + "\t" + GenUtil.strNumericFormat(TotalAmt[++k].ToString()) + "\t" + GenUtil.strNumericFormat(TotalAmt[++k].ToString()) + "\t" + GenUtil.strNumericFormat(SecSales.ToString())); sw.Close(); }
/// <summary> /// This method is used to prepares the report file PrimarySecSalesAnalysys.txt for printing. /// </summary> public void makingReport() { try { string home_drive = Environment.SystemDirectory; home_drive = home_drive.Substring(0, 2); string path = home_drive + @"\Inetpub\wwwroot\Servosms\Sysitem\ServosmsPrintServices\ReportView\PrimarySecAnalysis.txt"; StreamWriter sw = new StreamWriter(path); string info = ""; // Condensed sw.Write((char)27); //added by vishnu sw.Write((char)67); //added by vishnu sw.Write((char)0); //added by vishnu sw.Write((char)12); //added by vishnu sw.Write((char)27); //added by vishnu sw.Write((char)78); //added by vishnu sw.Write((char)5); //added by vishnu sw.Write((char)27); //added by vishnu sw.Write((char)15); //********** string des = "----------------------------------------------------------------------------------------------------------------------------------------"; string Address = GenUtil.GetAddress(); string[] addr = Address.Split(new char[] { ':' }, Address.Length); sw.WriteLine(GenUtil.GetCenterAddr(addr[0], des.Length).ToUpper()); sw.WriteLine(GenUtil.GetCenterAddr(addr[1] + addr[2], des.Length)); sw.WriteLine(GenUtil.GetCenterAddr("Tin No : " + addr[3], des.Length)); sw.WriteLine(des); //********** sw.WriteLine(GenUtil.GetCenterAddr("===================================================================", des.Length)); sw.WriteLine(GenUtil.GetCenterAddr("Primary Secondary Sales Analysis Report From Year " + DropYearFrom.SelectedItem.Text + " To Year " + DropYearTo.SelectedItem.Text, des.Length)); sw.WriteLine(GenUtil.GetCenterAddr("===================================================================", des.Length)); //sw.WriteLine(" From Year : "+DropYearFrom.SelectedItem.Text+", To Year : "+DropYearTo.SelectedItem.Text); sw.WriteLine("+----------+-------------------------------------------------------------+-------------------------------------------------------------+"); sw.WriteLine("| | Primary Sales | Secondary Sales |"); sw.WriteLine("+----------+----------+---------+---------+---------+---------+----------+----------+---------+---------+---------+---------+----------+"); sw.WriteLine("| Month | Lube | 2T | 4T | Grease |gen. Oils| Total | Lube | 2T | 4T | Grease |gen. Oils| Total |"); sw.WriteLine("+----------+----------+---------+---------+---------+---------+----------+----------+---------+---------+---------+---------+----------+"); // 1234567890 123456789 123456789 123456789 123456789 123456789 1234567890 123456789 123456789 123456789 123456789 123456789 1234567890 info = " {0,-10:S} {1,10:F} {2,9:S} {3,9:S} {4,9:S} {5,9:S} {6,10:S} {7,10:F} {8,9:S} {9,9:S} {10,9:S} {11,9:S} {12,10:S}"; string[] DiffMon = { "Apr." + DropYearFrom.SelectedItem.Text, "May." + DropYearFrom.SelectedItem.Text, "Jun." + DropYearFrom.SelectedItem.Text, "Jul." + DropYearFrom.SelectedItem.Text, "Aug." + DropYearFrom.SelectedItem.Text, "Sep." + DropYearFrom.SelectedItem.Text, "Oct." + DropYearFrom.SelectedItem.Text, "Nov." + DropYearFrom.SelectedItem.Text, "Dec." + DropYearFrom.SelectedItem.Text, "Jan." + DropYearTo.SelectedItem.Text, "Feb." + DropYearTo.SelectedItem.Text, "Mar." + DropYearTo.SelectedItem.Text }; string[] SameMon = { "Jan." + DropYearFrom.SelectedItem.Text, "Feb." + DropYearFrom.SelectedItem.Text, "Mar." + DropYearFrom.SelectedItem.Text, "Apr." + DropYearFrom.SelectedItem.Text, "May." + DropYearFrom.SelectedItem.Text, "Jun." + DropYearFrom.SelectedItem.Text, "Jul." + DropYearFrom.SelectedItem.Text, "Aug." + DropYearFrom.SelectedItem.Text, "Sep." + DropYearFrom.SelectedItem.Text, "Oct." + DropYearFrom.SelectedItem.Text, "Nov." + DropYearFrom.SelectedItem.Text, "Dec." + DropYearFrom.SelectedItem.Text }; double[] TotalAmt = new double[8]; int k = 0; SecSales = 0; PrimarySales = 0; if (DropYearFrom.SelectedIndex == DropYearTo.SelectedIndex) { for (int i = 0; i < SameMon.Length; i++) { TotalPrimarySales = 0; TotalSecSales = 0; k = 0; sw.WriteLine(info, SameMon[i].ToString(), GetPrimaryLubeSales(SameMon[i].ToString()), GetPrimarySales("2T", SameMon[i].ToString()), GetPrimarySales("4T", SameMon[i].ToString()), GetPrimarySales("Grease", SameMon[i].ToString()), GetPrimarySalesGen(SameMon[i].ToString()), GenUtil.strNumericFormat(TotalPrimarySales.ToString()), GetSecLubeSales(SameMon[i].ToString()), GetSecSales("2T", SameMon[i].ToString()), GetSecSales("4T", SameMon[i].ToString()), GetSecSales("Grease", SameMon[i].ToString()), GetSecSalesGen(SameMon[i].ToString()), GenUtil.strNumericFormat(TotalSecSales.ToString())); PrimarySales += TotalPrimarySales; SecSales += TotalSecSales; TotalAmt[k] += double.Parse(GetPrimarySales("2T", SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetPrimarySales("4T", SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetPrimarySales("Grease", SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetPrimarySalesGen(SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSales("2T", SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSales("4T", SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSales("Grease", SameMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSalesGen(SameMon[i].ToString())); } } else { for (int i = 0; i < SameMon.Length; i++) { TotalPrimarySales = 0; TotalSecSales = 0; k = 0; sw.WriteLine(info, DiffMon[i].ToString(), GetPrimaryLubeSales(DiffMon[i].ToString()), GetPrimarySales("2T", DiffMon[i].ToString()), GetPrimarySales("4T", DiffMon[i].ToString()), GetPrimarySales("Grease", DiffMon[i].ToString()), GetPrimarySalesGen(DiffMon[i].ToString()), GenUtil.strNumericFormat(TotalPrimarySales.ToString()), GetSecLubeSales(DiffMon[i].ToString()), GetSecSales("2T", DiffMon[i].ToString()), GetSecSales("4T", DiffMon[i].ToString()), GetSecSales("Grease", DiffMon[i].ToString()), GetSecSalesGen(DiffMon[i].ToString()), GenUtil.strNumericFormat(TotalSecSales.ToString())); PrimarySales += TotalPrimarySales; SecSales += TotalSecSales; TotalAmt[k] += double.Parse(GetPrimarySales("2T", DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetPrimarySales("4T", DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetPrimarySales("Grease", DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetPrimarySalesGen(DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSales("2T", DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSales("4T", DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSales("Grease", DiffMon[i].ToString())); TotalAmt[++k] += double.Parse(GetSecSalesGen(DiffMon[i].ToString())); } } k = 0; sw.WriteLine("+----------+----------+---------+---------+---------+---------+----------+----------+---------+---------+---------+---------+----------+"); sw.WriteLine(info, " Total", GenUtil.strNumericFormat(PrimarySales.ToString()), GenUtil.strNumericFormat(TotalAmt[k].ToString()), GenUtil.strNumericFormat(TotalAmt[++k].ToString()), GenUtil.strNumericFormat(TotalAmt[++k].ToString()), GenUtil.strNumericFormat(TotalAmt[++k].ToString()), GenUtil.strNumericFormat(PrimarySales.ToString()), GenUtil.strNumericFormat(SecSales.ToString()), GenUtil.strNumericFormat(TotalAmt[++k].ToString()), GenUtil.strNumericFormat(TotalAmt[++k].ToString()), GenUtil.strNumericFormat(TotalAmt[++k].ToString()), GenUtil.strNumericFormat(TotalAmt[++k].ToString()), GenUtil.strNumericFormat(SecSales.ToString())); sw.WriteLine("+----------+----------+---------+---------+---------+---------+----------+----------+---------+---------+---------+---------+----------+"); sw.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }