private void buttonOK_Click(object sender, EventArgs e) { if (textBoxID_Kho.Text != "" && textBoxTen.Text != "" && comboBoxTrangThai.SelectedIndex != -1 && comboBoxKhuVuc.SelectedIndex != -1 && textBoxDienTich.Text != "") { Kho s = new Kho { ID_Kho = Convert.ToInt32(textBoxID_Kho.Text), Ten = textBoxTen.Text, Dientich = Convert.ToDouble(textBoxDienTich.Text), Trangthai = comboBoxTrangThai.SelectedItem.ToString(), ID_KhuVuc = ((CBBItem)comboBoxKhuVuc.SelectedItem).Value }; if (this.ID_Kho == -1) { if (CSDL_OOP.Instance.AddKho(s)) { MessageBox.Show("Add Success!"); this.Close(); } else { MessageBox.Show("Add Fail!"); } } else { CSDL_OOP.Instance.UpdateKho(s); MessageBox.Show("Update Success!"); this.Close(); } this.d(0, ""); } }
public void AddDataRow(Kho s) { DataRow dr = DSKho.NewRow(); dr["ID_Kho"] = s.ID_Kho; dr["Ten"] = s.Ten; dr["Dientich"] = s.Dientich; dr["Trangthai"] = s.Trangthai; dr["ID_KhuVuc"] = s.ID_KhuVuc; DSKho.Rows.Add(dr); }
private void buttonDelete_Click(object sender, EventArgs e) { DataGridViewSelectedRowCollection data = dataGridViewQLK.SelectedRows; if (data.Count == 1) { int ID_Kho = Convert.ToInt32(data[0].Cells["ID_Kho"].Value.ToString()); Kho s = CSDL_OOP.Instance.GetKhoByID_Kho(ID_Kho); CSDL_OOP.Instance.DeleteKho(s); } Show(0, textBoxSearch.Text); }
public void UpdateKho(Kho k) { foreach (DataRow r in CSDL.Instance.DSKho.Rows) { if ((int)r["ID_Kho"] == k.ID_Kho) { r["Ten"] = k.Ten; r["dienTich"] = k.Dientich; r["TrangThai"] = k.Trangthai; r["ID_KhuVuc"] = k.ID_KhuVuc; } } }
public Kho GetKhoByID_Kho(int ID_Kho) { Kho s = new Kho(); foreach (Kho i in GetAllKho()) { if (i.ID_Kho == ID_Kho) { s = i; } } return(s); }
public bool AddKho(Kho k) { bool b = false; if (this.FindKho(k.ID_Kho) == null) { DataRow dr = CSDL.Instance.DSKho.NewRow(); dr["ID_Kho"] = k.ID_Kho; dr["Ten"] = k.Ten; dr["DienTich"] = k.Dientich; dr["TrangThai"] = k.Trangthai; dr["ID_KhuVuc"] = k.ID_KhuVuc; CSDL.Instance.DSKho.Rows.Add(dr); b = true; } return(b); }
public void RemoveDataRow(Kho s) { try { foreach (DataRow i in DSKho.Rows) { //if (i["ID_Kho"].ToString() == s.ID_Kho) if(Convert.ToInt32(i["ID_Kho"].ToString()) == s.ID_Kho) { DSKho.Rows.Remove(i); } } DSKho.AcceptChanges(); } catch (Exception) { } }
public List <Kho> SortKho(int idkho, string ten, MyCompare cmp) { List <Kho> data = GetListKho(idkho, ten); for (int i = 0; i < data.Count - 1; ++i) { for (int j = i + 1; j < data.Count; ++j) { if (cmp(data[i], data[j])) { Kho temp = data[i]; data[i] = data[j]; data[j] = temp; } } } return(data); }
private void buttonEdit_Click(object sender, EventArgs e) { //DataGridViewSelectedRowCollection data = dataGridViewQLK.SelectedRows; //if (data.Count == 1) //{ // int ID_Kho = Convert.ToInt32(data[0].Cells["ID_Kho"].Value.ToString()); // Form2 EDIT = new Form2(ID_Kho); // EDIT.ShowDialog(); // Show(0, textBoxSearch.Text); if (dataGridViewQLK.SelectedRows.Count == 1) { int k = (int)dataGridViewQLK.SelectedRows[0].Cells["ID_Kho"].Value; Kho kho = CSDL_OOP.Instance.FindKho(k); Form2 f2 = new Form2(kho.ID_Kho); f2.d = new Form2.mydelegate(Show); f2.Show(); } }
public void ExecuteDB(Kho s) { bool check = false; foreach (Kho i in GetAllKho()) { if (s.ID_Kho == i.ID_Kho) { check = true; } } if (check) { CSDL.Instance.EditDataRow(s); } else { CSDL.Instance.AddDataRow(s); } }
public void EditDataRow(Kho s) { try { foreach (DataRow i in DSKho.Rows) { if (Convert.ToInt32(i["ID_Kho"].ToString()) == s.ID_Kho) { i["Ten"] = s.Ten; i["Dientich"] = s.Dientich; i["Trangthai"] = s.Trangthai; i["ID_KhuVuc"] = s.ID_KhuVuc; } } } catch (Exception) { } }
public void ADDANDEDIT() { Kho s = CSDL_OOP.Instance.FindKho(this.ID_Kho); if (s != null) { this.textBoxID_Kho.Text = s.ID_Kho.ToString(); this.textBoxTen.Text = s.Ten; foreach (KhuVuc K in CSDL_OOP.Instance.GetAllKhuVuc()) { comboBoxKhuVuc.Items.Add(new CBBItem { Value = K.ID_KV, Text = K.Diachi }); if (s.ID_KhuVuc == K.ID_KV) { comboBoxKhuVuc.SelectedItem = comboBoxKhuVuc.Items[comboBoxKhuVuc.Items.Count - 1]; } } this.textBoxDienTich.Text = s.Dientich.ToString(); this.comboBoxTrangThai.Items.Add("Full"); this.comboBoxTrangThai.Items.Add("Not Full"); this.comboBoxTrangThai.Items.Add("KHD"); this.comboBoxTrangThai.Text = s.Trangthai; this.textBoxID_Kho.Enabled = false; } else { foreach (KhuVuc K in CSDL_OOP.Instance.GetAllKhuVuc()) { comboBoxKhuVuc.Items.Add(new CBBItem { Value = K.ID_KV, Text = K.Diachi }); } this.comboBoxTrangThai.Items.Add("Full"); this.comboBoxTrangThai.Items.Add("Not Full"); this.comboBoxTrangThai.Items.Add("KHD"); } }
public void DeleteKho(Kho ID_Kho) { CSDL.Instance.RemoveDataRow(ID_Kho); }