private void createBtn_Click(object sender, EventArgs e)
 {
     Software.Model.Unit_Type type = new Software.Model.Unit_Type
     {
         Name   = nameBox.Text,
         Symbol = symbolBox.Text
     };
     Software.Database.SQL.Unit_TypeDB.InsertUnit_Type(type);
     MetroFramework.MetroMessageBox.Show(this, "Sucess", "Data Inserted Successfully", MessageBoxButtons.OK, MessageBoxIcon.Information);
     Close();
 }
        private void table_SelectionChanged(object sender, EventArgs e)
        {
            if (table.SelectedCells.Count > 0)
            {
                int             selectedRowIndex = table.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow      = table.Rows[selectedRowIndex];
                nameBox.Text        = Convert.ToString(selectedRow.Cells["Name"].Value);
                descriptionBox.Text = Convert.ToString(selectedRow.Cells["Description"].Value);
                costBox.Text        = Convert.ToString(selectedRow.Cells["Unit_Cost"].Value);
                amountBox.Text      = Convert.ToString(selectedRow.Cells["Amount"].Value);

                Software.Model.Unit_Type type = types.Single(t => t.Id == Convert.ToInt32(Convert.ToString(selectedRow.Cells["Unit_Id"].Value)));
                comboBox.SelectedIndex = comboBox.FindStringExact(type.Name);
            }
        }
Ejemplo n.º 3
0
        private void updateBtn_Click(object sender, EventArgs e)
        {
            int selectedRowIndex = 0;

            if (table.SelectedCells.Count > 0)
            {
                Software.Model.Unit_Type type = new Software.Model.Unit_Type();

                selectedRowIndex = table.SelectedCells[0].RowIndex;
                DataGridViewRow selectedRow = table.Rows[selectedRowIndex];

                type.Id     = Convert.ToInt32(Convert.ToString(selectedRow.Cells["Id"].Value));
                type.Name   = nameBox.Text;
                type.Symbol = symbolBox.Text;
                Software.Database.SQL.Unit_TypeDB.UpdateUnit_Type(type);
            }
            else
            {
                MessageBox.Show("You must select a row to update its value!", "Invalid Selection");
            }

            DoRefresh();
            table.Rows[selectedRowIndex].Selected = true;
        }