public void Save(ref DataTable dt) { Luu = false; grvData.PostEditor(); //if (!Check_Valid(dt)) //{ // return; //} try { TheoDoiVatTu_BLL.YeuCauVatTu_BLL obj = new TheoDoiVatTu_BLL.YeuCauVatTu_BLL(); DataTable dtRemine; dtRemine = dt.GetChanges(); if (dtRemine != null) { for (int i = 0; i < dtRemine.Rows.Count; i++) { if (dtRemine.Rows[i]["Status"].ToString() == "3" || dtRemine.Rows[i]["Status"].ToString() == "2") { continue; } YeuCauVatTuModel model = new YeuCauVatTuModel(); model.UserID = Global.UserID; model.TenVatTu = dtRemine.Rows[i]["TenVatTu"].ToString(); model.MaVatTu = dtRemine.Rows[i]["MaVatTu"].ToString(); model.Hang = dtRemine.Rows[i]["Hang"].ToString(); model.MaSP = dtRemine.Rows[i]["MaSP"].ToString(); model.TenDuAn = dtRemine.Rows[i]["TenDuAn"].ToString(); model.MaDuAn = dtRemine.Rows[i]["MaDuAn"].ToString(); //["MaDuAn"].ToString(); model.SoLuong = dtRemine.Rows[i]["SoLuong"].ToString(); model.NgayYeuCau = (dtRemine.Rows[i]["NgayYeuCau"].ToString()); //["NgayYeuCau"].ToString(); model.NgayVeDuKien = (dtRemine.Rows[i]["NgayVeDuKien"].ToString()); //["NgayVeDuKien"].ToString(); model.NgayThucTe = (dtRemine.Rows[i]["NgayThucTe"].ToString()); //["NgayThucTe"].ToString(); model.ThoiGianDatHangTHucTe = dtRemine.Rows[i]["ThoiGianDatHangTHucTe"].ToString(); //["ThoiGianDatHangTHucTe"].ToString(); model.NguyenNhanCham = dtRemine.Rows[i]["NguyenNhanCham"].ToString(); //["NguyenNhanCham"].ToString(); model.GhiChu = dtRemine.Rows[i]["GhiChu"].ToString(); //["GhiChu"].ToString(); model.NgayVeDuKien2 = dtRemine.Rows[i]["NgayVeDuKien2"].ToString(); model.NgayVeDuKien3 = dtRemine.Rows[i]["NgayVeDuKien3"].ToString(); if (dtRemine.Rows[i][colID.FieldName] == DBNull.Value) //add new { YeuCauVatTuBO.Instance.Insert(model); } else { if (dtRemine.Rows[i]["UserID"].ToString() == Global.UserID.ToString()) { model.ID = Convert.ToInt32(dtRemine.Rows[i]["ID"].ToString()); YeuCauVatTuBO.Instance.Update(model); } } Luu = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnSave_Click(object sender, EventArgs e) { //for (int i = 0; i < gridView1.GetSelectedRows().Count(); i++) //{ // string ff = gridView1.GetRowCellValue(gridView1.GetSelectedRows()[i], colHang).ToString(); //} //DataTable dt2 = new DataTable(); //foreach (GridColumn colum in gridView1.VisibleColumns) //{ // dt2.Columns.Add(colum.FieldName, colum.ColumnType); //} //for (int i = 0; i < gridView1.GetSelectedRows().Count(); i++) //{ // DataRow row = dt2.NewRow(); // foreach (GridColumn colum in gridView1.VisibleColumns) // { // row[colum.FieldName] = gridView1.GetRowCellValue(gridView1.GetSelectedRows()[i], colum); // } // dt2.Rows.Add(row); //} //return; try { DataTable dt = new DataTable(); foreach (GridColumn colum in gridView1.VisibleColumns) { dt.Columns.Add(colum.FieldName, colum.ColumnType); } for (int i = 0; i < gridView1.DataRowCount; i++) { DataRow row = dt.NewRow(); foreach (GridColumn colum in gridView1.VisibleColumns) { row[colum.FieldName] = gridView1.GetRowCellValue(i, colum); } dt.Rows.Add(row); } DataTable dtRemine = dt; if (dtRemine != null) { for (int i = 0; i < dtRemine.Rows.Count; i++) { YeuCauVatTuModel model = new YeuCauVatTuModel(); model.UserID = Global.UserID; model.TenVatTu = dtRemine.Rows[i]["TenVatTu"].ToString(); model.MaVatTu = dtRemine.Rows[i]["MaVatTu"].ToString(); model.Hang = dtRemine.Rows[i]["Hang"].ToString(); model.MaSP = dtRemine.Rows[i]["MaSP"].ToString(); model.TenDuAn = dtRemine.Rows[i]["TenDuAn"].ToString(); model.MaDuAn = dtRemine.Rows[i]["MaDuAn"].ToString(); //["MaDuAn"].ToString(); model.SoLuong = dtRemine.Rows[i]["SoLuong"].ToString(); model.NgayYeuCau = NgayLap; //["NgayYeuCau"].ToString(); model.NgayVeDuKien = ""; //(dtRemine.Rows[i]["NgayVeDuKien"].ToString());//["NgayVeDuKien"].ToString(); model.NgayThucTe = ""; // (dtRemine.Rows[i]["NgayThucTe"].ToString());//["NgayThucTe"].ToString(); model.ThoiGianDatHangTHucTe = dtRemine.Rows[i]["ThoiGianDatHangTHucTe"].ToString(); //["ThoiGianDatHangTHucTe"].ToString(); model.NguyenNhanCham = dtRemine.Rows[i]["NguyenNhanCham"].ToString(); //["NguyenNhanCham"].ToString(); model.GhiChu = dtRemine.Rows[i]["GhiChu"].ToString(); YeuCauVatTuBO.Instance.Insert(model); } } MessageBox.Show("Nhập dữ liệu từ file Excel thành công", "Thông báo"); } catch (Exception) { throw; } }
protected YeuCauVatTuFacade(YeuCauVatTuModel model) : base(model) { }