/// <summary>
        /// Put user code to initialize the page here
        /// This method is used for setting the Session variable for userId and
        /// after that filling the required dropdowns with database values
        /// and also check accessing priviledges for particular user
        /// and generate the next ID also.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                //string User_ID;
                uid = (Session["User_Name"].ToString());
            }
            catch (Exception ex)
            {
                CreateLogFiles.ErrorLog("Form:TaxEntry_Master.aspx,Method:pageLoad" + " EXCEPTION  " + ex.Message + " userid  " + uid);
                Response.Redirect("../../Sysitem/ErrorPage.aspx", false);
                return;
            }
            if (!IsPostBack)
            {
                checkPrivileges();

                // The code below fills the combo with products names of type fuel.
                System.Data.SqlClient.SqlDataReader rdr = null;
                obj.SelectQuery("select Prod_Name from products where Category = 'Fuel'", ref rdr);
                drp_pname.DataSource     = rdr;
                drp_pname.DataValueField = "Prod_Name";
                drp_pname.DataBind();
                drp_pname.Items.Insert(0, "Select");
                obj.Dispose();
            }
        }
        //This is used to make report for printing with making a file.txt.
        public void reportmaking()
        {
            /*
             *                                                              ======================
             *                                                                      CREDIT BILL REPORT
             *                                                              ======================
             * M/s        :
             * Bill No    :
             * Bill Date  :
             +----------+-----+-------------------------+----+-------+---------+-------------+
             |Inv.Date  |Slip |       Product Name      |Qty | Rate  | Amount  | Vehicle.No  |
             +----------+-----+-------------------------+----+-------+---------+-------------+
             * 18/7/2006  12345 1234567890123456789012345 1235 1234567 123456.00 1234567890123  DD/MM/YYYY  XXX    1234567890123456789012345 123456.78 123456.00  1234567.00  xxxxxxxxxx
             */
            System.Data.SqlClient.SqlDataReader rdr = null;
            string home_drive = Environment.SystemDirectory;

            home_drive = home_drive.Substring(0, 2);
            string       path = home_drive + @"\Inetpub\wwwroot\Servosms\Sysitem\ServosmsPrintServices\ReportView\CreditBillReport.txt";
            StreamWriter sw   = new StreamWriter(path);

            string sql     = "";
            string info    = "";
            string strDate = "";

            string abc      = DropCustID.SelectedItem.Text;
            string billno   = lblBillNo.Text;
            string billdate = lblDate.Text;

            //sql="select sm.invoice_no, slip_no, invoice_date, vehicle_no, prod_Name+ ' ' +Pack_Type Prod_Name, qty, rate, amount from sales_master sm, sales_details sd, products p where sm.invoice_date between '"+ ToMMddYYYY(txtDateFrom.Text) +"' and dateadd(day,1,'"+ ToMMddYYYY(txtDateTO.Text) + "') and sm.cust_id in ( select cust_id from customer where cust_name=substring('"+ DropCustID.SelectedItem.Value +"',1,charindex(':','"+ DropCustID.SelectedItem.Value +"')-1)  and city=substring('"+ DropCustID.SelectedItem.Value +"',charindex(':','"+ DropCustID.SelectedItem.Value +"')+1,len('"+ DropCustID.SelectedItem.Value +"'))) and sm.invoice_no = sd.invoice_no and sd.prod_id = p.prod_id";
            if (DropVehicleNo.SelectedIndex == 0)
            {
                sql = "select sm.invoice_no, slip_no, invoice_date, vehicle_no, prod_Name+ ' ' +Pack_Type Prod_Name, qty, rate, amount from sales_master sm, sales_details sd, products p where sm.invoice_date between '" + ToMMddYYYY(txtDateFrom.Text) + "' and dateadd(day,1,'" + ToMMddYYYY(txtDateTO.Text) + "') and sm.cust_id in ( select cust_id from customer where cust_name=substring('" + DropCustID.SelectedItem.Value + "',1,charindex(':','" + DropCustID.SelectedItem.Value + "')-1)  and city=substring('" + DropCustID.SelectedItem.Value + "',charindex(':','" + DropCustID.SelectedItem.Value + "')+1,len('" + DropCustID.SelectedItem.Value + "'))) and sm.sales_type = 'credit' and sm.invoice_no = sd.invoice_no and sd.prod_id = p.prod_id";
            }
            else
            {
                sql = "select sm.invoice_no, slip_no, invoice_date, vehicle_no, prod_Name+ ' ' +Pack_Type Prod_Name, qty, rate, amount from sales_master sm, sales_details sd, products p where sm.invoice_date between '" + ToMMddYYYY(txtDateFrom.Text) + "' and dateadd(day,1,'" + ToMMddYYYY(txtDateTO.Text) + "') and sm.cust_id in ( select cust_id from customer where cust_name=substring('" + DropCustID.SelectedItem.Value + "',1,charindex(':','" + DropCustID.SelectedItem.Value + "')-1)  and city=substring('" + DropCustID.SelectedItem.Value + "',charindex(':','" + DropCustID.SelectedItem.Value + "')+1,len('" + DropCustID.SelectedItem.Value + "'))) and sm.sales_type = 'credit' and sm.invoice_no = sd.invoice_no and sd.prod_id = p.prod_id and Vehicle_No = '" + DropVehicleNo.SelectedItem.Text + "'";
            }


            dbobj.SelectQuery(sql, ref rdr);
            // Condensed
            sw.Write((char)27);
            sw.Write((char)15);

            sw.WriteLine("                                  ======================");
            sw.WriteLine("                                    CREDIT BILL REPORT ");
            sw.WriteLine("                                  ======================  ");
            sw.WriteLine("M/s        : " + abc);
            sw.WriteLine("Bill No    : " + billno);
            sw.WriteLine("Bill Date  : " + billdate);
            sw.WriteLine("+----------+--------+------------------------------+-----+--------+----------+--------------+");
            sw.WriteLine("|Inv.Date  |Slip No |       Product Name           | Qty |  Rate  | Amount   | Vehicle.No   |");
            sw.WriteLine("+----------+--------+------------------------------+-----+--------+----------+--------------+");
            //             18/7/2006  12345678 123456789012345678901234567890 12345 12345678 1234567.00 1234567890123
            if (rdr.HasRows)
            {
                info = " {0,-10:S} {1,8:S} {2,-30:S} {3,5:F} {4,8:F} {5,10:F} {6,-14:S}";
                while (rdr.Read())
                {
                    // Trim Date
                    strDate = rdr["invoice_date"].ToString().Trim();
                    int pos = strDate.IndexOf(" ");

                    if (pos != -1)
                    {
                        strDate = strDate.Substring(0, pos);
                    }
                    else
                    {
                        strDate = "";
                    }

                    sw.WriteLine(info, GenUtil.str2DDMMYYYY(strDate),
                                 rdr["Slip_no"].ToString().Trim(),
                                 strTrim(rdr["prod_Name"].ToString()),
                                 rdr["qty"].ToString().Trim(),
                                 rdr["rate"].ToString().Trim(),
                                 GenUtil.strNumericFormat(rdr["amount"].ToString().Trim()),
                                 rdr["Vehicle_no"].ToString().Trim());
                }
            }

            sw.WriteLine("+----------+--------+------------------------------+-----+--------+----------+--------------+");
            // deselect Condensed
            sw.Write((char)18);
            sw.Write((char)12);
            dbobj.Dispose();
            sw.Close();

            rdr.Close();
        }