Beispiel #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            //fetching connection string from ConstantData class
            using (connection = new SqlConnection(ConstantData.getConnectionString()))
                using (adapter = new SqlDataAdapter("select consumer_name from Consumer", connection))
                {
                    //connection.Open();
                    DataTable consumer_col = new DataTable();
                    adapter.Fill(consumer_col);

                    //Inserting extra row in DataTable
                    DataRow row = consumer_col.NewRow();
                    row["consumer_name"] = "Select Consumer";
                    consumer_col.Rows.InsertAt(row, 0);

                    consumerList.DisplayMember = "consumer_name";
                    consumerList.DataSource    = consumer_col;
                }
        }
Beispiel #2
0
        private void getConsumerDetails(object sender, EventArgs e)
        {
            clearForm();

            string name = consumerList.Text;

            addrText.Text  = "";
            waterText.Text = "";
            quotaText.Text = "";
            using (connection = new SqlConnection(ConstantData.getConnectionString()))
            {
                DataTable consumerDetail = new DataTable();
                connection.Open();
                SqlDataReader myReader  = null;
                SqlCommand    myCommand = new SqlCommand("select * from Consumer where consumer_name = '" + name + "'", connection);

                myReader = myCommand.ExecuteReader();


                if (myReader.Read())
                {
                    addrText.Text  = (myReader["Address"].ToString());
                    waterText.Text = (myReader["water_source"].ToString());
                    quotaText.Text = (myReader["sanction_quota"].ToString());

                    //storing data for further referance
                    ConstantData.customerName    = name;
                    ConstantData.customerAddress = myReader["Address"].ToString();
                    ConstantData.waterResource   = myReader["water_source"].ToString();
                    ConstantData.sanctionQuota   = double.Parse(myReader["sanction_quota"].ToString());

                    //take contact details from db if required
                }
                else
                {
                    //MessageBox.Show("No Record Found.");
                }
            }
        }
Beispiel #3
0
        private void addDetailstoList(object sender, EventArgs e)
        {
            string contract    = contractType.Text;
            double kharip_rate = 0;
            double rabbi_rate  = 0;
            double hot_rate    = 0;

            using (connection = new SqlConnection(ConstantData.getConnectionString()))
            {
                DataTable consumerDetail = new DataTable();
                connection.Open();
                SqlDataReader myReader  = null;
                SqlCommand    myCommand = new SqlCommand("select * from Contract where contract_type = '" + contract + "'", connection);
                //MessageBox.Show(contract);
                myReader = myCommand.ExecuteReader();

                if (myReader.Read())
                {
                    if (!checkMeterInstalled.Checked)
                    {
                        if (int.Parse(meter1.Text) > int.Parse(meter2.Text))
                        {
                            MessageBox.Show("Please enter correct details");
                        }
                    }
                    //addrText.Text = (myReader["Address"].ToString());
                    kharip_rate = float.Parse((myReader["kharip_rate"]).ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                    rabbi_rate  = float.Parse((myReader["rabbi_rate"]).ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                    hot_rate    = float.Parse((myReader["hot_season_rate"]).ToString(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat);
                    //Adding record in bill table
                    ConstantData.contractType = contract;
                    updateBill(kharip_rate, rabbi_rate, hot_rate);
                }
                else
                {
                    MessageBox.Show("Unable to fetch contract details");
                }
            }
        }