SafeDispatch/SubscriberAndUserManager/controlReports.cs

266 lines
11 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SafeMobileLib;
using SafeMobileLib.DBmanagers;
using Telerik.WinControls.UI;
namespace SubscriberAndUserManager
{
public partial class controlReports : UserControl
{
DBdailyreportManager regManager;
DBuserManager usrManager;
List<dailyReport> ReportList;
private void setLanguage()
{
gvReports.Columns[0].HeaderText = MainForm.returnLNGString("reptype");
gvReports.Columns[1].HeaderText = MainForm.returnLNGString("emailname");
gvReports.Columns[2].HeaderText = MainForm.returnLNGString("start");
gvReports.Columns[3].HeaderText = MainForm.returnLNGString("end");
gvReports.Columns[4].HeaderText = MainForm.returnLNGString("unitname");
gvReports.Columns[5].HeaderText = MainForm.returnLNGString("geoname");
labelReportName.Text = MainForm.returnLNGString("Dailyreports");
labelReportDetails.Text = MainForm.returnLNGString("DailyReportsDetails");
}
public controlReports(DBdailyreportManager DBreg, DBuserManager DBuser)
{
InitializeComponent();
usrManager = DBuser;
setLanguage();
regManager = DBreg;
populateList();
//showRegistrations();
// set the row height
gvReports.TableElement.RowHeight = 43;
this.gvReports.EnableAlternatingRowColor = true;
this.gvReports.TableElement.GridViewElement.TableElement.AlternatingRowColor = Color.LightYellow;
// remove border for grid
this.gvReports.GridViewElement.DrawBorder = false;
this.gvReports.GridViewElement.GroupPanelElement.DrawBorder = false;
GridViewComboBoxColumn comboColumn = new GridViewComboBoxColumn("userName");
//set the column data source - the possible column values
List<string> usersNameList = usrManager.getAllUsersNames();
comboColumn.DataSource = usersNameList;
//set the FieldName - the column will retrieve the value from "Phone" column in the data table
comboColumn.FieldName = "userName";
comboColumn.Width = 200;
//add the column to the grid
gvReports.Columns.Add(comboColumn);
gvReports.Columns["userName"].HeaderText = MainForm.returnLNGString("usename");
}
public void populateList()
{
try
{
ReportList = regManager.getAlldailyReports();
if (ReportList.Count > 0)
panelNoEvents.Visible = false;
else
panelNoEvents.Visible = true;
foreach (dailyReport obj in ReportList)
{
if (obj.intdatafrom == 0)
{
obj.datafrom = DateTime.Now;
obj.datato = DateTime.Now;
}
else
{
obj.datafrom = GetDTFromSeconds(ConvertGMTToLocal(obj.intdatafrom));
obj.datato = GetDTFromSeconds(ConvertGMTToLocal(obj.intdatato));
}
if (obj.unitname.Contains(','))
{
obj.unitname = "Multiple units";
}
else
{
if (obj.unitname.Length > 0)
{
if (Convert.ToInt32(obj.reptype) != 5)
{
//scot ID
obj.unitname = regManager.get_Vehname_from_sc_id(obj.unitname);
}
else //in functie de iMEI
{
obj.unitname = regManager.get_Vehname_from_imei(obj.unitname);
}
}
}
if (obj.zonename != "0")
{
if (Convert.ToInt32(obj.reptype) == 1) obj.zonename = regManager.get_Zonename_from_ID(obj.zonename);
else if (Convert.ToInt32(obj.reptype) == 4) obj.zonename = regManager.get_Placename_from_ID(obj.zonename);
}
switch (Convert.ToInt32(obj.reptype))
{
case 0: obj.reptype = MainForm.returnLNGString("RFID"); break; //RFID
case 1: obj.reptype = MainForm.returnLNGString("zoneAlarms"); break; //"Zone alarms"
case 2: obj.reptype = MainForm.returnLNGString("speedalarm"); break; //Speed alarms
case 3: obj.reptype = MainForm.returnLNGString("emergAlarms"); break; //Emergency alarms
case 4: obj.reptype = MainForm.returnLNGString("landmarkAlarms"); break; //Landmark alarms
case 5: obj.reptype = MainForm.returnLNGString("unitOnOff"); break; //Unit ON/OFF
case 6: obj.reptype = MainForm.returnLNGString("eod"); break; //End of the day
case 7: obj.reptype = MainForm.returnLNGString("stopsReport"); break; // Stops report
case 8: obj.reptype = MainForm.returnLNGString("idleReport"); break; //Idle report
case 9: obj.reptype = MainForm.returnLNGString("fleetReport"); break; //Fleet report
case 10: obj.reptype = MainForm.returnLNGString("smsReceived"); break; //Text Messaging Received
case 11: obj.reptype = MainForm.returnLNGString("smsSend"); break; //Text Messaging Send
case 12: obj.reptype = MainForm.returnLNGString("callReceived"); break; //Call Received
case 13: obj.reptype = MainForm.returnLNGString("callSend"); break; // Call Send
case 14: obj.reptype = MainForm.returnLNGString("telemetryAlarm"); break; //Telemetry Alarm
case 15: obj.reptype = MainForm.returnLNGString("telemetryEvent"); break; // Telemetry Event
case 16: obj.reptype = MainForm.returnLNGString("history"); break; //History
case 17: obj.reptype = MainForm.returnLNGString("allAlarms"); break; //All Alarms
case 18: obj.reptype = MainForm.returnLNGString("smsGPS"); break;//Text message with GPS
case 19: obj.reptype = MainForm.returnLNGString("ticketReport"); break; //Job Ticketing Report
}
}
this.gvReports.MasterTemplate.AutoGenerateColumns = false;
gvReports.DataSource = ReportList;
}
catch (Exception ex)
{
SM.Debug("Error on populate"+ex.ToString());
}
}
public System.DateTime GetDTFromSeconds(Int32 param)
{
System.DateTime dateTime;
dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0);
dateTime = dateTime.AddSeconds((double)param);
return dateTime;
}
public Int32 ConvertGMTToLocal(Int32 param)
{
DateTime time = this.GetDTFromSeconds(param);
DateTime GMTTime = time.ToUniversalTime();
TimeSpan span = time - GMTTime;
long nOfSeconds = (long)span.TotalSeconds;
return (Int32)(nOfSeconds + param);
}
private void gvReports_ContextMenuOpening(object sender, Telerik.WinControls.UI.ContextMenuOpeningEventArgs e)
{
try
{
RadDropDownMenu openedSMSmenu = new RadDropDownMenu();
RadMenuItem menuItem1 = new RadMenuItem(MainForm.returnLNGString("delsel"));
menuItem1.Click += new EventHandler(menuItem1_Click);
openedSMSmenu.Items.Add(menuItem1);
RadMenuItem menuItem2 = new RadMenuItem(MainForm.returnLNGString("refreshGrid"));
menuItem2.Click += new EventHandler(menuItem2_Click);
openedSMSmenu.Items.Add(menuItem2);
if (e.ContextMenuProvider is GridDataCellElement)
{
e.ContextMenu = openedSMSmenu;
}
}
catch (Exception ex)
{
SM.Debug("Add context menu:" + ex.ToString());
}
}
void menuItem1_Click(object sender, EventArgs e)
{
try
{
Int32 delete_idx = (Int32)gvReports.SelectedRows[0].Cells[6].Value;
regManager.delete_reports(delete_idx.ToString());
}
catch (Exception ex)
{
SM.Debug("EX:" + ex.ToString());
}
try { populateList(); }
catch (Exception ex)
{
SM.Debug("EX:" + ex.ToString());
}
}
void menuItem2_Click(object sender, EventArgs e)
{
try { populateList(); }
catch (Exception ex)
{
SM.Debug("EX:" + ex.ToString());
}
}
private void gvReports_ValueChanged(object sender, EventArgs e)
{
try
{
Int32 update_idx = (Int32)gvReports.SelectedRows[0].Cells[6].Value;
String value = ((Telerik.WinControls.UI.RadDropDownListEditor)(sender)).Value.ToString();
regManager.update_report_user(update_idx.ToString(), value);
}
catch (Exception ex)
{
SM.Debug("EX:" + ex.ToString());
}
}
private void gvReports_CellFormatting(object sender, CellFormattingEventArgs e)
{
GridCellElement cellElement = e.CellElement;
GridViewDataColumn columnInfo = e.CellElement.ColumnInfo as GridViewDataColumn;
if (cellElement == null || columnInfo == null)
return;
if (e.CellElement.ColumnInfo.Name == "unitname" && e.CellElement.Text == "")
{
e.CellElement.Text = MainForm.returnLNGString("allUnits");
}
// do not draw border
cellElement.DrawBorder = false;
// do not highlight the cell on which was clicked
if (e.CellElement.IsCurrent)
{
e.CellElement.IsCurrent = false;
}
}
/// <summary>
/// Change background color for the row according to its state and theme
/// </summary>
private void gvReports_RowFormatting(object sender, RowFormattingEventArgs e)
{
e.RowElement.DrawFill = true;
e.RowElement.NumberOfColors = 1;
if (e.RowElement.IsSelected)
e.RowElement.BackColor = MainForm.GridSelectedRow;
else
e.RowElement.BackColor = (e.RowElement.RowInfo.Index % 2 == 0 ? Color.White : MainForm.GridAlternateRow);
}
}
}