private void buttonAdd_Click(object sender, EventArgs e) { if (CheckForms()) { //Lấy Thông tin được chọn từ Forms Employee = (Model_Employee)comboBoxEmployee.SelectedItem; Model_Product Product = (Model_Product)comboBoxProduct.SelectedItem; Supplier = (Model_Supplier)comboBoxSupplier.SelectedItem; string NameOfProduct = GetProductName(Product.Name); DateTime day = DateEntryPicker.Value; // Kiem tra san pham da co trong danh sách chưa if (CheckStock(Product.ID) == false) { MessageBox.Show("Đã có sản phẩm trong danh sách", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { stockEntry.Add(Product.ID); //Tổng tiền = (Số Lượng * đơn Giá ) * (1 - Giảm Giá) tongtien += (numericUpDownQuantity.Value * decimal.Parse(textBoxUnitPrice.Text)) * (1 - decimal.Parse(textBoxDiscount.Text) / 100); labelTotal.Text = "Tổng tiền : " + tongtien.ToString("N0", System.Globalization.CultureInfo.GetCultureInfo("de")) + " VND"; //Thêm thông tin vào datagridview int n = dataGridView1.Rows.Add(); dataGridView1.Rows[n].Cells[0].Value = Product.ID; dataGridView1.Rows[n].Cells[1].Value = NameOfProduct; dataGridView1.Rows[n].Cells[2].Value = numericUpDownQuantity.Value.ToString(); dataGridView1.Rows[n].Cells[3].Value = textBoxUnitPrice.Text; dataGridView1.Rows[n].Cells[4].Value = textBoxDiscount.Text; } //Clear data ClearText(); } }
private void buttonDelete_Click(object sender, EventArgs e) { if (temp != null) { if (MessageBox.Show("Bạn có chắc chắn muốn xóa Nhà Cung Cấp này ? ", "Thông Báo", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } else { try { GlobalConfig.Connection.DeleteSupplier(temp); temp = null; MessageBox.Show("Xóa Thành Công", "Thông Báo", MessageBoxButtons.OK); temp = null; ClearData(); WireData(); } catch { MessageBox.Show("Có lỗi Xóa không thành công ", "Thông Báo", MessageBoxButtons.OK); } } } else { MessageBox.Show("Hãy chọn 1 hàng trên danh sách ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void DeleteSupplier(Model_Supplier model) { DynamicParameters p = new DynamicParameters(); p.Add("@SupplierID", model.ID); using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnectionString("Clothes"))) { connection.Execute("Delete_Supplier", p, commandType: CommandType.StoredProcedure); } }
public void UpdateSupplier(Model_Supplier model) { DynamicParameters p = new DynamicParameters(); p.Add("@SupplierID", model.ID); p.Add("@Name", model.Name); p.Add("@PhoneNumber", model.PhoneNumber); p.Add("@Address", model.Address); using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnectionString("Clothes"))) { connection.Execute("UpdateSupplier", p, commandType: CommandType.StoredProcedure); } }
//Tạo Nhà Cung Cấp mới public Model_Supplier InsertNewSupplier(Model_Supplier model) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.ConnectionString("Clothes"))) { var p = new DynamicParameters(); p.Add("@Name", model.Name); p.Add("@Address", model.Address); p.Add("@PhoneNumber", model.PhoneNumber); p.Add("@ID", "", DbType.String, direction: ParameterDirection.Output); connection.Execute("dbo.InsertNewSupplier", p, commandType: CommandType.StoredProcedure); p.Get <string>("@ID"); return(model); } }
private void comboBoxNCC_SelectedIndexChanged(object sender, EventArgs e) { if (comboBoxNCC.Text != "") { Model_Supplier s = (Model_Supplier)comboBoxNCC.SelectedItem; try { DataTable table = GlobalConfig.Connection.ReportSupplier(s.ID); DanhsachNCC.DataSource = null; DanhsachNCC.DataSource = table; } catch { } } }
private void buttonOK_Click(object sender, EventArgs e) { if (ValidateForm()) { Model_Supplier model = new Model_Supplier(textBoxName.Text, textBoxAddress.Text, textBoxPhoneNumber.Text); //Chạy lệnh SQL try { GlobalConfig.Connection.InsertNewSupplier(model); } catch { } MessageBox.Show("Nhập Thành Công", "Thông Báo", MessageBoxButtons.OK); this.Dispose(); } }
private void buttonSave_Click(object sender, EventArgs e) { Model_Supplier model = new Model_Supplier(textBoxName.Text, textBoxAddress.Text, textBoxPhoneNumber.Text); model.ID = textBoxID.Text; try { GlobalConfig.Connection.UpdateSupplier(model); MessageBox.Show($"Sửa thông tin Nhà Cung Cấp mã {model.ID} thành công", "Thông Báo", MessageBoxButtons.OK); ResetButton(); WireData(); buttonSave.Visible = false; } catch { MessageBox.Show("Có lỗi Sửa không thành công ", "Thông Báo", MessageBoxButtons.OK); } }
private void DanhsachNCC_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { if (textBoxName.ReadOnly == false) { ResetButton(); } temp = new Model_Supplier(); DataGridViewRow selectRow = this.DanhsachNCC.Rows[e.RowIndex]; temp.ID = selectRow.Cells["Mã Nhà Cung Cấp"].Value.ToString(); temp.Name = selectRow.Cells["Tên Nhà Cung Cấp"].Value.ToString(); temp.PhoneNumber = selectRow.Cells["Số Điện Thoại"].Value.ToString(); temp.Address = selectRow.Cells["Địa Chỉ"].Value.ToString(); textBoxID.Text = temp.ID; textBoxName.Text = temp.Name; textBoxPhoneNumber.Text = temp.PhoneNumber; textBoxAddress.Text = temp.Address; } }