Example #1
0
        private async void button_Submit_Click(object sender, EventArgs e)
        {
            // Get & Validate Username
            String username = textBox_Username.Text.Trim();

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

            // Get & Validate Password
            String password = textBox_Password.Text.Trim();

            if (!CUtils.IsValidPassword(password))
            {
                if (CUtils.LastLogMsg != null)
                {
                    MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Cause: Invalid Password!", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                return;
            }
            password = CUtils.sha256(password);

            // Get & Validate Account/User Type
            Byte type = (Byte)comboBox_Account.SelectedIndex;

            if (!(await CUtils.IsValidUserType(type)))
            {
                if (CUtils.LastLogMsg != null)
                {
                    MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Cause: Invalid Account Type!", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                return;
            }

            // Get & Validate EmailID
            String email = textBox_EmailID.Text.Trim();

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

            // Register User
            if (!(await CUser.Register(username, password, email, type)))
            {
                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("You have Successfully Registered!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            prev.StartPosition = this.StartPosition;
            prev.Location      = this.Location;
            prev.Visible       = true;
            this.Close();
            this.Dispose();
        }
Example #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();
            }
        }
Example #3
0
        public async static Task <List <CProduct> > SearchProductList(Int32 catagory_id, String keyword)
        {
            List <CProduct> ret = new List <CProduct>();

            try
            {
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = Program.conn;
                String sql = "SELECT * FROM `product`";
                if (catagory_id != 0)
                {
                    sql += " WHERE `catagory_id` = @catagory_id";
                    cmd.Parameters.AddWithValue("@catagory_id", catagory_id);
                }
                else
                {
                    sql += " WHERE (`catagory_id` = '0' OR `catagory_id` is NULL)";
                }
                if (!String.IsNullOrWhiteSpace(keyword))
                {
                    sql += " AND `name` LIKE CONCAT('%', '" + keyword + "', '%')";
                }
                cmd.CommandText = sql;
                DbDataReader reader = await cmd.ExecuteReaderAsync();

                cmd.Dispose();
                while (await reader.ReadAsync())
                {
                    ret.Add
                    (
                        new CProduct(reader.GetInt32(reader.GetOrdinal("id")),
                                     catagory_id,
                                     reader.GetString(reader.GetOrdinal("name")),
                                     reader.GetString(reader.GetOrdinal("description")),
                                     (await reader.IsDBNullAsync(reader.GetOrdinal("minprice"))) ? 0.0 : reader.GetDouble(reader.GetOrdinal("minprice")),
                                     (await reader.IsDBNullAsync(reader.GetOrdinal("sales"))) ? 0 : reader.GetInt32(reader.GetOrdinal("sales")),
                                     (await reader.IsDBNullAsync(reader.GetOrdinal("raters"))) ? 0 : reader.GetInt32(reader.GetOrdinal("raters")),
                                     (await reader.IsDBNullAsync(reader.GetOrdinal("rating"))) ? 0.0 : reader.GetDouble(reader.GetOrdinal("rating")),
                                     (await reader.IsDBNullAsync(reader.GetOrdinal("quantity"))) ? 0 : reader.GetInt32(reader.GetOrdinal("quantity")),
                                     (await reader.IsDBNullAsync(reader.GetOrdinal("image"))) ? global::OPS.Properties.Resources.noimage : CUtils.GetImageFromReader(reader, reader.GetOrdinal("image")))
                    );
                }
                if (!reader.IsClosed)
                {
                    reader.Close();
                }
                CUtils.LastLogMsg = null;
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.WriteLine(ex.Message + " " + ex.StackTrace);
#endif
                CUtils.LastLogMsg = "Unahandled Exception!";
            }
            return(ret);
        }
Example #4
0
        public async static Task <CProduct> Retrieve(Int32 catagory_id, String name)
        {
            CProduct ret = null;

            try
            {
                String       sql = "SELECT * FROM `product` WHERE `catagory_id` = @catagory_id and `name` = @name LIMIT 1";
                MySqlCommand cmd = new MySqlCommand(sql, Program.conn);
                cmd.Parameters.AddWithValue("@catagory_id", catagory_id);
                cmd.Parameters.AddWithValue("@name", name);
                DbDataReader reader = await cmd.ExecuteReaderAsync();

                cmd.Dispose();
                if (!(await reader.ReadAsync()))
                {
                    if (!reader.IsClosed)
                    {
                        reader.Close();
                    }
                    CUtils.LastLogMsg = "Product with catagory_id '" + catagory_id + "' and name '" + name + "' not found!";
                    return(ret);
                }
                ret = new CProduct(reader.GetInt32(reader.GetOrdinal("id")),
                                   catagory_id,
                                   name,
                                   reader.GetString(reader.GetOrdinal("description")),
                                   (await reader.IsDBNullAsync(reader.GetOrdinal("minprice"))) ? 0 : reader.GetDouble(reader.GetOrdinal("minprice")),
                                   (await reader.IsDBNullAsync(reader.GetOrdinal("sales"))) ? 0 : reader.GetInt32(reader.GetOrdinal("sales")),
                                   (await reader.IsDBNullAsync(reader.GetOrdinal("raters"))) ? 0 : reader.GetInt32(reader.GetOrdinal("raters")),
                                   (await reader.IsDBNullAsync(reader.GetOrdinal("rating"))) ? 0 : reader.GetDouble(reader.GetOrdinal("rating")),
                                   (await reader.IsDBNullAsync(reader.GetOrdinal("quantity"))) ? 0 : reader.GetInt32(reader.GetOrdinal("quantity")),
                                   (await reader.IsDBNullAsync(reader.GetOrdinal("image"))) ? global::OPS.Properties.Resources.noimage : CUtils.GetImageFromReader(reader, reader.GetOrdinal("image")));
                if (!reader.IsClosed)
                {
                    reader.Close();
                }
                CUtils.LastLogMsg = null;
            }
            catch (Exception ex)
            {
#if DEBUG
                Console.WriteLine(ex.Message + " " + ex.StackTrace);
#endif
                CUtils.LastLogMsg = "Unahandled Exception!";
            }
            return(ret);
        }
Example #5
0
        private async void button_Submit_Click(object sender, EventArgs e)
        {
            // Get & Validate Username
            String username = textBox_Username.Text.Trim();

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

            // Get & Validate Password
            String password = textBox_Password.Text.Trim();

            if (!CUtils.IsValidPassword(password))
            {
                if (CUtils.LastLogMsg != null)
                {
                    MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Cause: Invalid Password!", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                return;
            }
            password = CUtils.sha256(password);

            // Get & Validate Account/User Type
            Byte type = (Byte)comboBox_Account.SelectedIndex;

            if (!(await CUtils.IsValidUserType(type)))
            {
                if (CUtils.LastLogMsg != null)
                {
                    MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show("Cause: Invalid Account Type!", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                return;
            }

            // Login User
            CUser.cur_user = await CUser.Retrieve(username, password, type);

            if (CUser.cur_user == 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;
            }

            /*if (!(await CUser.cur_user.login()))
             * {
             *  if (CUtils.LastLogMsg != null)
             *      MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
             *  else
             *      MessageBox.Show("Cause: " + CUtils.LastLogMsg, "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             *  return;
             * }*/
            MessageBox.Show("You have Successfully Logged In!" + type, "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            switch (type)
            {
            case 0: new Customer_Home(this).Visible = true; break;

            case 1: new Seller_Home(this).Visible = true; break;
                //case 2: new OrderManager_Home(this).Visible = true; break;
                //case 3: new ProductManager_Home(this).Visible = true; break;
            }
            this.Visible = false;
        }
 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();
 }