Ejemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //   do
            //  {

            /*  for (int i = 0; i < itemList.Count; i++)
             * {
             *    Item item = (Item)itemList[i]; //retrieve attribute values from this specific RFQ.
             *    if (item.PartNumber == txtPartNumber.Text)
             *    {
             *        MessageBox.Show("PartNumber already exist", "Incomplete Fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
             *        tabItemForm.SelectedTab = tabItemForm.TabPages["tabItemDetails"];
             *        return;
             *    } */


            int  numericPartNumber;
            bool numberNumeric   = int.TryParse(PartNumber, out numericPartNumber);
            int  countPartNumber = sql.GetPNCount(PartNumber);    //call db to check if there is already that part number that exist

            dateResult = DateTime.Compare(FromDate, ToDate);

            if (
                (PartNumber.Length == 0) ||
                (ItemName.Length == 0) ||
                (SupplierUnitPrice.Length == 0) ||
                (Markup.Length == 0) ||
                (ReicUnitPrice.Length == 0) ||
                (Moq.Length == 0) ||
                (Uom.Length == 0)
                )
            {
                MessageBox.Show("All Fields are Required to be Filled out.", "Incomplete Fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tabItemForm.SelectedTab = tabItemForm.TabPages["tabItemDetails"];
                return;
            }

            if (numberNumeric == false)     //to check if partNumber only consists of numbers.
            {
                MessageBox.Show("Part Number consists of Alphabet.", "Incorrect Field", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tabItemForm.SelectedTab = tabItemForm.TabPages["tabItemDetails"];
                return;
            }

            if (countPartNumber > 0)
            {
                MessageBox.Show("Part Number already exists.", "Incorrect Field", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tabItemForm.SelectedTab = tabItemForm.TabPages["tabItemDetails"];
                return;
            }

            if (nudSuppPrice.Text == "0")     //SuppPrice cannot be zero
            {
                MessageBox.Show("Supplier's Unit Price cannot be zero.", "Incorrect Field", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tabItemForm.SelectedTab = tabItemForm.TabPages["tabItemDetails"];
                return;
            }

            if (cbbSupplierName.Text == "Select Supplier")
            {
                MessageBox.Show("Please select a Supplier.", "Incomplete Fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tabItemForm.SelectedTab = tabItemForm.TabPages["tabSupplierDetails"];
                return;
            }

            if (dateResult > 0)
            {
                MessageBox.Show("To Date of the Validity Period should be later than From Date.", "Invalid Date", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tabItemForm.SelectedTab = tabItemForm.TabPages["tabItemDetails"];
                return;
            }


            if (dateResult == 0)
            {
                MessageBox.Show("To Date of the Validity Period should be later than From Date.", "Invalid Date", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tabItemForm.SelectedTab = tabItemForm.TabPages["tabItemDetails"];
                return;
            }
            SupplierIDFK = sql.SelectSupplierID(SupplierName);


            cancel = false;
            this.Close();
        }