public int addNewKalpi(Kalpi kalpi)
 {
     con.sqlCommand("addNewKalpi");
     con.InsertValstring("@kalpiCode", kalpi.KalpiCode);
     con.InsertValstring("@kalpiName", kalpi.KalpiName);
     con.InsertValstring("@address", kalpi.Address);
     con.InsertValstring("@city", kalpi.City);
     con.InsertValstring("@area", this.Area);
     con.InsertValint("@maxVoters", kalpi.MaxVoters);
     return(int.Parse(con.getVal("Result").ToString()));
 }
        private void buttonAdd_Click(object sender, EventArgs e)
        {
            if (textBoxAddress.Text.Trim() == "" || textBoxCity.Text.Trim() == "" ||
                textBoxCode.Text.Trim() == "" || textBoxKalpiName.Text.Trim() == "" ||
                textBoxMaxVoters.Text.Trim() == "")
            {
                MessageBox.Show("One or more of the fields is empty.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int maxVoters = 0;

            try
            {
                maxVoters = int.Parse(textBoxMaxVoters.Text.Trim());
                if (maxVoters <= 0 || maxVoters > 1000)
                {
                    throw new Exception();
                }
            }
            catch
            {
                MessageBox.Show("Invalid input in 'maximum Voters'.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            try
            {
                Kalpi kalpi = new Kalpi(textBoxCode.Text, "", textBoxKalpiName.Text, textBoxAddress.Text, textBoxCity.Text, areaManager.Area, 0, maxVoters, true);
                int   flag  = areaManager.addNewKalpi(kalpi);
                if (flag == 1)
                {
                    MessageBox.Show("The new Kalpi added to the DataBase.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("There is already kalpi with that kalpiCode", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch
            {
                MessageBox.Show("Add New Kalpi Failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Search for kalpi manager by his id, and show his details and his kalpi details
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void search_button_Click(object sender, EventArgs e)
        {
            clearFields();
            search_success = false;

            if (isIdValid() == false)
            {
                MessageBox.Show("Enter Valid ID.");
            }
            else
            {
                kalpi_mngr = area_mngr.SearchKalpiManager(IDtextBox.Text.ToString().Trim(), area_mngr.Area);
                if (kalpi_mngr == null)
                {
                    MessageBox.Show("No such kalpi manager in " + area_mngr.Area + " area.");
                }
                else
                {
                    search_success = true;

                    first_text.Text   = kalpi_mngr.FName;
                    last_text.Text    = kalpi_mngr.LName;
                    address_text.Text = kalpi_mngr.Address + ", " + kalpi_mngr.City;
                    phone_text.Text   = kalpi_mngr.Tell;

                    kalpi = area_mngr.SearchKalpiByManager(IDtextBox.Text.ToString().Trim());
                    if (kalpi != null)
                    {
                        code_text.Text     = kalpi.KalpiCode;
                        area_text.Text     = kalpi.Area;
                        city_text.Text     = kalpi.City;
                        location_text.Text = kalpi.Address;
                    }
                }
            }
        }