private void btn_SaveEdit_Click(object sender, EventArgs e) { if (this.cbb_HotKey_Edit.SelectedIndex != 0) { foreach (DataRow dr in MatHangManager.s_DanhSachMatHang.Rows) { //string a = dr["HotKey"].ToString(); if (int.Parse(dr["HotKey"].ToString()) == this.cbb_HotKey_Edit.SelectedIndex) { string value = dr["Price"].ToString(); int ivalue; bool isValidValue = int.TryParse(value, NumberStyles.Integer | NumberStyles.AllowThousands, CultureInfo.GetCultureInfo("en-US"), out ivalue); SqlHelper.UpdateMatHang(int.Parse(dr["ID"].ToString()), dr["Name"].ToString(), ivalue, 0); } } } SqlHelper.UpdateMatHang(int.Parse(this.dataGridView2.CurrentRow.Cells["ID"].Value.ToString()), this.txb_Name_Edit.Text, (int)this.numeric_Price_Edit.Value, this.cbb_HotKey_Edit.SelectedIndex); MatHangManager.refresh(); this.dataGridView2.DataSource = MatHangManager.s_DanhSachMatHang; this.Edit_container.Visible = false; this.Add_container.Visible = true; }
private void btn_Add_Click(object sender, EventArgs e) { if (!this.txb_Name_Add.Text.Equals("")) { if (this.cbb_HotKey_Add.SelectedIndex != 0) { foreach (DataRow dr in MatHangManager.s_DanhSachMatHang.Rows) { string a = dr["HotKey"].ToString(); if (int.Parse(dr["HotKey"].ToString()) == this.cbb_HotKey_Add.SelectedIndex) { string value = dr["Price"].ToString(); int ivalue; bool isValidValue = int.TryParse(value, NumberStyles.Integer | NumberStyles.AllowThousands, CultureInfo.GetCultureInfo("en-US"), out ivalue); SqlHelper.UpdateMatHang(int.Parse(dr["ID"].ToString()), dr["Name"].ToString(), ivalue, 0); } } } SqlHelper.InsertMatHang(this.txb_Name_Add.Text, (int)this.numeric_Price_Add.Value, this.cbb_HotKey_Add.SelectedIndex); MatHangManager.refresh(); this.dataGridView2.DataSource = MatHangManager.s_DanhSachMatHang; } }
public void TXSMH_closed(object sender, FormClosedEventArgs e) { MatHangManager.refresh(); this.dataGridView2.DataSource = MatHangManager.s_DanhSachMatHang; dataGridView2.ClearSelection(); this.dataGridView2.Rows[0].Selected = true; this.m_selected_ID_MH = int.Parse(dataGridView2.SelectedRows[0].Cells["ID"].Value.ToString()); this.lbl_MatHang.Text = dataGridView2.SelectedRows[0].Cells["Name"].Value.ToString(); }
private void btn_Delete_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Bạn có chắc chắn muốn xóa mặt hàng.\nDữ liệu sau khi xóa sẽ không thể khôi phục được.", "Cảnh báo", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { //do something int ID = int.Parse(this.dataGridView2.CurrentRow.Cells["ID"].Value.ToString()); SqlHelper.DeleteMatHang(ID); MatHangManager.refresh(); this.dataGridView2.DataSource = MatHangManager.s_DanhSachMatHang; MessageBox.Show("Xóa mặt hàng thành công."); } else if (dialogResult == DialogResult.No) { //do something else } }