private void btnAddNew_Click(object sender, EventArgs e) { try { if (!Validate()) return; var toaTau = new tblToaTau() { Ma_ToaTau = txtNumber.Text.Trim(), So_VanTai_Don = txtSoVanDon.Text.Trim(), Ngay_VanTai_Don = dtpVanDon.Value, Ten_DoiTac = txtPartner.Text.Trim(), Ma_DoanhNghiep = txtCompanyCode.Text.Trim(), Ten_Hang = txtTenHang.Text.Trim(), Trong_Luong = txtTrongLuong.Text.Trim(), Don_Vi_Tinh = txtDVT.Text.Trim(), Seal_VanTai = txtSealVT.Text.Trim(), Seal_HaiQuan = txtSealHQ.Text.Trim(), Ghi_Chu = txtNote.Text.Trim() }; _listToaTau.Add(toaTau); ((frmTrainImport)this.Owner.ActiveMdiChild).BindToaTau(); MessageBox.Show("Thêm mới toa tàu thành công!"); Reset(); } catch (Exception ex) { if (GlobalInfo.IsDebug) MessageBox.Show(ex.ToString()); } }
public static int InsertToaTau(tblToaTau toaTau) { var _db = new dbEcustomEntities(Common.Decrypt(ConfigurationManager.ConnectionStrings["dbEcustomEntities"].ConnectionString, true)); _db.Connection.Open(); toaTau.CreatedDate = CommonFactory.GetCurrentDate(); toaTau.BranchId = FDHelper.RgCodeOfUnit(); _db.AddTotblToaTaus(toaTau); try { if (_db.Connection.State == ConnectionState.Closed) _db.Connection.Open(); return _db.SaveChanges(); } catch (Exception ex) { return -1; } finally { _db.Connection.Close(); } }