예제 #1
0
 private void btnIn_Click(object sender, EventArgs e)
 {
     if (dataGridView2ChiTietBan.RowCount != 0 && txtMaHDB.TextLength != 0)
     {
         frmXuatHoaDonBan fr = new frmXuatHoaDonBan();
         fr.Ma_HD = txtMaHDB.Text;
         fr.ShowDialog();
     }
 }
예제 #2
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            //try
            //{
            if (dataGridView1.RowCount == 0)
            {
                MessageBox.Show("Hoá đơn chưa có thiết bị");
                return;
            }
            DateTime t = new DateTime();

            t = DateTime.Parse(dateTimePicker1.Value.ToShortDateString());
            if (t.Year <= 2010)
            {
                MessageBox.Show("Hóa đơn bán phải có năm lớn hơn năm 2010");
                return;
            }
            string query = "SET DATEFORMAT DMY INSERT INTO HOADON_BAN VALUES ('" + txtMaHoaDon.Text.ToString().Trim() + "',N'" + txtTenKH.Text + "','" + txtSoDienThoai.Text + "','" + dateTimePicker1.Value.ToShortDateString() + "'," + double.Parse(txtTongtien.Text.ToString()) + ",'" + txtMaNhanVien.Text.ToString().Trim() + "') ";

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            cmd = new SqlCommand(query, conn);
            cmd.ExecuteNonQuery();
            int rowcount = dataGridView1.RowCount;

            for (int i = 0; i < rowcount; i++)
            {
                query = "insert into CHITIET_HDB values ('" + txtMaHoaDon.Text.ToString().Trim() + "','" + dataGridView1.Rows[i].Cells[0].Value.ToString() + "'," + int.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString()) + "," + double.Parse(dataGridView1.Rows[i].Cells[3].Value.ToString()) + "," + double.Parse(dataGridView1.Rows[i].Cells[4].Value.ToString()) + ")";
                cmd   = new SqlCommand(query, conn);
                cmd.ExecuteNonQuery();
                query = "UPDATE THIETBI SET  SOLUONG -= " + int.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString()) + " where MA_TB = '" + dataGridView1.Rows[i].Cells[0].Value.ToString() + "'";
                cmd   = new SqlCommand(query, conn);
                cmd.ExecuteNonQuery();
            }


            conn.Close();
            DialogResult ok;

            ok = MessageBox.Show("Thành công. Bạn có muốn in không ?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (ok == DialogResult.Yes)
            {
                frmXuatHoaDonBan fr = new frmXuatHoaDonBan();

                fr.Ma_HD = txtMaHoaDon.Text.ToString();
                fr.ShowDialog();
            }
            dataGridView1.Rows.Clear();
            txtTongtien.Text = "0";
            txtMaHoaDon.Text = TaoMaHDTuDong();
            //}
            //catch { }
        }