Esempio n. 1
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            try
            {
                MdlBill bobj = new MdlBill();


                //dgvExcel.DataSource = obj.GetBillDataFromFile(tbFileName.Text);
                //  reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1",obj.GetBillDataFromFile(tbFileName.Text)) );
                // reportViewer1.LocalReport.DataSources = obj.GetBillDataFromFile(tbFileName.Text);
                // MdlBillBindingSource.DataSource = obj.GetBillDataFromFile(tbFileName.Text);

                DataTable dt1 = new DataTable();
                dt1 = obj.GetBillDataFromFile(tbFileName.Text);

                MdlBillBindingSource.DataSource = bobj.ConvertDtToList(dt1);
                //dgvExcel.DataSource = MdlBillBindingSource;

                //reportViewer2.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", dt1));
                reportViewer2.RefreshReport();
            }
            catch (Exception ex)
            {
                MessageBox.Show("An Error Occoured: Check data otherwise contact admin:\n" + ex.Message);
            }
        }
Esempio n. 2
0
        public List <MdlBill> ConvertDtToList(DataTable dt)
        {
            //MngExcel cexl = new MngExcel();
            //dt = cexl.GetBillDataFromFile(filepath);

            List <MdlBill> lst = new List <MdlBill>();
            MdlBill        obj;

            foreach (DataRow dr in dt.Rows)
            {
                obj                = new MdlBill();
                obj.consumerid     = dr["ConsumerID"].ToString();
                obj.oldid          = dr["OldID"].ToString();
                obj.consumername   = dr["ConsumerName"].ToString();
                obj.consumertype   = dr["ConsumerType"].ToString();
                obj.cnicno         = dr["CNICNo"].ToString();
                obj.contactno      = dr["ContactNo"].ToString();
                obj.zone           = dr["Zone"].ToString();
                obj.uc             = dr["UC"].ToString();
                obj.plothouse      = dr["PlotHouseNo"].ToString();
                obj.houseentrtance = dr["Houseentrance"].ToString();
                obj.plotsize       = dr["PlotSize"].ToString();
                obj.streetno       = dr["Street#"].ToString();
                obj.sectormohalla  = dr["SectorMohallah"].ToString();
                obj.phase          = dr["Phase"].ToString();
                obj.area           = dr["Area"].ToString();
                obj.from           = dr["BillingPeriodFrom"].ToString();
                obj.to             = dr["BillingPeriodTo"].ToString();
                obj.issuedate      = dr["Issueddate"].ToString();
                obj.duedate        = dr["DueDate"].ToString();
                obj.watercg        = dr["WaterCharges"] == System.DBNull.Value ? 0: Convert.ToDouble(dr["WaterCharges"]);
                obj.conservancycg  = dr["ConservancyCharges"] == System.DBNull.Value? 0: Convert.ToDouble(dr["ConservancyCharges"]);
                obj.seweragecg     = dr["SewerageCharges"] == System.DBNull.Value? 0: Convert.ToDouble(dr["SewerageCharges"]);
                obj.newconncg      = dr["NewConnectionCharges"] == System.DBNull.Value?0:  Convert.ToDouble(dr["NewConnectionCharges"]);

                obj.totalcrntdue          = dr["TotalCurrentdues"] == System.DBNull.Value? 0: Convert.ToDouble(dr["TotalCurrentdues"]);
                obj.arears                = dr["Arears"] == System.DBNull.Value ? 0: Convert.ToDouble(dr["Arears"]);
                obj.amountpaybyduedate    = dr["AmountPayablebyDuedate"] == System.DBNull.Value? 0: Convert.ToDouble(dr["AmountPayablebyDuedate"]);
                obj.surcharge             = dr["Surcharge@10%afterduedate"] == System.DBNull.Value ? 0: Convert.ToDouble(dr["Surcharge@10%afterduedate"]);
                obj.amountpayafterduedate = dr["AmountPayableafterDuedate"] == System.DBNull.Value ? 0 : Convert.ToDouble(dr["AmountPayableafterDuedate"]);

                if (obj.consumername.Length > 80)
                {
                    obj.consumername = obj.consumername.Substring(0, 80);
                }
                if (obj.sectormohalla.Length > 12)
                {
                    obj.sectormohalla = obj.sectormohalla.Substring(0, 12);
                }
                if (obj.area.Length > 16)
                {
                    obj.area = obj.area.Substring(0, 16);
                }
                if (obj.plotsize.Length > 12)
                {
                    obj.plotsize = obj.plotsize.Substring(0, 12);
                }

                //obj.account = dr["Account"].ToString();
                lst.Add(obj);
            }
            return(lst);
        }