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(); } }
public AddProduct(Model_Product model = null) { InitializeComponent(); WireDataCate(); WireDataColor(); WireDataManufactured(); WireDataMaterial(); WireDataObject(); WireDataSeason(); WireDataSize(); //Nếu có 1 đối tượng được truyền vào if (model != null) { labelTitle.Text = "Sửa Sản Phẩm"; ID = model.ID; getPicture(model.ID); textBox_TenSP.Text = model.Name; cbxChatLieu.Text = model.Material.Name; cbxDoituong.Text = model.Object.Name; cbxKichco.Text = model.Size.Size; cbxMauSac.Text = model.Color.Name; cbxMua.Text = model.Season.Name; cbxNSX.Text = model.Manufactured.Name; cbxSanPham.Text = model.Category.Name; textBox_GiaBan.Text = model.PriceSell.ToString(); textBox_GiaNhap.Text = model.PriceEntry.ToString(); textBox_soluong.Text = model.Quantity.ToString(); //bật tắt nút :) textBox_GiaBan.Enabled = true; textBox_GiaNhap.Enabled = true; textBox_soluong.Enabled = true; //biến để xác định là thêm hay sửa isAdjust = true; } }
private void buttonDelete_Click(object sender, EventArgs e) { DataGridViewRow d = DanhsachSP.CurrentRow; if (d.Index >= 0) { string ID; if (MessageBox.Show("Bạn Có Chắc muôn xóa sản phẩm này ", "Announcement", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { if (d.Index >= 0) { ID = d.Cells[0].Value.ToString(); Model_Product a = new Model_Product(); a.ID = ID; GlobalConfig.Connection.DeleteProduct(a); WireData(); MessageBox.Show("Xóa Thành Công Sản Phẩm "); } } catch (Exception t) { MessageBox.Show($"xóa Không thành công {t.Message}"); } } } }
//---------------------------------------------------------------------------------------------------------------------------------- #region Các Lệnh Delete Update public void DeleteProduct(Model_Product model) { using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnectionString("Clothes"))) { var p = new DynamicParameters(); p.Add("@ProductID", model.ID); connection.Execute("[dbo].[Delete_Product]", p, commandType: CommandType.StoredProcedure); } }
private void buttonOK_Click(object sender, EventArgs e) { if (ValidateForm()) { Model_Category cate = (Model_Category)cbxSanPham.SelectedItem; Model_Color color = (Model_Color)cbxMauSac.SelectedItem; Model_Object obj = (Model_Object)cbxDoituong.SelectedItem; Model_RawMaterial material = (Model_RawMaterial)cbxChatLieu.SelectedItem; Model_Season season = (Model_Season)cbxMua.SelectedItem; Model_Size size = (Model_Size)cbxKichco.SelectedItem; int quantity = int.Parse(textBox_soluong.Text); string Name = textBox_TenSP.Text; decimal priceEntry = decimal.Parse(textBox_GiaNhap.Text); decimal priceSell = decimal.Parse(textBox_GiaBan.Text); Model_Manufactured manufactured = (Model_Manufactured)cbxNSX.SelectedItem; Model_Product model = new Model_Product(Name, cate, size, material, color, obj, season, manufactured, quantity, priceEntry, priceSell); if (textBoxAddpicture.Text != "") { model.Picture = fileName; } try { if (isAdjust == false) { GlobalConfig.Connection.InsertNewProduct(model); MessageBox.Show("Thêm Sản Phẩm Thành Công !", "Thông Báo", MessageBoxButtons.OK); this.Dispose(); } else { //dòng 319 chưa có ID nên lúc sửa phải gán lại ID , biến ID là biến toàn cục model.ID = ID; //nếu thay đổi ảnh thì vào chỗ if này if (textBoxAddpicture.Text != "") { model.Picture = fileName; } else { //nếu k có thay đổi gì thì lấy link ảnh từ db model.Picture = GlobalConfig.Connection.find_anh(model.ID); } //update thôi GlobalConfig.Connection.UpdateProduct(model); MessageBox.Show("Sửa Sản Phẩm Thành Công !", "Thông Báo", MessageBoxButtons.OK); this.Dispose(); } } catch { MessageBox.Show("Lỗi Thêm Nhân viên vào Database Liên hệ Thảo để fix :)", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } }
internal Model_Product ReadProduct(string Number) { Model_Product m = new Model_Product(); string sql = "Select Guid,Name From T_ProductInfo_Product Where Number='" + Number + "' AND DeleteMark ISNULL"; DataSet ds = new DataSet(); if (new Helper.SQLite.DBHelper().QueryData(sql, out ds)) { foreach (DataRow dr in ds.Tables[0].Rows) { m.Guid = (Guid)dr["Guid"]; m.Number = Number; m.Name = dr["Name"].ToString(); } } return(m); }
public void UpdateProduct(Model_Product model) { using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnectionString("Clothes"))) { var p = new DynamicParameters(); p.Add("@ProductID", model.ID); p.Add("@ProductName", model.Name); p.Add("@CategoryID", model.Category.ID); p.Add("@SizeID", model.Size.ID); p.Add("@RawMaterial_ID", model.Material.ID); p.Add("@ColorID", model.Color.ID); p.Add("@ObjectID", model.Object.ID); p.Add("@SeasonID", model.Season.ID); p.Add("@ManufacturedID", model.Manufactured.ID); p.Add("@Quantity", model.Quantity); p.Add("@Picture", model.Picture); p.Add("@PriceEntry", model.PriceEntry); p.Add("@PriceSell", model.PriceSell); connection.Execute("dbo.UpdateProduct", p, commandType: CommandType.StoredProcedure); } }
//Tạo Sản phẩm mới public Model_Product InsertNewProduct(Model_Product model) { using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnectionString("Clothes"))) { var p = new DynamicParameters(); p.Add("@ProductName", model.Name); p.Add("@CategoryID", model.Category.ID); p.Add("@SizeID", model.Size.ID); p.Add("@RawMaterial_ID", model.Material.ID); p.Add("@ColorID", model.Color.ID); p.Add("@ObjectID", model.Object.ID); p.Add("@SeasonId", model.Season.ID); p.Add("@ManufacturedID", model.Manufactured.ID); p.Add("Quantity", model.Quantity); p.Add("@Picture", model.Picture); p.Add("@PriceEntry", model.PriceEntry); p.Add("@PriceSell", model.PriceSell); p.Add("@ProductID", "", DbType.String, direction: ParameterDirection.Output); connection.Execute("dbo.InsertNewProduct", p, commandType: CommandType.StoredProcedure); model.ID = p.Get <string>("@ProductID"); } return(model); }
private void buttonSua_Click(object sender, EventArgs e) { string ID, Name, Cate, Size, material, color, objectt, season, manu, quantity, pic = "Khong co anh", entryPrice, sellPrice; Model_Product pro = null; DataGridViewRow d = DanhsachSP.CurrentRow; if (d.Index >= 0) { //Lấy thông tin từ datagrid view ID = d.Cells[0].Value.ToString(); Name = d.Cells[1].Value.ToString(); Cate = d.Cells[2].Value.ToString(); Size = d.Cells[3].Value.ToString(); material = d.Cells[4].Value.ToString(); color = d.Cells[5].Value.ToString(); objectt = d.Cells[6].Value.ToString(); season = d.Cells[7].Value.ToString(); manu = d.Cells[8].Value.ToString(); quantity = d.Cells[9].Value.ToString(); entryPrice = d.Cells[10].Value.ToString(); sellPrice = d.Cells[11].Value.ToString(); try { pic = GlobalConfig.Connection.find_anh(ID); } catch { } //cho thông tin vào 1 đối tượng pro = new Model_Product(ID, Name, Cate, Size, material, color, objectt, season, manu, quantity, entryPrice, sellPrice, pic); //truyền đối tượng sang form addproduct để update :) AddProduct a = new AddProduct(pro); a.Text = "Sửa sản Phẩm"; a.ShowDialog(); WireData(); } }
private void dataGridViewhanghoa_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (dataGridView1.Rows.Count == 0) { return; } //het hang if (int.Parse(dataGridViewhanghoa.CurrentRow.Cells[9].Value.ToString()) == 0) { MessageBox.Show("Sản phẩm đã hết", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //sp đã đc chọn if (checkma(dataGridViewhanghoa.CurrentRow.Cells[0].Value.ToString()) == false) { MessageBox.Show("Sản phẩm đã được chọn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { idhang.Add(dataGridViewhanghoa.CurrentRow.Cells[0].Value.ToString()); Model_Product product = new Model_Product(); DataGridViewRow currentRow = new DataGridViewRow(); currentRow = dataGridViewhanghoa.CurrentRow; product.ID = currentRow.Cells[0].Value.ToString(); product.Name = currentRow.Cells[1].Value.ToString(); Model_Color cloColor = new Model_Color(); cloColor.Name = currentRow.Cells[5].Value.ToString(); product.Color = cloColor; Model_Size modelSize = new Model_Size(); modelSize.Size = currentRow.Cells[3].Value.ToString(); product.Size = modelSize; product.PriceSell = decimal.Parse(currentRow.Cells[10].Value.ToString()); DataGridViewRow addRow = (DataGridViewRow)dataGridView1.Rows[0].Clone(); addRow.Cells[0].Value = product.ID; addRow.Cells[1].Value = product.Name; addRow.Cells[2].Value = product.Size.Size; addRow.Cells[3].Value = product.Color.Name; addRow.Cells[4].Value = 1; addRow.Cells[5].Value = product.PriceSell; addRow.Cells[6].Value = 0; addRow.Cells[7].Value = product.PriceSell; dataGridView1.Rows.Add(addRow); int dem = 0; float tongtien = 0; for (var VARIABLE = 0; VARIABLE <= dataGridView1.Rows.Count - 1; VARIABLE++) { if (dataGridView1.Rows[VARIABLE].Cells[4].Value != null) { dem += int.Parse(dataGridView1.Rows[VARIABLE].Cells[4].Value.ToString()); } if (dataGridView1.Rows[VARIABLE].Cells[7].Value != null) { tongtien += float.Parse(dataGridView1.Rows[VARIABLE].Cells[7].Value.ToString()); } } labeltongsoluong.Text = " " + (dem); labeltongtien.Text = " " + tongtien; labelkhachtra.Text = float.Parse(labeltongtien.Text) - float.Parse(labelgiamgia.Text) + ""; } }