Ejemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtBlockno.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Block No Cannot Be Empty");
                txtBlockno.Focus();
                return;
            }

            if (txtBlockname.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Block Name Cannot Be Empty");
                txtBlockname.Focus();
                return;
            }

            if (cmbProjectID.Text.Trim() == "")
            {
                MessageBox.Show("Project ID Cannot Be Empty");
                cmbProjectID.Focus();
                return;
            }

            if (cmbUoM.SelectedIndex == -1)
            {
                MessageBox.Show("An area unit must be selected");
                cmbUoM.Focus();
                return;
            }



            if (txtTotalArea.Text.Trim() == "")
            {
                MessageBox.Show("Total area must be enetered.");
                txtTotalArea.Focus();
                return;
            }
            if (txtDevArea.Text.Trim() == "")
            {
                MessageBox.Show("Developed area must be selected.");
                txtTotalArea.Focus();
                return;
            }

            foreach (DataGridViewRow dgr in dgBlockList.Rows)
            {
                if (dgr.Cells["ProjectNo"].Value.ToString().Trim().ToUpper() == cmbProjectID.Text.Trim().ToUpper() &&
                    dgr.Cells["BlockNo"].Value.ToString().Trim().ToUpper() == txtBlockno.Text.Trim().ToUpper() &&
                    this.id != Convert.ToInt32(dgr.Cells["ID1"].Value))
                {
                    MessageBox.Show("A block no with same ID already exists.");
                    return;
                }
            }

            clsBlock info      = new clsBlock();
            decimal  decResult = 0;

            bool b = decimal.TryParse(txtTotalArea.Text, out decResult);

            if (b == false)
            {
                MessageBox.Show("Total area is invalid.");
                txtTotalArea.Focus();
                return;
            }

            info.decTotalArea = decResult;

            b = decimal.TryParse(txtDevArea.Text, out decResult);
            if (b == false)
            {
                MessageBox.Show("Developed area is invalid.");
                txtDevArea.Focus();
                return;
            }

            info.decDevelopedArea = decResult;

            info.BlockNo   = txtBlockno.Text;
            info.BlockName = txtBlockname.Text;
            info.ProjectID = cmbProjectID.Text;
            info.strUOMid  = cmbUoM.Text;
            info.id        = this.id;

            bool result = da.AddBlockInfo(info);

            if (result == false)
            {
                MessageBox.Show("An Error Occoured");
            }

            LoadBlocks();

            Clear();
        }