示例#1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (txtMaPhieuGiaoHang.Text == "")
            {
                MessageBox.Show("Mã giao hàng không được để trống", "Lỗi");
            }
            int mancc = -1;

            try
            {
                mancc = int.Parse(nhacungcap.GetIDNCCTheoTen(cbbTenNhaCC.Text).Rows[0][0].ToString());
            }
            catch
            {
                MessageBox.Show("Nhà cung cấp không tồn tại", "Lỗi");
            }
            if (mancc != -1)
            {
                if (long.TryParse(txtSoDienThoai.Text, out long reult) == false || txtSoDienThoai.Text.Length < 10 || txtSoDienThoai.Text.Length > 12)
                {
                    MessageBox.Show("Số điện thoại phải từ 10 đến 11 chữ số");
                }
                else if (long.TryParse(txtThanhToan.Text, out long re) == false)
                {
                    MessageBox.Show("Số tiền đã thanh toán phải là số nguyên");
                }
                else if (long.TryParse(txtTongTien.Text, out long s) == false)
                {
                    MessageBox.Show("Tổng tiền hóa đơn phải là số nguyên");
                }
                else
                {
                    DataTable dt = new DataTable();
                    if (dataGridView1.Columns.Count > 0)
                    {
                        foreach (DataGridViewColumn col in dataGridView1.Columns)
                        {
                            dt.Columns.Add(col.HeaderText);
                        }
                    }
                    if (dataGridView1.Rows.Count > 0)
                    {
                        foreach (DataGridViewRow row in dataGridView1.Rows)
                        {
                            DataRow dr;
                            dr = dt.NewRow();
                            for (int i = 0; i < row.Cells.Count; i++)
                            {
                                dr[i] = row.Cells[i].Value;
                            }
                            dt.Rows.Add(dr);
                        }
                    }

                    phieuNhap.InsertPhieuNhap(txtMaPhieuGiaoHang.Text, mancc, txtNguoiGiaoHang.Text, txtSoDienThoai.Text, long.Parse(txtTongTien.Text), long.Parse(txtThanhToan.Text), dtpNgayNhap.Value, dt);
                }
            }
            else
            {
                MessageBox.Show("Nhà cung cấp không tồn tại");
            }
        }