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();
            }
        }
Beispiel #2
0
 private void buttonOK_Click(object sender, EventArgs e)
 {
     if (ValidateForm())
     {
         char Sex;
         if (rbMale.Checked == true)
         {
             Sex = 'M';
         }
         else
         {
             Sex = 'F';
         }
         Model_Role     role  = (Model_Role)cbxRole.SelectedItem;
         Model_Employee model = new Model_Employee(textBoxFirstName.Text,
                                                   Sex, dateTimePicker1.Value.Date,
                                                   textBoxPhoneNumber.Text,
                                                   textBoxAddress.Text,
                                                   role);
         try
         {
             GlobalConfig.Connection.InsertNewEmployee(model);
         }
         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;
         }
         MessageBox.Show("Thêm nhân viên Thành công", "Thông Báo", MessageBoxButtons.OK);
         this.Dispose();
     }
 }
Beispiel #3
0
 public void UpdateEmployee(Model_Employee model)
 {
     using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnectionString("Clothes")))
     {
         var p = new DynamicParameters();
         p.Add("@EmployeeID", model.ID);
         p.Add("@Name", model.Name);
         p.Add("@Sex", model.Sex);
         p.Add("@DateOfBirth", model.DateOfBirth.Date);
         p.Add("@PhoneNumber", model.PhoneNumber);
         p.Add("@Address", model.Address);
         p.Add("@RoleID", model.Role.ID);
         connection.Execute("dbo.UpdateEmployee", p, commandType: CommandType.StoredProcedure);
     }
 }
Beispiel #4
0
 //Tạo Nhân Viên mới
 public Model_Employee InsertNewEmployee(Model_Employee model)
 {
     using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.ConnectionString("Clothes")))
     {
         var p = new DynamicParameters();
         p.Add("@Name", model.Name);
         p.Add("@Sex", model.Sex);
         p.Add("@DateOfBirth", model.DateOfBirth);
         p.Add("@PhoneNumber", model.PhoneNumber);
         p.Add("@Address", model.Address);
         p.Add("@RoleID", model.Role.ID);
         p.Add("@ID", "", DbType.String, direction: ParameterDirection.Output);
         connection.Execute("dbo.InsertNewEmployee", p, commandType: CommandType.StoredProcedure);
         p.Get <string>("@ID");
         return(model);
     }
 }
Beispiel #5
0
 private void buttonSave_Click(object sender, EventArgs e)
 {
     if (Validation())
     {
         Model_Employee em   = new Model_Employee();
         Model_Role     role = new Model_Role();
         em.ID          = textBoxID.Text;
         em.Name        = textBoxName.Text;
         em.DateOfBirth = dateOfbirth.Value;
         em.Address     = textBoxAddress.Text;
         em.PhoneNumber = textBoxPhoneNumber.Text;
         role           = (Model_Role)comboBoxRole.SelectedItem;
         em.Role        = role;
         if (radioButtonNam.Checked == true)
         {
             em.Sex = 'M';
         }
         else
         {
             em.Sex = 'F';
         }
         try
         {
             GlobalConfig.Connection.UpdateEmployee(em);
             WireData();
         }
         catch (Exception t)
         {
             MessageBox.Show($"Lỗi không update được  {t}");
         }
         finally
         {
             DeActiveBtn();
         }
     }
 }
Beispiel #6
0
        private void buttonthanhtoan_Click(object sender, EventArgs e)
        {
            if (textBoxthanhtoan.Text == "")
            {
                textBoxthanhtoan.Text = "0";
            }
            if (comboBox1.SelectedItem == null)
            {
                MessageBox.Show("Chọn nhân viên", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (textBoxmakh.Text == "")
            {
                MessageBox.Show("Chọn khách hàng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Model_Employee nhanvien = (Model_Employee)comboBox1.SelectedItem;

            if (float.Parse(textBoxthanhtoan.Text) < float.Parse(labelkhachtra.Text))
            {
                MessageBox.Show("Số tiền khách trả chưa đủ", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            try
            {
                model = GlobalConfig.Connection.Insert_SaleInvoice(nhanvien.ID, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), textBoxmakh.Text, decimal.Parse(labelkhachtra.Text));
            }
            catch (Exception r)
            {
                MessageBox.Show($"{r.ToString()} Lỗi câu lệnh sql ~ 1 ~ line 186", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            for (var VARIABLE = 0; VARIABLE <= dataGridView1.Rows.Count - 1; VARIABLE++)
            {
                try
                {
                    if (dataGridView1.Rows[VARIABLE].Cells[4].Value != null || dataGridView1.Rows[VARIABLE].Cells[6].Value != null || dataGridView1.Rows[VARIABLE].Cells[7].Value != null)
                    {
                        GlobalConfig.Connection.insert_hoadonban_chitiet(
                            model.ID,
                            dataGridView1.Rows[VARIABLE].Cells[0].Value.ToString(),
                            float.Parse(dataGridView1.Rows[VARIABLE].Cells[6].Value.ToString()),
                            int.Parse(dataGridView1.Rows[VARIABLE].Cells[4].Value.ToString()),
                            decimal.Parse(dataGridView1.Rows[VARIABLE].Cells[7].Value.ToString())
                            );
                    }
                }
                catch
                {
                    MessageBox.Show(" Lỗi câu lệnh sql ~ 2 ~ line 199", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            model = null;

            labeltienthua.Text = "" + (float.Parse(textBoxthanhtoan.Text) - float.Parse(labelkhachtra.Text));
            reset();
            MessageBox.Show("Lập hóa đơn thành công", "Thông báo", MessageBoxButtons.OK);
            button1.PerformClick();
        }