示例#1
0
 public Model_SaleInvoice Insert_SaleInvoice(string nhanvien_id, string day, string khach_id, decimal tongtien)
 {
     using (IDbConnection connection = new SqlConnection(GlobalConfig.ConnectionString("Clothes")))
     {
         Model_SaleInvoice model = new Model_SaleInvoice();
         var p = new DynamicParameters();
         p.Add("@id", "", DbType.String, direction: ParameterDirection.Output);
         p.Add("@manv ", nhanvien_id);
         p.Add("@makh", khach_id);
         p.Add("@ngayban", day);
         p.Add("@tongtien", tongtien);
         connection.Execute("Insert_SaleInvoice", p, commandType: CommandType.StoredProcedure);
         model.ID         = p.Get <string>("@id");
         model.EmployeeID = nhanvien_id;
         model.day        = DateTime.Parse(day);
         model.CustomerID = khach_id;
         model.Total      = tongtien;
         return(model);
     }
 }
示例#2
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();
        }