示例#1
0
        public Carat GetCaratByID(int id)
        {
            Carat result = null;

            string       mySelectQuery = "SELECT carat FROM master_carat WHERE id=" + id.ToString() + ";";
            MySqlCommand myCommand     = new MySqlCommand(mySelectQuery, dbConn);

            if (isDBConnected)
            {
                MySqlDataReader myReader;
                myReader = myCommand.ExecuteReader();
                try
                {
                    if (myReader.HasRows)
                    {
                        myReader.Read();
                        string value = myReader.GetString("carat");
                        result = new Carat(id, value);
                    }
                    else
                    {
                        throw new Exception("Error ID: " + id + " not found in carat!");
                    }
                }
                finally
                {
                    myReader.Close();
                }
            }

            return(result);
        }
示例#2
0
        /*
         * Master Carat
         */
        #region MasterCarat
        public List <Carat> GetAllCarat()
        {
            List <Carat> result        = new List <Carat>();
            string       mySelectQuery = "SELECT id, nama FROM master_carat;";
            MySqlCommand myCommand     = new MySqlCommand(mySelectQuery, dbConn);

            if (isDBConnected)
            {
                MySqlDataReader myReader;
                myReader = myCommand.ExecuteReader();
                try
                {
                    while (myReader.Read())
                    {
                        int    id     = myReader.GetInt32("id");
                        string value  = myReader.GetString("carat");
                        Carat  _carat = new Carat(id, value);
                        result.Add(_carat);
                    }
                }
                finally
                {
                    myReader.Close();
                }
            }
            return(result);
        }
        private void LoadViewInventoryByCat(string cat_id)
        {
            if (dgvInventory.Rows.Count > 0)
            {
                dgvInventory.Rows.Clear();
            }

            itemList = manager.GetAllInventoriesByCat(cat_id);

            for (int i = 0; i < itemList.Count; i++)
            {
                DataGridViewRow row = new DataGridViewRow();
                row.CreateCells(dgvInventory);

                row.Cells[0].Value = itemList[i].inventory_id;
                row.Cells[1].Value = itemList[i].inventory_sub.parent.category_name;
                row.Cells[2].Value = itemList[i].inventory_sub.subcategory_name;
                row.Cells[3].Value = itemList[i].inventory_name;
                Carat carat = manager.GetCaratByID(itemList[i].inventory_carats);
                row.Cells[4].Value = carat.value;
                row.Cells[5].Value = itemList[i].inventory_weight.ToString("0.000");

                //listCat.Add(categories[i].category_id, categories[i].category_name);
                dgvInventory.Rows.Add(row);
            }
        }
示例#4
0
        public bool DeleteCarat(Carat cat)
        {
            bool result = false;

            string       myDeleteQuery = "DELETE FROM master_carat WHERE id='" + cat.id + "';";
            MySqlCommand myCommand     = new MySqlCommand(myDeleteQuery, dbConn);

            try
            {
                int rows = myCommand.ExecuteNonQuery();
                if (rows > 0)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error delete master_carat! " + ex.Message);
            }

            return(result);
        }
示例#5
0
        public bool UpdateCarat(Carat cat)
        {
            bool result = false;

            string myUpdateQuery = "UPDATE master_carat SET carat='" + cat.value + "' WHERE id=" +
                                   cat.id + ";";
            MySqlCommand myCommand = new MySqlCommand(myUpdateQuery, dbConn);

            try
            {
                int rows = myCommand.ExecuteNonQuery();
                if (rows > 0)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error update master_carat! " + ex.Message);
            }

            return(result);
        }
示例#6
0
        public bool AddNewCarat(Carat carat)
        {
            bool result = false;

            string myInsertQuery = "INSERT INTO master_carat (id, carat) VALUES (" +
                                   carat.id + ",'" + carat.value + "');";
            MySqlCommand myCommand = new MySqlCommand(myInsertQuery, dbConn);

            try
            {
                int rows = myCommand.ExecuteNonQuery();
                if (rows > 0)
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error insert into master_carat! " + ex.Message);
            }

            return(result);
        }
        private void BtnCarSave_Click(object sender, EventArgs e)
        {
            if (txbCarID.TextLength > 0 & txbCarName.TextLength > 0)
            {
                Carat new_cat = new Carat(int.Parse(txbCarID.Text), txbCarName.Text);
                try
                {
                    if (data_mode == 1)
                    {
                        if (manager.AddNewCarat(new_cat))
                        {
                            MessageBox.Show("Add new carat succeed!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else if (data_mode == 2)
                    {
                        if (manager.UpdateCarat(new_cat))
                        {
                            MessageBox.Show("Update carat succeed!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                LoadViewCarats();
                ClearGBCarat();
            }
            else
            {
                MessageBox.Show("Carat ID and Value can't be empty!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txbCarID.Focus();
            }
        }