private void btnIn_Click(object sender, EventArgs e)
 {
     if (dataGridView1DSCHITIET_HDM.RowCount != 0 && txtmahdM.TextLength != 0)
     {
         frmXuatHoaDonNHap fr = new frmXuatHoaDonNHap();
         fr.Ma_HD = txtmahdM.Text.ToString();
         fr.ShowDialog();
     }
 }
Beispiel #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;
                }

                string query = "SET DATEFORMAT DMY INSERT INTO HOADON_MUA VALUES ('" + txbMaHD.Text.ToString() + "','" + cbbTenNCC.SelectedValue.ToString() + "','" + dateTimePicker1.Value.ToShortDateString() + "'," + double.Parse(txtTongHD.Text.ToString()) + ",'" + txbMaNVHDMH.Text.ToString() + "') ";
                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_HDM values ('" + txbMaHD.Text.ToString().Trim() + "','" + dataGridView1.Rows[i].Cells[0].Value.ToString() + "'," + dataGridView1.Rows[i].Cells[2].Value.ToString() + "," + dataGridView1.Rows[i].Cells[4].Value.ToString() + "," + dataGridView1.Rows[i].Cells[6].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)
                {
                    frmXuatHoaDonNHap fr = new frmXuatHoaDonNHap();
                    fr.Ma_HD = txbMaHD.Text.ToString().Trim();
                    fr.ShowDialog();
                }
                dataGridView1.Rows.Clear();
                txtTongHD.Text = "0";
                txbMaHD.Text   = TaoMaHDTuDong();
            }
            catch { }
        }