Exemplo n.º 1
0
        private void btnChonDV_Click(object sender, EventArgs e)
        {
            int LayMADV;

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            if (string.IsNullOrEmpty(this.txtSoluong.Text))
            {
                MessageBox.Show("Vui lòng nhập số lượng", "Thông báo");
                txtSoluong.Focus();
            }
            else
            {
                string     QueryMaDV = "select madv from dichvu where madv='" + cboTenDV.SelectedValue.ToString() + "'";
                SqlCommand cmdMaDV   = new SqlCommand(QueryMaDV, conn);
                LayMADV = (int)cmdMaDV.ExecuteScalar();
                double sl;
                if (dgvDatDV.Rows.Count == 0)
                {
                    dgvDatDV.Rows.Add(LayMADV.ToString(), this.cboTenDV.Text, this.txtDongia.Text, this.txtSoluong.Text, this.txtThanhTien.Text);
                }

                else
                {
                    for (int i = 0; i < dgvDatDV.Rows.Count; i++)
                    {
                        if (Double.Parse(dgvDatDV.Rows[i].Cells[0].Value.ToString()) == LayMADV)
                        {
                            sl = Double.Parse(dgvDatDV.Rows[i].Cells[3].Value.ToString()) + (Double.Parse(txtSoluong.Text));
                            dgvDatDV.Rows[i].Cells[3].Value = sl;
                            dgvDatDV.Rows[i].Cells[4].Value = sl * (Double.Parse((txtDongia.Text)));
                            break;
                        }
                        dgvDatDV.Rows.Add(LayMADV.ToString(), this.cboTenDV.Text, this.txtDongia.Text, this.txtSoluong.Text, this.txtThanhTien.Text);
                    }
                }

                tongtienthanhtoan();
                txtSoluong.Clear();
            }
            conn.Close();
        }
        private void btnChonDV_Click(object sender, EventArgs e)
        {
            int LayMADV;

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            if (string.IsNullOrEmpty(this.txtSoluong.Text))
            {
                MessageBox.Show("Vui lòng nhập số lượng", "Thông báo");
                txtSoluong.Focus();
            }
            else
            {
                string     QueryMaDV = "select madv from dichvu where madv='" + cboTenDV.SelectedValue.ToString() + "'";
                SqlCommand cmdMaDV   = new SqlCommand(QueryMaDV, conn);
                LayMADV = (int)cmdMaDV.ExecuteScalar();
                double sl;
                if (dgvDatDV.Rows.Count == 0)
                {
                    dgvDatDV.Rows.Add(LayMADV.ToString(), this.cboTenDV.Text, this.txtDongia.Text, this.txtSoluong.Text, this.txtThanhTien.Text);
                }

                else
                {
                    for (int i = 0; i < dgvDatDV.Rows.Count; i++)
                    {
                        if (Double.Parse(dgvDatDV.Rows[i].Cells[0].Value.ToString()) == LayMADV)
                        {
                            sl = Double.Parse(dgvDatDV.Rows[i].Cells[3].Value.ToString()) + (Double.Parse(txtSoluong.Text));
                            dgvDatDV.Rows[i].Cells[3].Value = sl;
                            dgvDatDV.Rows[i].Cells[4].Value = sl * (Double.Parse((txtDongia.Text)));
                            break;
                        }
                        dgvDatDV.Rows.Add(LayMADV.ToString(), this.cboTenDV.Text, this.txtDongia.Text, this.txtSoluong.Text, this.txtThanhTien.Text);
                    }
                }

//if (dgvCTSAN.Rows.Count > 0)
//                {
//                    int rowmasan = dgvSanCL.SelectedCells[0].RowIndex;
//                    DataGridViewRow rowms = dgvSanCL.Rows[rowmasan];
//                    string sa = rowms.Cells[0].Value.ToString();

//                    for (int n = 0; n < dgvCTSAN.Rows.Count; n++)
//                    {
//                        string masann = "" + dgvCTSAN.Rows[n].Cells[0].Value;
//                        string ngayy = "" + dgvCTSAN.Rows[n].Cells[3].Value;

//                        if (sa == masann && dgvCTSAN.Rows[n].Cells[2].Value == dgvTrangThai.Rows[i].Cells[0].Value && ngayy == dateNgaySDSan.Value.ToShortDateString())
//                        {
//                            dgvTrangThai.Rows[i].DefaultCellStyle.BackColor = Color.Aqua;
//                        }
//                    }
//                }



                tongtienthanhtoan();
                txtSoluong.Clear();
            }
            conn.Close();
        }