public static tblListHandoverReply InsertListHandoverReply(tblListHandoverReply handoverReply, List <tblHandover> listHandover, tblNumberGenerate numberGenerate) { var db = new dbTrainEntities(ConnectionController.GetConnection()); db.AddTotblNumberGenerates(numberGenerate); db.AddTotblListHandoverReplies(handoverReply); foreach (tblHandover handover in listHandover) { tblHandover obj = db.tblHandovers.Where(g => g.ID == handover.ID).FirstOrDefault(); if (obj != null) { obj.tblListHandoverReply = handoverReply; } } int result = db.SaveChanges(); if (result > 0) { return(handoverReply); } else { return(null); } }
public static int UpdateHandover(tblHandover handover) { try { var db = Instance(); handover.ModifiedDate = CommonFactory.GetCurrentDate(); var originHandover = db.tblHandovers.Include("tblHandoverResources").Where(g => g.ID == handover.ID).FirstOrDefault(); if (originHandover == null) { return(0); } db.Detach(originHandover); if (originHandover.EntityState == EntityState.Detached) { object original = null; if (db.TryGetObjectByKey(originHandover.EntityKey, out original)) { db.ApplyPropertyChanges(originHandover.EntityKey.EntitySetName, handover); } } return(db.SaveChanges()); } catch (Exception ex) { return(0); } }
public frmBBBG(UserInfo userInfo, string type, tblHandover handover, short mode = (short)1) { InitializeComponent(); _userInfo = userInfo; _type = type; _mode = mode; _handover = handover; }
public static int InsertBBBG(tblHandover handover, tblNumberGenerate numberGenerate) { var db = Instance(); if (handover.Type == "1") //neu la BBBG chuyen den, khong generate handoverNumber { db.AddTotblNumberGenerates(numberGenerate); } db.AddTotblHandovers(handover); return(db.SaveChanges()); }
public static int UpdateHandover(tblHandover handover, List <tblToaTau> listToaTau) { try { var db = Instance(); //xoa cac toa tau cu BBBG List <tblHandoverResource> listReource = db.tblHandoverResources.Where(x => x.tblHandover.ID == handover.ID).ToList(); foreach (tblHandoverResource resource in listReource) { db.DeleteObject(resource); } //cap nhat thong tin to BBBG tblHandover handoverOrigin = db.tblHandovers.Where(x => x.ID == handover.ID).FirstOrDefault(); if (handoverOrigin != null) { handoverOrigin.ModifiedBy = handover.ModifiedBy; handoverOrigin.NumberHandover = handover.NumberHandover; handoverOrigin.DateHandover = handover.DateHandover; handoverOrigin.CodeStation = handover.CodeStation; handoverOrigin.CodeStationFromTo = handover.CodeStationFromTo; handoverOrigin.StatusGoods = handover.StatusGoods; handoverOrigin.StatusVehicle = handover.StatusVehicle; handoverOrigin.ModifiedBy = handover.ModifiedBy; //thong tin hoi bao handoverOrigin.IsReplied = handover.IsReplied; handoverOrigin.NoteReply = handover.NoteReply; handoverOrigin.ReplyStatusGoods = handover.ReplyStatusGoods; handoverOrigin.DateReply = handover.DateReply; //them cac toa tau moi cho BBBG foreach (var toaTau in listToaTau) { var declarationResource = new tblHandoverResource { tblToaTau = toaTau }; handoverOrigin.tblHandoverResources.Add(declarationResource); } db.SaveChanges(); } return(1); } catch (Exception) { } return(0); }
private void InitData() { if (_handover == null) { return; } _handover = TrainFactory.FindHandoverByID(_handover.ID); txtNumberHandover.Text = _handover.NumberHandover; dtpHandover.Value = (DateTime)_handover.DateHandover; txtCodeCuaKhau.Text = _handover.CodeStation; ddlCuaKhau.SelectedValue = _handover.CodeStation; txtCodeGaDenDi.Text = _handover.CodeStationFromTo; ddlGaDenDi.SelectedValue = _handover.CodeStationFromTo; txtStatusGood.Text = _handover.StatusGoods; txtStatusVehicle.Text = _handover.StatusVehicle; //txtSoVanDon.Text = _handover.Ma_Chuyen_Tau; //txtSoVanDon.ReadOnly = true; cbReply.Checked = _handover.IsReplied.Value; if (cbReply.Checked) { dtpReplyDate.Enabled = true; dtpReplyDate.Value = _handover.DateReply.Value; txtReplyNote.Text = _handover.NoteReply; txtReplyNote.Enabled = true; txtReplyStatusGoods.Text = _handover.ReplyStatusGoods; txtReplyStatusGoods.Enabled = true; } else { dtpReplyDate.Enabled = false; txtReplyNote.Text = ""; txtReplyNote.Enabled = false; txtReplyStatusGoods.Enabled = false; txtReplyStatusGoods.Text = ""; } if (!_handover.tblHandoverResources.IsLoaded) { _handover.tblHandoverResources.Load(); } foreach (var resource in _handover.tblHandoverResources) { resource.tblToaTauReference.Load(); listToaTau.Add(resource.tblToaTau); } BindToaTau(null); }
public static int UpdateListHandoverReply(tblListHandoverReply handoverReply, List <tblHandover> listHandover) { //update all related Handover RemoveListReplyIDFromHandover(handoverReply.ID); //update ListHandoverReply var db = new dbTrainEntities(ConnectionController.GetConnection()); tblListHandoverReply objUpdate = db.tblListHandoverReplies.Where(g => g.ID == handoverReply.ID).FirstOrDefault(); if (objUpdate != null) { try { objUpdate.ListReplyNumber = handoverReply.ListReplyNumber; objUpdate.ListReplyDate = handoverReply.ListReplyDate; objUpdate.ReportFromDate = handoverReply.ReportFromDate; objUpdate.ReportToDate = handoverReply.ReportToDate; objUpdate.CustomsCodeReceiver = handoverReply.CustomsCodeReceiver; objUpdate.ReplyStatusGoods = handoverReply.ReplyStatusGoods; objUpdate.Note = handoverReply.Note; //db.SaveChanges(); //db.Dispose(); //db = new dbTrainEntities(ConnectionController.GetConnection()); foreach (tblHandover handover in listHandover) { tblHandover obj = db.tblHandovers.Where(g => g.ID == handover.ID).FirstOrDefault(); if (obj != null) { obj.tblListHandoverReply = objUpdate; } } return(db.SaveChanges()); } catch (Exception ex) { return(0); } } return(0); }
private bool Validate() { var valid = techlinkErrorProvider1.Validate(this); if (_mode == 0) //kiem tra so BBBG trung lap khi nhap moi { tblHandover exist = TrainFactory.FindHandoverByNumber(txtNumberHandover.Text.Trim()); if (exist != null) { MessageBox.Show("Số BBBG này đã tồn tại, xin nhập số khác"); return(false); } return(valid); } else { return(valid); } }
private void printBBBG() { try { var reportHandOver = new ReportHandOver(); var txtNumberHandover = (TextObject)reportHandOver.Section1.ReportObjects["txtNumberHandover"]; var ddlGaDenDi = (TextObject)reportHandOver.Section1.ReportObjects["ddlGaDenDi"]; var dtpHandover = (TextObject)reportHandOver.Section1.ReportObjects["dtpHandover"]; //Khong dung //var txtSummary = (TextObject)reportHandOver.Section1.ReportObjects["txtSummary"]; var txtStatusVehicle = (TextObject)reportHandOver.Section1.ReportObjects["txtStatusVehicle"]; var txtStatusGoods = (TextObject)reportHandOver.Section1.ReportObjects["txtStatusGoods"]; var txtCustoms = (TextObject)reportHandOver.Section1.ReportObjects["txtCustoms"]; //var txtPath = (TextObject)reportHandOver.Section1.ReportObjects["txtPath"]; //var txtConfirmOfToStation = (TextObject)reportHandOver.Section1.ReportObjects["txtConfirmOfToStation"]; var txtToStation = (TextObject)reportHandOver.Section1.ReportObjects["txtToStation"]; var txtFromStation = (TextObject)reportHandOver.Section1.ReportObjects["txtFromStation"]; long handoverId = _handover.ID; //1L; tblHandover handover = TrainFactory.FindHandoverByID(handoverId); if (handover != null) { if (handover.tblHandoverResources.IsLoaded == false) { handover.tblHandoverResources.Load(); } List <tblHandoverResource> listTblHandoverResources = TrainFactory.FindHandoverResourceByHandoverID(handoverId); //List<tblHandoverResource> listTblHandoverResources = handover.tblHandoverResources.ToList(); ; List <tblToaTau> listToaTau = new List <tblToaTau>(); foreach (tblHandoverResource obj in listTblHandoverResources) { if (obj.tblToaTauReference.IsLoaded == false) { obj.tblToaTauReference.Load(); } if (obj.tblToaTau != null) { listToaTau.Add(obj.tblToaTau); } } DataSet1 dataset = new DataSet1(); DataTable dt = dataset.tblToaTau; //dt = ListToDataTable.ToDataTable(listToaTau); foreach (tblToaTau toaTau in listToaTau) { if (toaTau.tblChuyenTauReference.IsLoaded == false) { toaTau.tblChuyenTauReference.Load(); } dt.Rows.Add(toaTau.ToaTauID, toaTau.Ma_ToaTau , toaTau.So_VanTai_Don , toaTau.Ngay_VanTai_Don , toaTau.Ten_DoiTac , toaTau.Ma_DoanhNghiep , toaTau.Ten_Hang , toaTau.Trong_Luong , toaTau.Don_Vi_Tinh , toaTau.Seal_VanTai , toaTau.Seal_VanTai2 , toaTau.Seal_HaiQuan , toaTau.Seal_HaiQuan2 , toaTau.Ghi_Chu , toaTau.CreatedDate , toaTau.CreatedBy , toaTau.ModifiedDate , toaTau.ModifiedBy , toaTau.tblChuyenTau.TrainID); } reportHandOver.SetDataSource(dataset); String fromStation = CustomsFacory.FindByCode(handover.CodeStation).CustomsName; String toStation = CustomsFacory.FindByCode(handover.CodeStationFromTo).CustomsName; //if (handover.DateHandover != null) //{ // String dateString = "Hồi " + handover.DateHandover.Value.Hour + " giờ " + handover.DateHandover.Value.Minute + " phút, ngày " + handover.DateHandover.Value.Day + " tháng " + handover.DateHandover.Value.Month + " năm " + handover.DateHandover.Value.Year; // txtSummary.Text = dateString + " " + fromStation + " bàn giao cho Chi nhánh vận tải hàng hóa đường sắt Đồng Đăng" + // " lô hàng nhập khẩu chuyển cảng vận chuyển từ " + fromStation + " đến " + toStation + "."; //} //txtNumberHandover.Text = "Số: " + handover.NumberHandover + "/BBBG-HQGA"; txtNumberHandover.Text = "Số: " + handover.NumberHandover; // Ten hai quan den ddlGaDenDi.Text = "Kính gửi: " + toStation; if (handover.DateHandover != null) { dtpHandover.Text = "Thời gian chuyển: hồi " + handover.DateHandover.Value.Hour + " giờ ngày " + handover.DateHandover.Value.Day + " tháng " + handover.DateHandover.Value.Month + " năm " + handover.DateHandover.Value.Year; } txtStatusVehicle.Text = handover.StatusVehicle; txtStatusGoods.Text = handover.StatusGoods; txtCustoms.Text = fromStation.ToUpper(); //txtPath.Text = "Từ " + fromStation + " đến " + toStation; //txtConfirmOfToStation.Text = "5. Xác nhận của " + toStation + ":"; txtFromStation.Text = fromStation; txtToStation.Text = toStation; } reportHandOver.Section3.SectionFormat.EnableUnderlaySection = true; reportHandOver.Section3.SectionFormat.EnableKeepTogether = true; FrmPreviewReport frmReport = new FrmPreviewReport(reportHandOver); frmReport.MdiParent = this.MdiParent; frmReport.Show(); } catch (Exception ex) { throw ex; } }
private void btnAddNew_Click(object sender, EventArgs e) { var dr = MessageBox.Show(ConstantInfo.CONFIRM_ADD_NEW, "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr != DialogResult.Yes) { return; } try { if (!Validate()) { return; } var train = TrainFactory.GetByCode(txtSoVanDon.Text.Trim()); if (grdToaTau.RowCount == 0) { MessageBox.Show("Bạn phải chọn ít nhất một toa tàu!"); return; } Nullable <DateTime> replyDate = null; if (cbReply.Checked) { replyDate = dtpReplyDate.Value; } var handOver = new tblHandover { NumberHandover = txtNumberHandover.Text.Trim(), DateHandover = dtpHandover.Value, CodeStation = txtCodeCuaKhau.Text.Trim(), CodeStationFromTo = txtCodeGaDenDi.Text.Trim(), StatusGoods = txtStatusGood.Text.Trim(), StatusVehicle = txtStatusVehicle.Text.Trim(), CreatedBy = _userInfo.UserID, CreatedDate = CommonFactory.GetCurrentDate(), Type = _type.ToString(), IsReplied = cbReply.Checked, DateReply = replyDate, NoteReply = cbReply.Checked?txtReplyNote.Text:null, ReplyStatusGoods = cbReply.Checked ? txtReplyStatusGoods.Text : null, }; foreach (var toaTau in listToaTau) { var handOverResource = new tblHandoverResource { tblToaTau = toaTau }; handOver.tblHandoverResources.Add(handOverResource); } var result = TrainFactory.InsertBBBG(handOver, _NumberGenerate); if (result > 0) { if (cbPrint.Checked == true) { MessageBox.Show("Thêm mới Biên bản bàn giao thành công. Bạn hãy tắt hộp thoại này để xem bản in"); _handover = TrainFactory.FindHandoverByID(handOver.ID); printBBBG(); Reset(); } else { MessageBox.Show("Thêm mới Biên bản bàn giao thành công!"); Reset(); } } else { MessageBox.Show("Thêm mới Biên bản bàn không thành công!"); } } catch (Exception ex) { if (GlobalInfo.IsDebug) { MessageBox.Show(ex.ToString()); } } }