public frmTrainPassengers(frmSearchTrainPassenger frmSearch, UserInfo userInfo, tblTrain tblTrain, short mode = 0) { InitializeComponent(); _userInfo = userInfo; _tblTrain = tblTrain; _frmSearch = frmSearch; _mode = mode; }
public ActionResult DeleteConfirmed(int id) { tblTrain tblTrain = db.tblTrains.Find(id); db.tblTrains.Remove(tblTrain); db.SaveChanges(); return(RedirectToAction("Index")); }
public static int Insert(tblTrain train) { var db = new dbTrainEntities(ConnectionController.GetConnection()); train.CreatedDate = CommonFactory.GetCurrentDate(); db.AddTotblTrains(train); return(db.SaveChanges()); }
public ActionResult Edit([Bind(Include = "TrainNo,TrainName,Departure,Destination")] tblTrain tblTrain) { if (ModelState.IsValid) { db.Entry(tblTrain).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblTrain)); }
public ActionResult Create([Bind(Include = "TrainNo,TrainName,Departure,Destination")] tblTrain tblTrain) { if (ModelState.IsValid) { db.tblTrains.Add(tblTrain); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tblTrain)); }
// GET: tblTrains/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } tblTrain tblTrain = db.tblTrains.Find(id); if (tblTrain == null) { return(HttpNotFound()); } return(View(tblTrain)); }
public static int Update(tblTrain train) { var db = new dbTrainEntities(ConnectionController.GetConnection()); train.ModifiedDate = CommonFactory.GetCurrentDate(); var originTrain = db.tblTrains.Where(g => g.TrainID == train.TrainID).FirstOrDefault(); if (originTrain == null) { return(-1); } db.Attach(originTrain); db.ApplyPropertyChanges("tblTrains", train); return(db.SaveChanges()); }
private void btnDelete_Click(object sender, EventArgs e) { try { if (this.grdTrain.SelectedRows.Count > 0) { int selectedIndex = grdTrain.SelectedRows[0].Index; // gets the RowID from the first column in the grid Int64 trainID = Int64.Parse(grdTrain[0, selectedIndex].Value.ToString()); tblTrain train = TrainFactory.FindTrainByID(trainID); if (train == null) { MessageBox.Show("Tàu khách này không còn tồn tại trong Cơ Sở Dữ Liệu. Bạn hãy kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } int delete = TrainFactory.Delete(trainID); if (delete > 0) { MessageBox.Show("Xóa thành công"); search(); } else { MessageBox.Show("Xóa không thành công, xin kiểm tra lại kết nối mạng"); } } else { MessageBox.Show("Bạn cần chọn một bản ghi để xóa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { if (GlobalInfo.IsDebug) { MessageBox.Show(ex.ToString()); } } }
private void btnAddNew_Click(object sender, EventArgs e) { try { if (!Validate()) { return; } var train = new tblTrain(); train.Number = txtNumberTrain.Text.Trim(); train.Type = (short)((ComboBoxItem)ddlTypeName.SelectedItem).Value; if (train.Type == (short)TrainType.TypeExport) { train.IsExport = true; train.DateExport = dtpRegisterDate.Value; } else if (train.Type == (short)TrainType.TypeImport) { train.IsImport = true; train.DateImport = dtpRegisterDate.Value; } train.NumberPartTrain = txtNumberPartofTrain.Text.Trim(); train.CreatedBy = _userInfo.UserID; if (TrainFactory.Insert(train) > 0) { MessageBox.Show("Thêm mới thành công!"); Reset(); } else { MessageBox.Show("Thêm mới không thành công!"); } } catch (Exception ex) { if (GlobalInfo.IsDebug) { MessageBox.Show(ex.ToString()); } } }
private void btnAddNew_Click(object sender, EventArgs e) { var confirm = MessageBox.Show(ConstantInfo.CONFIRM_ADD_NEW, "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (confirm != DialogResult.Yes) { return; } try { if (!Validate()) { return; } var trainPassenger = new tblTrain(); trainPassenger.Number = txtNumberTrain.Text.Trim(); trainPassenger.Type = (short)((ComboBoxItem)ddlTypeName.SelectedItem).Value; trainPassenger.DateImportExport = dtpRegisterDate.Value; trainPassenger.Jounery = txtJourney.Text.Trim(); trainPassenger.PassengerVN = int.Parse(txtNumberPersonVN.Text); trainPassenger.PassengerForegin = int.Parse(txtNumberPersonForegin.Text); trainPassenger.Staff = int.Parse(txtNumberStaff.Text); trainPassenger.CreatedBy = _userInfo.UserID; if (TrainFactory.Insert(trainPassenger) > 0) { MessageBox.Show("Thêm mới thành công!"); Reset(); } else { MessageBox.Show("Thêm mới không thành công!"); } } catch (Exception ex) { if (GlobalInfo.IsDebug) { MessageBox.Show(ex.ToString()); } } }
private void grdTrain_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { try { if (this.grdTrain.SelectedRows.Count > 0) { int selectedIndex = grdTrain.SelectedRows[0].Index; // gets the RowID from the first column in the grid Int64 trainID = Int64.Parse(grdTrain[0, selectedIndex].Value.ToString()); tblTrain train = TrainFactory.FindTrainByID(trainID); if (train == null) { MessageBox.Show("Tàu khách này không còn tồn tại trong Cơ Sở Dữ Liệu. Bạn hãy kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } frmTrainPassengers form = new frmTrainPassengers(this, _userInfor, train, 1); form.MdiParent = this.MdiParent; form.Show(); } else { MessageBox.Show("Bạn cần chọn một bản ghi để cập nhật", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { if (GlobalInfo.IsDebug) { MessageBox.Show(ex.ToString()); } } }
public static tblTrain CreatetblTrain(long trainID, string branchId) { tblTrain tblTrain = new tblTrain(); tblTrain.TrainID = trainID; tblTrain.BranchId = branchId; return tblTrain; }
public void AddTotblTrains(tblTrain tblTrain) { AddObject("tblTrains", tblTrain); }
private void btnAddNew_Click(object sender, EventArgs e) { try { if (!Validate()) { return; } var train = new tblTrain(); train.Number = txtNumberTrain.Text.Trim(); var type = (short)((ComboBoxItem)ddlTypeName.SelectedItem).Value; train.Type = type; if (type == (short)TrainType.TypeExport || type == (short)TrainType.TypeExportChange || type == (short)TrainType.TypeExportNormal) { train.IsExport = true; train.DateExport = CommonFactory.GetCurrentDate(); } else { train.IsImport = true; train.DateImport = CommonFactory.GetCurrentDate(); } if (type == (short)TrainType.TypeExportChange || type == (short)TrainType.TypeImportChange) { train.NumberHandover = txtNumberHandover.Text.Trim(); train.DateHandover = dtpHandover.Value; train.CodeStation = txtCodeCuaKhau.Text.Trim(); train.CodeStationFromTo = txtCodeGaDenDi.Text.Trim(); train.StatusVehicle = txtStatusVehicle.Text.Trim(); train.StatusGoods = txtStatusGood.Text.Trim(); } train.CreatedBy = _userInfo.UserID; if (TrainFactory.Insert(train) > 0) { //insert tờ khai if (type == (short)TrainType.TypeExportNormal || type == (short)TrainType.TypeImportNormal) { var declare = new tblToKhaiTau() { Number = Convert.ToInt32(txtExportNumber.Text.Trim()), DateDeclaration = dtpDeclaration.Value, TypeCode = txtTypeExport.Text.Trim(), CustomCode = txtCustomsCode.Text.Trim(), CreatedBy = _userInfo.UserID, //TrainID = train.TrainID }; TrainFactory.InsertToKhai(declare); } //insert toa tàu if (grdToaTau.Rows.Count > 0) { var listToaTau = new List <tblToaTau>(); for (int i = 0; i < grdToaTau.Rows.Count; i++) { var toaTau = (tblToaTau)grdToaTau.Rows[i].DataBoundItem; toaTau.CreatedBy = _userInfo.UserID; //toaTau.TrainID = train.TrainID; listToaTau.Add(toaTau); } TrainFactory.InsertToaTau(listToaTau); } MessageBox.Show("Thêm mới thành công!"); Reset(); } else { MessageBox.Show("Thêm mới không thành công!"); } } catch (Exception ex) { if (GlobalInfo.IsDebug) { MessageBox.Show(ex.ToString()); } } }