Example #1
0
 private void btn_lappn_Click(object sender, EventArgs e)
 {
     if (!daLap)
     {
         if ((dgv_ct.DataSource as DataTable) == null || (dgv_ct.DataSource as DataTable).Rows.Count == 0)
         {
             MessageBox.Show("Chưa có nguyên liệu xuất");
             return;
         }
         try
         {
             timeNow = DateTime.Now;
             if (busPX.them(new DTO.PhieuNhapDTO()
             {
                 MaNV1 = (Application.OpenForms[1] as frmGui).NV.MaNV1,
                 NgayLap1 = timeNow,
                 NgayNhap1 = date_ngayxuat.Value.Date,
                 DiaChi1 = tb_diachi.Text,
                 TinhTrang1 = "False",
                 TongTien1 = tongtien
             }) == true)
             {
                 DataTable dtMaPX = busPX.loadMaPX(timeNow);
                 if (dtMaPX != null && dtMaPX.Rows.Count == 1)
                 {
                     mapn = dtMaPX.Rows[0][0].ToString();
                     try
                     {
                         DataTable  temp = new DataTable("ctphieunhap");
                         DataColumn column;
                         DataRow    dataRow;
                         //mapx
                         {
                             column            = new DataColumn();
                             column.DataType   = Type.GetType("System.String");
                             column.ColumnName = "mapn";
                             temp.Columns.Add(column);
                             //manl
                             column            = new DataColumn();
                             column.DataType   = Type.GetType("System.String");
                             column.ColumnName = "manl";
                             temp.Columns.Add(column);
                             //soluong
                             column            = new DataColumn();
                             column.DataType   = Type.GetType("System.Single");
                             column.ColumnName = "soluong";
                             temp.Columns.Add(column);
                             //dongia
                             column            = new DataColumn();
                             column.DataType   = Type.GetType("System.Single");
                             column.ColumnName = "dongia";
                             temp.Columns.Add(column);
                         }
                         foreach (DataRow row in (dgv_ct.DataSource as DataTable).Rows)
                         {
                             dataRow            = temp.NewRow();
                             dataRow["mapn"]    = mapn;
                             dataRow["manl"]    = row[0];
                             dataRow["soluong"] = row[3];
                             dataRow["dongia"]  = row[4];
                             temp.Rows.Add(dataRow);
                         }
                         if (busCT.updateData(temp))
                         {
                             MessageBox.Show("Lập phiếu xuất thành công");
                             daLap = true;
                         }
                         else
                         {
                             busPX.xoa(new DTO.PhieuNhapDTO()
                             {
                                 MaNV1 = mapn
                             });
                             MessageBox.Show("Lập phiếu xuất thất bai");
                         }
                     }
                     catch (Exception ex)
                     {
                         MessageBox.Show("Lỗi thêm chi tiết " + ex.Message);
                     }
                 }
                 else
                 {
                     MessageBox.Show("Thêm thất bại");
                 }
             }
             else
             {
                 MessageBox.Show("Lập phiếu nhập thất bại");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Thêm phiếu nhập " + ex.Message);
         }
     }
     else
     {
         DialogResult dialogResult = MessageBox.Show("Bạn có muốn lập phiếu xuất mới", "Phiếu xuất đã được lập", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             clearData();
             daLap = false;
         }
         else if (dialogResult == DialogResult.No)
         {
             return;
         }
     }
 }