private async void button_AddToCart_Click(object sender, EventArgs e)
        {
            // Check Valid Quantity
            if (!CUtils.IsNumeric(textBox_Quantity.Text))
            {
                MessageBox.Show("Invalid Quantity!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            int quantity = Int32.Parse(textBox_Quantity.Text);

            // Check Quantity Inventory Exceed
            int temp2 = (int)(dataGridView_SellerList.SelectedRows[0].Cells["quantity"].Value);

            if (quantity > temp2)
            {
                MessageBox.Show("Quantity Exceeds Seller's Capability!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // Try Retrieve Existing Cart
            CUser_Seller   temp     = (CUser_Seller)(dataGridView_SellerList.SelectedRows[0].Cells["extra_2"].Value);
            CCustomer_Cart cartitem = await CCustomer_Cart.Retrieve(CUser.cur_user.id, item.id, temp.user_id);

            if (cartitem != null)
            {
                if (!(await cartitem.Commit(cartitem.quantity + quantity)))
                {
                    if (CUtils.LastLogMsg != null)
                    {
                        MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("Cause: Unknown", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    return;
                }
            }
            else if (!(await CCustomer_Cart.Register(CUser.cur_user.id,
                                                     item.id,
                                                     temp.user_id,
                                                     quantity)))  // Create New Cart
            {
                if (CUtils.LastLogMsg == null || CUtils.LastLogMsg.Equals("Inventory Already Exists!"))
                {
                    MessageBox.Show("Cause: Unknown", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                return;
            }
            MessageBox.Show("Successfully Added to Cart!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Visible = false;
            this.Dispose();
        }
Exemple #2
0
        private async void button_Main_Click(object sender, EventArgs e)
        {
            if (!ButtonState)
            {
                // Check Constraints
                if (String.IsNullOrWhiteSpace(textBox_Name.Text))
                {
                    MessageBox.Show("Invalid Name!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (comboBox_Catagory.SelectedIndex < 0)
                {
                    MessageBox.Show("Invalid Catagory!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (String.IsNullOrWhiteSpace(richTextBox_Description.Text))
                {
                    MessageBox.Show("Invalid Description!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                foreach (extFieldStruct x in extField)
                {
                    if (String.IsNullOrWhiteSpace(x.textBox.Text))
                    {
                        {
                            MessageBox.Show("Invalid " + x.label.Text + "!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                    }
                }
                if (pictureBox_Picture.Image == null || pictureBox_Picture.Image.Equals(global::OPS.Properties.Resources.noimage))
                {
                    MessageBox.Show("Invalid Image!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // Register Product
                if (!(await CProduct.Register(((CCatagory)comboBox_Catagory.SelectedItem).id,
                                              textBox_Name.Text,
                                              richTextBox_Description.Text,
                                              pictureBox_Picture.Image)))
                {
                    if (CUtils.LastLogMsg != null)
                    {
                        MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("Cause: Unknown", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    return;
                }
                item = await CProduct.Retrieve(((CCatagory)comboBox_Catagory.SelectedItem).id,
                                               textBox_Name.Text);

                if (item == null)
                {
                    if (CUtils.LastLogMsg != null)
                    {
                        MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("Cause: Unknown", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    return;
                }

                // Lock Product Specifications
                textBox_Name.ReadOnly            = true;
                comboBox_Catagory.Enabled        = false;
                richTextBox_Description.ReadOnly = true;
                foreach (extFieldStruct x in extField)
                {
                    x.textBox.ReadOnly = true;
                }
                button_Browse.Visible = false;

                // Change Form & Button State
                tableLayoutPanel2.Visible = true;
                button_Main.Text          = "Add To Inventory";
                ButtonState = true;
            }
            else
            {
                if (!CUtils.IsNumeric(textBox_Price.Text))
                {
                    MessageBox.Show("Invalid Price!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (!CUtils.IsNumeric(textBox_Quantity.Text))
                {
                    MessageBox.Show("Invalid Quantity!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (comboBox_Pincode.SelectedIndex < 0)
                {
                    MessageBox.Show("Invalid Pincode!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (!CUtils.IsNumeric(textBox_Warranty.Text))
                {
                    MessageBox.Show("Invalid Warranty!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                Console.WriteLine("QUAT=" + Int32.Parse(textBox_Quantity.Text));
                if (!(await CSeller_Inventory.Register(CUser.cur_user.id,
                                                       item.id,
                                                       Double.Parse(textBox_Price.Text),
                                                       Int32.Parse(textBox_Quantity.Text),
                                                       ((CLocation)comboBox_Pincode.SelectedItem).pincode,
                                                       Double.Parse(textBox_Warranty.Text))))
                {
                    if (CUtils.LastLogMsg.Equals("Inventory Already Exists!"))
                    {
                        CSeller_Inventory inv = await CSeller_Inventory.Retrieve(CUser.cur_user.id, item.id);

                        if (inv != null)
                        {
                            if (!(await inv.Commit(inv.price,
                                                   inv.quantity + Int32.Parse(textBox_Quantity.Text),
                                                   inv.pincode,
                                                   inv.warranty)))
                            {
                                MessageBox.Show("Successfully Added to Inventory!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                this.Visible = false;
                                this.Dispose();
                                return;
                            }
                        }
                        MessageBox.Show("Cause: Unknown", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                    if (CUtils.LastLogMsg != null)
                    {
                        MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show("Cause: Unknown", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                    return;
                }
                MessageBox.Show("Successfully Added to Inventory!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Visible = false;
                this.Dispose();
            }
        }
 private async void button_AddToInventory_Click(object sender, EventArgs e)
 {
     if (!CUtils.IsNumeric(textBox_Price.Text))
     {
         MessageBox.Show("Invalid Price!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     if (!CUtils.IsNumeric(textBox_Quantity.Text))
     {
         MessageBox.Show("Invalid Quantity!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     if (comboBox_Pincode.SelectedIndex < 0)
     {
         MessageBox.Show("Invalid Pincode!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     if (!CUtils.IsNumeric(textBox_Warranty.Text))
     {
         MessageBox.Show("Invalid Warranty!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     if (invitem != null)
     {
         if (!(await invitem.Commit(invitem.price,
                                    invitem.quantity + Int32.Parse(textBox_Quantity.Text),
                                    invitem.pincode,
                                    invitem.warranty)))
         {
             if (CUtils.LastLogMsg != null)
             {
                 MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
             else
             {
                 MessageBox.Show("Cause: Unknown", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
             return;
         }
     }
     else if (!(await CSeller_Inventory.Register(CUser.cur_user.id,
                                                 item.id,
                                                 Double.Parse(textBox_Price.Text),
                                                 Int32.Parse(textBox_Quantity.Text),
                                                 ((CLocation)comboBox_Pincode.SelectedItem).pincode,
                                                 Double.Parse(textBox_Warranty.Text))))
     {
         if (CUtils.LastLogMsg == null || CUtils.LastLogMsg.Equals("Inventory Already Exists!"))
         {
             MessageBox.Show("Cause: Unknown", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
         else
         {
             MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
         return;
     }
     MessageBox.Show("Successfully Added to Inventory!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
     this.Visible = false;
     this.Dispose();
 }