Beispiel #1
0
 //cap nhat
 public static void Update(CTPN_DTO ctpn)
 {
     string sql;
     sql = "Update service_import_detail set MaPN = ('" + ctpn.MaPN + "'),MaDV=('" + ctpn.MaDV
         + "'),Soluong=('" + ctpn.Soluong + "'),Dongia=('" + ctpn.Dongia + "'),Thanhtien=('"
         + ctpn.Thanhtien + "')";
     sql += "Where MaCTPN = " + ctpn.MaCTPN;
     DataAccess.executeNonQuery(sql);
 }
Beispiel #2
0
        //them
        public static void Insert(CTPN_DTO ctpn)
        {
            string sql;
            sql = "Insert into service_import_detail(MaPN, MaDV, Soluong, Dongia, Thanhtien) values (";
            sql += "'" + ctpn.MaPN + "','" + ctpn.MaDV + "','" + ctpn.Soluong + "','" + ctpn.Dongia
                + "','" + ctpn.Thanhtien + "')";
            DataAccess.executeNonQuery(sql);

            //update so luong service
            DataTable dt = DataAccess.executeQuery("service_numbers", "service_stt="+ctpn.MaDV, "service");
            int soluong = int.Parse(dt.Rows[0]["service_numbers"].ToString());
            ServiceDTO service = new ServiceDTO();
            service.Service_stt = ctpn.MaDV;
            service.Service_number = soluong + ctpn.Soluong;
            ServiceData.UpdateSL(service);
        }
Beispiel #3
0
        //xoa
        public static void Delete(CTPN_DTO ctpn)
        {
            string sql;
            sql = "Delete From service_import_detail Where MaCTPN = " + ctpn.MaCTPN;
            DataAccess.executeNonQuery(sql);

            //update so luong service
            DataTable dt = DataAccess.executeQuery("service_numbers", "service_stt=" + ctpn.MaDV, "service");
            int soluong = int.Parse(dt.Rows[0]["service_numbers"].ToString());
            ServiceDTO service = new ServiceDTO();
            service.Service_stt = ctpn.MaDV;
            service.Service_number = soluong - ctpn.Soluong;
            ServiceData.UpdateSL(service);

            //update phieu nhap
            DataTable dt2 = DataAccess.executeQuery("Tongtien", "MaPN=" + ctpn.MaPN, "service_import");
            int tongtien = int.Parse(dt2.Rows[0]["Tongtien"].ToString());
            PN_DTO pn = new PN_DTO();
            pn.TongTien = tongtien - ctpn.Thanhtien;
            pn.MaPN = ctpn.MaPN;
            PN_Data.UpdateTT(pn);
        }
