Ejemplo n.º 1
0
        private void DoSave(object ignore)
        {
            try
            {
                long ticketId = -1;
                ImportTicketData.PumpTotal = BusinessHelper.FindPumpTotalByTankId(importTicketData.TankId);

                BusinessHelper.InserUpdateImportTicket(
                    ref ticketId, importTicketData.TankId, ImportTicketData.ImportDate, ImportTicketData.DriverName, ImportTicketData.CarPlate,
                    ImportTicketData.StaffName, ImportTicketData.StaffPos, ImportTicketData.TemplateBottleId, ImportTicketData.ImportCapacity,
                    ImportTicketData.FuelId, ImportTicketData.MaxCapacity, ImportTicketData.TankCapacity, ImportTicketData.TankLevel, ImportTicketData.PumpTotal,
                    ImportTicketData.ExStore, ImportTicketData.SealId, ImportTicketData.SealStatus);

                App.Log.LogDebugMessage(String.Format(@"ticketId: {0}", ticketId));
                if (ticketId != -1)
                {
                    ImportTicketData.TicketId = ticketId;

                    System.Windows.MessageBox.Show(@"Lưu thông tin thành công!!!", @"Lưu thông tin nhập bồn", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Information);

                    CloseAction(); // Invoke the Action previously defined by the View
                }
                else
                {
                    System.Windows.MessageBox.Show(@"Có lỗi trong quá trình lưu thông tin!!!", @"Lưu thông tin nhập bồn", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                }
            }
            catch (Exception ex)
            {
                App.Log.LogException(ex);
            }
        }
Ejemplo n.º 2
0
 private void DoStationStat(object ignore)
 {
     try
     {
         List <TankModel> tankList = new List <TankModel>(this._CollecTank);
         foreach (var tank in tankList)
         {
             tank.TankPumpTotal = BusinessHelper.FindPumpTotalByTankId(tank.TankId);
         }
         ViewModelStationStat vmStationStat  = new ViewModelStationStat(tankList, ClientPub);
         StationStatWindow    stationStatWnd = new StationStatWindow();
         stationStatWnd.DataContext = vmStationStat;
         stationStatWnd.WindowState = WindowState.Maximized;
         stationStatWnd.Show();
     }
     catch (Exception ex)
     {
         App.Log.LogException(ex);
     }
 }
Ejemplo n.º 3
0
        private void DoImportFinish(UInt64 tankId)
        {
            var selTank = (from _tank in CollecTank
                           where _tank.TankId == (long)tankId
                           select _tank).FirstOrDefault() as TankModel;
            DateTime _now = DateTime.Now;

            try
            {
                if (App.Demo != 1)
                {
                    if (MessageBox.Show(String.Format(@"Kết thúc nhập bồn {0}", selTank.Description), @"Nhập nhiên liệu", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.Cancel)
                    {
                        return;
                    }
                    BusinessHelper.SaveTankData(selTank.TankId, selTank.Capacity, selTank.Thermometer, selTank.WaterCapacity, (Byte)SaveDataStatus.SAVE, _now);

                    DataTable dt = BusinessHelper.GetTankList(selTank.TankId);
                    foreach (DataRow _dr in dt.Rows)
                    {
                        long tankid = Convert.ToInt64(_dr["tankid"]);
                        //BusinessHelper.UpdateTankStatus(tankid);
                        BusinessHelper.UpdatePumpStatus(tankid);
                    }
                }


                DataTable    _dtReport     = BusinessHelper.FindLastTicketByTankId(selTank.TankId);
                ImportReport _importReport = new ImportReport();
                long         _ticketId     = -1;
                long         _tankId       = -1;
                if (_dtReport != null)
                {
                    DataRow _dr = _dtReport.Rows[0];
                    _ticketId = Convert.ToInt64(_dr["ticket_id"]);
                    _tankId   = Convert.ToInt64(_dr["tank_id"]);
                    _importReport.StationName    = selTank.StationName;
                    _importReport.ReportDate     = Convert.ToDateTime(_dr["ticketdate"]);
                    _importReport.DriverName     = Convert.ToString(_dr["drivername"]);
                    _importReport.CarPlate       = Convert.ToString(_dr["carplate"]);
                    _importReport.StaffName      = Convert.ToString(_dr["staffname"]);
                    _importReport.StaffPos       = Convert.ToString(_dr["staffpos"]);
                    _importReport.TemplateBottle = Convert.ToString(_dr["templatebottle"]);
                    _importReport.ImportCapacity = Convert.ToDouble(_dr["importcapacity"]);
                    long fuelId = Convert.ToInt64(_dr["fuel_id"]);
                    _importReport.Fuel = BusinessHelper.FindFuelById(fuelId);

                    _importReport.BeginCapacity  = Convert.ToDouble(_dr["capacity"]);
                    _importReport.BeginLevel     = Convert.ToDouble(_dr["level"]);
                    _importReport.BeginTotalPump = Convert.ToUInt64(_dr["pumptotal"]);
                    _importReport.ExStore        = Convert.ToString(_dr["exstore"]);
                    _importReport.SealId         = Convert.ToString(_dr["sealid"]);
                    _importReport.SealStatus     = Convert.ToBoolean(_dr["sealstatus"]);
                }
                else
                {
                    System.Windows.MessageBox.Show(@"Phiếu không tồn tại!!!", @"Kết thúc nhập bồn", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    return;
                }
                _importReport.EndTotalPump = BusinessHelper.FindPumpTotalByTankId(selTank.TankId);
                _importReport.EndCapacity  = selTank.Capacity;
                _importReport.EndLevel     = selTank.FuelLevel;
                _importReport.RealCapacity = _importReport.EndCapacity - _importReport.BeginCapacity;

                if (!BusinessHelper.UpdateImportTicket(_ticketId, _importReport.EndTotalPump, _importReport.EndCapacity, _importReport.EndLevel))
                {
                    App.Log.LogInfoMessage(String.Format("Update ticket {0} failed", _ticketId));
                    System.Windows.MessageBox.Show(@"Lỗi trong quá trình cập nhật phiếu!!!", @"Kết thúc nhập bồn", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    return;
                }
                else
                {
                    String _pubTopic = String.Format(@"importticket/{0}", _tankId);
                    String _pubData  = String.Format(@"{{""ticketId"": {0} }}", _ticketId);
                    if ((ClientPub != null) && (!ClientPub.IsConnected))
                    {
                        string pubClientId = Guid.NewGuid().ToString();


                        ClientPub.Connect(pubClientId, _MqttUser, _MqttPwd);
                    }
                    ClientPub.Publish(_pubTopic, Encoding.UTF8.GetBytes(_pubData), MqttMsgBase.QOS_LEVEL_AT_LEAST_ONCE, false);

                    selTank.IsImportFinished = true;

                    App.Log.LogDebugMessage("Topic: " + _pubTopic + "\t Data:" + _pubData);
                }



                ImportReportWindow    importReportWnd = new ImportReportWindow();
                ViewModelImportReport vmImportReport;
                if (App.Demo == 1)
                {
                    vmImportReport = new ViewModelImportReport();
                }
                else
                {
                    vmImportReport = new ViewModelImportReport(_importReport);
                }


                importReportWnd.DataContext = vmImportReport;
                importReportWnd.ShowDialog();
            }
            catch (Exception ex)
            {
                App.Log.LogException(ex);
            }
        }