private void btnXoa_Click(object sender, EventArgs e) { DialogResult msg = MessageBox.Show("Có phải bạn muốn xóa " + txtTen.Text + " không?", "Xóa", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); try { if (msg == DialogResult.OK) { //xóa loaiDoANBS bs = new loaiDoANBS(); bs.ldoan_xoaBS(txtMa.Text); MessageBox.Show("Xóa thành công"); } else { } } catch { MessageBox.Show("Đã có lỗi xảy ra trong quá trình xóa"); } load_loaidoan(); txtMa.Text = ""; txtTen.Text = ""; txtMa.Enabled = false; txtTen.Enabled = false; listView1.Enabled = true; btnThem.Enabled = true; btnXoa.Enabled = false; btnSua.Enabled = false; btnLuu.Enabled = false; btnBoqua.Enabled = false; }
private void them() { trung_dl(); try { if (of == true) { MessageBox.Show("Dữ liệu bạn nhập vào bị trùng ở textbox Mã tầng xin vui lòng kiểm ta lại"); txtMa.Text = ""; txtMa.Focus(); } else { loaiDoANBS them = new loaiDoANBS(); them.ldoan_themBS(txtMa.Text, txtTen.Text); MessageBox.Show("Thêm thành công!"); } of = false; them_sua = false; } catch { MessageBox.Show("Đã có lỗi xảy ra trong quá trình thêm"); } }
private void load_loaidoan() { cmdLoaiDoAn.Items.Clear(); loaiDoANBS bs = new loaiDoANBS(); List <loaiDoAnDB> ds = bs.loadloaiDoAn(); for (int i = 0; i < ds.Count; i++) { cmdLoaiDoAn.Items.Add(ds[i].tenloai.ToString()); } }
private void sua() { try { loaiDoANBS bs = new loaiDoANBS(); bs.ldoan_suaBS(txtMa.Text, txtTen.Text); MessageBox.Show("Sửa thành công!"); of = false; them_sua = false; } catch { MessageBox.Show("Đã có lỗi xảy ra trong quá trình sửa"); } }
private void trung_dl() { loaiDoANBS bs = new loaiDoANBS(); List <loaiDoAnDB> ds = bs.loadloaiDoAn(); for (int i = 0; i < ds.Count; i++) { if (txtMa.Text == ds[i].maloai.ToString()) { of = true; break; } } }
private string convertTo(string ma) { string text = ""; loaiDoANBS bs = new loaiDoANBS(); List <loaiDoAnDB> ds = bs.loadloaiDoAn(); for (int i = 0; i < ds.Count; i++) { if (ma == ds[i].maloai.ToString()) { text = ds[i].tenloai.ToString(); break; } } return(text); }
private void them() { trung_dl(); try { loaiDoANBS bs = new loaiDoANBS(); List <loaiDoAnDB> ds = bs.loadloaiDoAn(); tenLoaiDoAn = ds[maLoaiDoan].maloai.ToString(); //lu vao csdl string ten = "0"; if (img != "0") { //coppy file hinh string from1 = @"" + img + ""; string to1 = @"img\" + txtMaSP.Text + ".jpg"; System.IO.File.Copy((string)from1, (string)to1); ten = txtMaSP.Text; } else if (of == true) { MessageBox.Show("Dữ liệu bạn nhập vào bị trùng ở textbox Mã sản phẩm xin vui lòng kiểm ta lại"); txtMaSP.Text = ""; txtMaSP.Focus(); } else { menuBS them = new menuBS(); them.menu_themBS(txtMaSP.Text, txtTenSP.Text, Convert.ToDecimal(txtGia.Text), tenLoaiDoAn, ten); MessageBox.Show("Thêm thành công!"); } img = "0"; ten = "0"; } catch { MessageBox.Show("Một lỗi xảy ra khi ứng dụng đang cố gắng add file hình ảnh này"); } }
private void sua() { try { loaiDoANBS bs = new loaiDoANBS(); List <loaiDoAnDB> ds = bs.loadloaiDoAn(); tenLoaiDoAn = ds[maLoaiDoan].maloai.ToString(); string ten = "0"; //sua hinh if (img != "0") { //xoa file hinh anh hien tai System.IO.File.Delete(@"img\" + txtMaSP.Text + ".jpg"); //coppy file hinh string from1 = @"" + img + ""; string to1 = @"img\" + txtMaSP.Text + ".jpg"; System.IO.File.Copy((string)from1, (string)to1); ten = txtMaSP.Text; } menuBS bs1 = new menuBS(); bs1.menu_suaBS(txtMaSP.Text, txtTenSP.Text, Convert.ToDecimal(txtGia.Text), tenLoaiDoAn, ten); img = "0"; ten = "0"; MessageBox.Show("Sửa thành công!"); } catch { MessageBox.Show("Đã có lỗi xảy ra trong quá trình sửa"); } }