Beispiel #4
0
        public static void Update(CTPN_DTO ctpn, int slmoi, int dgmoi)
        {
            string sql;
            sql = "Update service_import_detail set Soluong=('" + slmoi + "'),Dongia=('" + dgmoi + "'),Thanhtien=('"
                + slmoi*dgmoi + "')";
            sql += "Where MaCTPN = " + ctpn.MaCTPN;
            DataAccess.executeNonQuery(sql);

            //update so luong service
            DataTable dt = DataAccess.executeQuery("service_numbers", "service_stt=" + ctpn.MaDV, "service");
            int soluong = int.Parse(dt.Rows[0]["service_numbers"].ToString());
            ServiceDTO service = new ServiceDTO();
            service.Service_stt = ctpn.MaDV;
            service.Service_number = soluong - ctpn.Soluong + slmoi;
            ServiceData.UpdateSL(service);

            //update phieu nhap
            DataTable dt2 = DataAccess.executeQuery("Tongtien", "MaPN=" + ctpn.MaPN, "service_import");
            int tongtien = int.Parse(dt2.Rows[0]["Tongtien"].ToString());
            PN_DTO pn = new PN_DTO();
            pn.TongTien = tongtien - ctpn.Thanhtien + slmoi * dgmoi;
            pn.MaPN = ctpn.MaPN;
            PN_Data.UpdateTT(pn);
        }
        private void btnNhapDV_Click(object sender, EventArgs e)
        {
            try
            {
                if (KTThongTinNhap() == false)
                {
                    MessageBox.Show("Thông tin chưa đầy đủ ,xin kiểm tra lại !", "Lỗi");
                    return;
                }
                else if (comboBoxDV.SelectedValue == null)
                {
                    MessageBox.Show("Dịch vụ này chưa tồn tại, vui lòng thêm dịch vụ trước !", "Thông báo");
                    return;
                }
                else
                {
                    CTPN_DTO ctpn = new CTPN_DTO();
                    ctpn.MaDV = int.Parse(comboBoxDV.SelectedValue.ToString());
                    ctpn.Soluong = int.Parse(textBoxSL.Text);
                    ctpn.Dongia = int.Parse(textBoxDG.Text);
                    ctpn.Thanhtien = ctpn.Soluong * ctpn.Dongia;

                    DataGridViewRow row = (DataGridViewRow)dtg_list_dv.Rows[0].Clone();
                    dtg_list_dv.Rows.Add(row);
                    dtg_list_dv[1, totalRow].Value = ctpn.MaDV;
                    dtg_list_dv[2, totalRow].Value = ctpn.Soluong;
                    dtg_list_dv[3, totalRow].Value = ctpn.Dongia;
                    dtg_list_dv[4, totalRow].Value = ctpn.Thanhtien;
                    totalRow++;
                    listCTPN.Add(ctpn);
                    load();
                }
            }
            catch
            {
                MessageBox.Show("Thêm thất bại, kiểm tra lại thông tin nhập !", "Lỗi");
            }
        }
        private void btnSua_Click(object sender, EventArgs e)
        {
            try
            {
                if (selectedRow < 0)
                {
                    MessageBox.Show("Chọn 1 dòng trên bảng để thao tác !", "Thông báo");
                }
                else if (KTThongTinNhap() == false)
                {
                    MessageBox.Show("Thông tin chưa đầy đủ ,xin kiểm tra lại !", "Lỗi");
                }
                else if (comboBoxDV.SelectedValue == null)
                {
                    MessageBox.Show("Dịch vụ này chưa tồn tại, vui lòng thêm dịch vụ trước !", "Thông báo");
                }
                else
                {
                    CTPN_DTO ctpn = new CTPN_DTO();
                    ctpn.MaDV = int.Parse(comboBoxDV.SelectedValue.ToString());
                    ctpn.Soluong = int.Parse(textBoxSL.Text);
                    ctpn.Dongia = int.Parse(textBoxDG.Text);
                    ctpn.Thanhtien = ctpn.Soluong * ctpn.Dongia;

                    dtg_list_dv[1, selectedRow].Value = ctpn.MaDV;
                    dtg_list_dv[2, selectedRow].Value = ctpn.Soluong;
                    dtg_list_dv[3, selectedRow].Value = ctpn.Dongia;
                    dtg_list_dv[4, selectedRow].Value = ctpn.Thanhtien;
                    listCTPN[selectedRow] = ctpn;
                    load();
                }

            }
            catch
            {
                MessageBox.Show("Sửa thất bại, kiểm tra lại thông tin nhập !", "Lỗi");
            }
        }
        private void dtg_list_ctpn_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                if (e.ColumnIndex == 5 && e.RowIndex != rows_ctpn)
                {
                    if (!isEditting)
                    {
                        ctpn.MaCTPN = int.Parse(dtg_list_ctpn.Rows[e.RowIndex].Cells["clm7"].Value.ToString());
                        ctpn.Soluong = int.Parse(dtg_list_ctpn.Rows[e.RowIndex].Cells["clm2"].Value.ToString());
                        ctpn.Dongia = int.Parse(dtg_list_ctpn.Rows[e.RowIndex].Cells["clm3"].Value.ToString());
                        ctpn.Thanhtien = int.Parse(dtg_list_ctpn.Rows[e.RowIndex].Cells["clm4"].Value.ToString());
                        ctpn.MaPN = selected_pn;
                        ctpn.MaDV = int.Parse(dtg_list_ctpn.Rows[e.RowIndex].Cells["clm1"].Value.ToString());

                        dtg_list_ctpn.Rows[e.RowIndex].Cells["clm2"].ReadOnly = false;
                        dtg_list_ctpn.CurrentCell = dtg_list_ctpn.Rows[e.RowIndex].Cells["clm2"];
                        dtg_list_ctpn.BeginEdit(true);
                        dtg_list_ctpn.Rows[e.RowIndex].Cells["clm3"].ReadOnly = false;
                        (dtg_list_ctpn.Rows[e.RowIndex].Cells["clm5"] as DataGridViewImageCell).Value = (System.Drawing.Image)Properties.Resources.save;

                        isEditting = true;
                    }
                    else
                    {
                        int slmoi = int.Parse(dtg_list_ctpn.Rows[e.RowIndex].Cells["clm2"].Value.ToString());
                        int dgmoi = int.Parse(dtg_list_ctpn.Rows[e.RowIndex].Cells["clm3"].Value.ToString());
                        CTPN_Data.Update(ctpn, slmoi, dgmoi);
                        isEditting = false;

                        DataTable dt = DataAccess.executeQuery("MaPN, Ngaynhap, Tongtien", "MONTH(Ngaynhap)=" + dateTime.Month + " AND YEAR(Ngaynhap)=" + dateTime.Year, "service_import");
                        dataGridViewPN.AutoGenerateColumns = false;
                        dataGridViewPN.Columns["dataGridViewTextBoxColumn2"].DataPropertyName = "Ngaynhap";
                        dataGridViewPN.Columns["dataGridViewTextBoxColumn3"].DataPropertyName = "Tongtien";
                        dataGridViewPN.Columns["dataGridViewTextBoxColumn4"].DataPropertyName = "MaPN";
                        dataGridViewPN.DataSource = dt;

                        DataTable dt2 = DataAccess.executeQuery("MaCTPN, MaDV, Soluong, Dongia, Thanhtien", "MaPN=" + selected_pn, "service_import_detail");
                        dtg_list_ctpn.AutoGenerateColumns = false;
                        dtg_list_ctpn.Columns["clm1"].DataPropertyName = "MaDV";
                        dtg_list_ctpn.Columns["clm2"].DataPropertyName = "Soluong";
                        dtg_list_ctpn.Columns["clm3"].DataPropertyName = "Dongia";
                        dtg_list_ctpn.Columns["clm4"].DataPropertyName = "Thanhtien";
                        dtg_list_ctpn.Columns["clm7"].DataPropertyName = "MaCTPN";
                        dtg_list_ctpn.DataSource = dt2;
                    }
                }
                if (e.ColumnIndex == 6 && e.RowIndex != rows_ctpn)
                {
                    if (MessageBox.Show("Bạn có chắc xoá chi tiết phiếu nhập này?", "Xác nhận", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        CTPN_DTO ctpn = new CTPN_DTO();
                        ctpn.MaCTPN = int.Parse(dtg_list_ctpn.Rows[e.RowIndex].Cells["clm7"].Value.ToString());
                        ctpn.Soluong = int.Parse(dtg_list_ctpn.Rows[e.RowIndex].Cells["clm2"].Value.ToString());
                        ctpn.MaDV = int.Parse(dtg_list_ctpn.Rows[e.RowIndex].Cells["clm1"].Value.ToString());
                        ctpn.MaPN = selected_pn;
                        ctpn.Thanhtien = int.Parse(dtg_list_ctpn.Rows[e.RowIndex].Cells["clm4"].Value.ToString());

                        CTPN_Data.Delete(ctpn);

                        DataTable dt = DataAccess.executeQuery("MaPN, Ngaynhap, Tongtien", "MONTH(Ngaynhap)=" + dateTime.Month + " AND YEAR(Ngaynhap)=" + dateTime.Year, "service_import");
                        dataGridViewPN.AutoGenerateColumns = false;
                        dataGridViewPN.Columns["dataGridViewTextBoxColumn2"].DataPropertyName = "Ngaynhap";
                        dataGridViewPN.Columns["dataGridViewTextBoxColumn3"].DataPropertyName = "Tongtien";
                        dataGridViewPN.Columns["dataGridViewTextBoxColumn4"].DataPropertyName = "MaPN";
                        dataGridViewPN.DataSource = dt;

                        DataTable dt2 = DataAccess.executeQuery("MaCTPN, MaDV, Soluong, Dongia, Thanhtien", "MaPN=" + selected_pn, "service_import_detail");
                        dtg_list_ctpn.AutoGenerateColumns = false;
                        dtg_list_ctpn.Columns["clm1"].DataPropertyName = "MaDV";
                        dtg_list_ctpn.Columns["clm2"].DataPropertyName = "Soluong";
                        dtg_list_ctpn.Columns["clm3"].DataPropertyName = "Dongia";
                        dtg_list_ctpn.Columns["clm4"].DataPropertyName = "Thanhtien";
                        dtg_list_ctpn.Columns["clm7"].DataPropertyName = "MaCTPN";
                        dtg_list_ctpn.DataSource = dt2;
                    }
                }
            }
        }