Exemplo n.º 1
0
        private void ThemDoan1()
        {
            int madoan = int.Parse(tbMaDoan.Text);
            // Thêm đoàn
            Doan d = new Doan();

            //   d.MaDoan = madoan;
            d.MaTour  = int.Parse(cbbMaTour.Text);
            d.TenDoan = tbTenDoan.Text;
            d.GioDi   = dtGioDi.Text;
            d.GioVe   = dtGioVe.Text;
            try
            {
                if (doan.insertDoan(d))
                {
                    MessageBox.Show("thêm đoàn thành công");
                }
                else
                {
                    MessageBox.Show("thêm đoàn thất bại");
                }
            }
            catch (Exception) { }

            // Thêm chi phí
            int flag = 0;

            for (int row = 0; row < dgvChiPhi.RowCount - 1; row++)
            {
                ChiPhi cp = new ChiPhi();
                cp.MaDoan = int.Parse(tbMaDoan.Text);
                cp.tenCP  = dgvChiPhi.Rows[row].Cells[0].Value.ToString();
                cp.sotien = float.Parse(dgvChiPhi.Rows[row].Cells[1].Value.ToString());
                cp.ghiChu = dgvChiPhi.Rows[row].Cells[2].Value.ToString();
                try
                {
                    if (doan.insertChiPhi(cp))
                    {
                        flag = 0;
                    }
                    else
                    {
                        flag = 1;
                        MessageBox.Show("Thêm chi phí đoàn thất bại");
                        break;
                    }
                }
                catch (Exception) { }
            }
            if (flag == 0)
            {
                MessageBox.Show("thêm chi phí đoàn thành công");
            }
            // Thêm nhân viên theo đoàn
            int flag2 = 0;

            for (int vt = 0; vt < dgvNV.RowCount - 1; vt++)
            {
                int nhiemVu = int.Parse(dgvNV.Rows[vt].Cells[3].Value.ToString());
                int manv    = int.Parse(dgvNV.Rows[vt].Cells[0].Value.ToString());
                try
                {
                    if (doan.insertNVTheoDoan(manv, madoan, nhiemVu))
                    {
                        flag2 = 0;
                    }
                    else
                    {
                        flag2 = 1;
                        MessageBox.Show("thêm nhân viên thất bại");
                        break;
                    }
                }
                catch (Exception) { }
            }
            if (flag == 0)
            {
                MessageBox.Show("Thêm nhân viên của đoàn thành công");
            }

            //Thêm chi tiết đoàn
            int flag3 = 0;

            for (int i = 0; i < dgvKH.RowCount - 1; i++)
            {
                int makh = int.Parse(dgvKH.Rows[i].Cells[0].Value.ToString());
                try
                {
                    if (doan.insertCTDoan(makh, madoan))
                    {
                        flag3 = 0;
                    }
                    else
                    {
                        flag3 = 1;
                        MessageBox.Show("Thêm chi tiết đoàn thất bại");
                        break;
                    }
                }
                catch (Exception) { }
            }
            if (flag3 == 0)
            {
                MessageBox.Show("Thêm chi tiết đoàn thành công");
            }
        }