private void BtnSave_Click(object sender, EventArgs e) { using (var db = new QLKhoDbContext()) { object[] obj = { new SqlParameter("@makho", (int)cmbStorage.SelectedValue), new SqlParameter("@mahh", int.Parse(txtID.Text)), new SqlParameter("@tenhh", txtName.Text), new SqlParameter("@tinhtrang", rtbState.Text), new SqlParameter("@mancc", (int)cmbSupplier.SelectedValue), new SqlParameter("@ngaysx", dtpProductDate.Value), new SqlParameter("@hansd", dtpExpireDate.Value), new SqlParameter("@soluongton", int.Parse(nudAmount.Text)), new SqlParameter("@ngaynhap", dtpEntryDate.Value), new SqlParameter("@nhasx", txtProducer.Text) }; int res = db.Database.ExecuteSqlCommand("dbo.commodity_modification @makho,@mahh,@tenhh,@tinhtrang," + "@mancc,@ngaysx,@hansd,@soluongton,@ngaynhap,@nhasx", obj); MessageBox.Show($"result = {res}"); if (res > 0) { LoadData(); LockControls(); } } }
private void LoadData() { using (var db = new QLKhoDbContext()) { object[] obj = { new SqlParameter("@makho", (int)cmbStorage.SelectedValue) }; using (var conn = db.Database.Connection) { conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "commodity_view"; cmd.Parameters.AddRange(obj); SqlDataAdapter da = new SqlDataAdapter((SqlCommand)cmd); DataTable dt = new DataTable(); da.Fill(dt); conn.Close(); dgvList.DataSource = dt; } //dgvList.DataSource = db.HangHoas.SqlQuery("commodity_view @makho", obj).ToList(); } }
private void BtnAdd_Click(object sender, EventArgs e) { if (txtCustomerName.Text == string.Empty || txtDayOfBirth.Text == string.Empty || !txtDayOfBirth.Text.IsPhoneNumber()) { MessageBox.Show("Nhap thong tin"); return; } int res = 0; try { string dob = $"{cbxMonthOfBirth.Text}/{txtDayOfBirth.Text}/{cbxYearOfBirth.Text}"; using (QLKhoDbContext db = new QLKhoDbContext()) { object[] obj = { new SqlParameter("@tenkh", txtCustomerName.Text), new SqlParameter("@gioitinh", rbnFemale.Checked ? "Nu" : "Nam"), new SqlParameter("@ngaysinh", DateTime.Parse(dob)), new SqlParameter("@diachi", rtbCustomerAddress.Text), new SqlParameter("@sdt", txtCustomerPN.Text) }; res = db.Database.ExecuteSqlCommand("sp_customer_insert @tenkh, @gioitinh, @ngaysinh, " + "@diachi, @sdt", obj); } MessageBox.Show($"{res} ban ghi da cap nhat"); } catch (Exception ex) { MessageBox.Show($"Error: {ex}"); } }
private void BtnAdd_Click(object sender, EventArgs e) { using (var db = new QLKhoDbContext()) { object[] obj = { new SqlParameter("@makho", (int)cmbStorage.SelectedValue), new SqlParameter("@mancc", (int)cmbSupplier.SelectedValue), new SqlParameter("@ngaynhap", dtpImportingDate.Value), new SqlParameter("@soluong", int.Parse(nudAmount.Text)), new SqlParameter("@danhan", cbxReceived.Checked ? 1:0), new SqlParameter("@ghichu", rtbNote.Text), new SqlParameter("@ten", txtCommodityName.Text), new SqlParameter("@tinhtrang", rtbState.Text), new SqlParameter("@ngaysx", dtpProductingDate.Value), new SqlParameter("@hansd", dtpExpiringDate.Value), new SqlParameter("@nhasx", txtProducer.Text) }; int res = db.Database.ExecuteSqlCommand(@"dbo.commodity_insertion @makho,@mancc, @ngaynhap,@soluong,@danhan,@ghichu,@ten,@tinhtrang,@ngaysx,@hansd,@nhasx", obj); if (res > 0) { MessageBox.Show($"Đã thêm hàng hóa!"); } } }
private void Form6_Load(object sender, EventArgs e) { using (QLKhoDbContext db = new QLKhoDbContext()) { dgvList.DataSource = db.KhachHangs.ToList(); } }
private void BtnDelete_Click(object sender, EventArgs e) { if (txtCustomerID.Text == string.Empty) { MessageBox.Show("Chon thong tin de xoa!"); return; } using (QLKhoDbContext db = new QLKhoDbContext()) { try { int id = int.Parse(txtCustomerID.Text); var customer = db.KhachHangs.Find(id); db.KhachHangs.Remove(customer); db.SaveChanges(); MessageBox.Show("Da xoa!"); Form6_Load(sender, e); LockControll(); BtnRefresh_Click(sender, e); } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } } }
private void BtnSave_Click(object sender, EventArgs e) { if (txtCustomerName.Text == string.Empty || cbxDayOfBirth.Text == string.Empty || !cbxDayOfBirth.Text.IsPhoneNumber()) { MessageBox.Show("Nhap thong tin"); return; } int res = 0; try { string dob = $"{cbxMonthOfBirth.Text}/{cbxDayOfBirth.Text}/{cbxYearOfBirth.Text}"; using (QLKhoDbContext db = new QLKhoDbContext()) { object[] obj = { new SqlParameter("@tenkh", txtCustomerName.Text), new SqlParameter("@gioitinh", rbnFemale.Checked ? "Nu" : "Nam"), new SqlParameter("@ngaysinh", DateTime.Parse(dob)), new SqlParameter("@diachi", rtbCustomerAddress.Text), new SqlParameter("@sdt", txtCustomerPN.Text) }; if (!edit) { res = db.Database.ExecuteSqlCommand("sp_customer_insert " + "@tenkh, @gioitinh, @ngaysinh, @diachi, @sdt", obj); } else { obj = new object[] { new SqlParameter("@makh", txtCustomerID.Text), new SqlParameter("@tenkh", txtCustomerName.Text), new SqlParameter("@gioitinh", rbnFemale.Checked ? "Nu" : "Nam"), new SqlParameter("@ngaysinh", DateTime.Parse(dob)), new SqlParameter("@diachi", rtbCustomerAddress.Text), new SqlParameter("@sdt", txtCustomerPN.Text) }; res = db.Database.ExecuteSqlCommand("sp_customer_update " + "@makh, @tenkh, @gioitinh, @ngaysinh, @diachi, @sdt", obj); } } if (res > 0) { MessageBox.Show($"Da cap nhat"); Form6_Load(sender, e); LockControll(); BtnRefresh_Click(sender, e); } } catch (Exception ex) { MessageBox.Show($"Error: {ex}"); } }
private void Form3_Load(object sender, EventArgs e) { using (var db = new QLKhoDbContext()) { cmbCustomerID.DataSource = (db.KhachHangs.Select(x => x)).ToList(); cmbCustomerID.DisplayMember = "ten"; cmbCustomerID.ValueMember = "makh"; } LoadData(); }
private void Form6_Load(object sender, EventArgs e) { using (QLKhoDbContext db = new QLKhoDbContext()) { dgvList.DataSource = db.KhachHangs.Select(x => x).ToList(); } for (int k = 1980; k <= 2017; k++) { cbxYearOfBirth.Items.Add($"{k}\n"); } }
private void Form2_Load(object sender, EventArgs e) { using (var db = new QLKhoDbContext()) { cmbSupplier.DataSource = (db.NhaCungCaps.Select(x => x)).ToList(); cmbSupplier.ValueMember = "mancc"; cmbSupplier.DisplayMember = "tenncc"; cmbStorage.DataSource = (db.Khoes.Select(x => x)).ToList(); cmbStorage.ValueMember = "makho"; cmbStorage.DisplayMember = "tenkho"; } }
private void Form1_Load(object sender, EventArgs e) { using (QLKhoDbContext db = new QLKhoDbContext()) { cmbStorage.DataSource = (db.Khoes.Select(x => x)).ToList(); cmbStorage.ValueMember = "makho"; cmbStorage.DisplayMember = "tenkho"; cmbSupplier.DataSource = (db.NhaCungCaps.Select(x => x)).ToList(); cmbSupplier.ValueMember = "mancc"; cmbSupplier.DisplayMember = "tenncc"; var madd = db.Khoes.SingleOrDefault(x => x.makho == (int)cmbStorage.SelectedValue).madd; txtPlace.Text = db.DiaDiems.SingleOrDefault(x => x.madd == madd).tendd; } LoadData(); cmbStorage.SelectedValueChanged += CmbStorage_SelectedValueChanged; }
private void LoadData() { using (var db = new QLKhoDbContext()) { using (var conn = db.Database.Connection) { conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "commodity_selection"; SqlDataAdapter da = new SqlDataAdapter((SqlCommand)cmd); DataTable dt = new DataTable(); da.Fill(dt); conn.Close(); dgvList.DataSource = dt; } } }
private void LoadData() { using (var db = new QLKhoDbContext()) { try { var res = db.Database.SqlQuery <CommodityView>("commodity_view @makho", new object[] { new SqlParameter("@makho", cbxStorage.SelectedValue) }); dgvList.DataSource = res; } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } } }
private void BtnSubmit_Click(object sender, EventArgs e) { try { int res = 0; using (var db = new QLKhoDbContext()) { int count = 0; foreach (DataGridViewRow row in dgvList.Rows) { DataGridViewCheckBoxCell cell = row.Cells["Chon"] as DataGridViewCheckBoxCell; if ((bool)cell.EditedFormattedValue == true) { object[] obj = { new SqlParameter("@makh", (int)cmbCustomerID.SelectedValue), new SqlParameter("@mahh", (int)row.Cells["mahh"].Value), new SqlParameter("@soluong", (int)row.Cells["soluong"].Value), new SqlParameter("@ngayxuat", (DateTime)dtpExportDate.Value), new SqlParameter("@ngaynhan", (DateTime)dtpReceiveDate.Value), new SqlParameter("@ghichu", rtbNote.Text), new SqlParameter("@danhan", cbxReceived.Checked ? 1:0), new SqlParameter("@makho", (int)row.Cells["makho"].Value) }; res = db.Database.ExecuteSqlCommand("dbo.commodity_exporting @makh,@mahh," + "@soluong,@ngayxuat,@ngaynhan,@ghichu,@danhan,@makho", obj); count += res; } } MessageBox.Show($"{count} ban ghi da cap nhat"); if (res > 0) { LoadData(); } } } catch (Exception ex) { MessageBox.Show($"{ex}"); } }
private void Form4_Load(object sender, EventArgs e) { using (var db = new QLKhoDbContext()) { using (var conn = db.Database.Connection) { conn.Open(); var cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; // load importing report cmd.CommandText = "select top 7 cast(ngaynhap as date) ngaynhap, count(*) soluong " + "from phieunhap group by cast(ngaynhap as date)"; SqlDataAdapter da = new SqlDataAdapter((SqlCommand)cmd); DataTable dt = new DataTable(); da.Fill(dt); foreach (DataRow row in dt.Rows) { chart1.Series["Import"].Points.AddXY(row.Field <DateTime>("ngaynhap"), new object[] { row.Field <int>("soluong") }); } // load exporting report cmd.CommandText = "select top 10 cast(ngayxuat as date) ngayxuat, count(*) soluong " + "from phieuxuat group by cast(ngayxuat as date)"; da.SelectCommand = (SqlCommand)cmd; dt = new DataTable(); da.Fill(dt); foreach (DataRow row in dt.Rows) { chart1.Series["Export"].Points.AddXY(row.Field <DateTime>("ngayxuat"), new object[] { row.Field <int>("soluong") }); } conn.Close(); } } }
private void BtnSearch_Click(object sender, EventArgs e) { if (txtSearchBox.Text == string.Empty) { return; } using (QLKhoDbContext db = new QLKhoDbContext()) { try { var res = db.Database.SqlQuery <CommodityView>("commodity_view @makho", new object[] { new SqlParameter("@makho", cbxStorage.SelectedValue) }); dgvList.DataSource = res; } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } } }