SafeDispatch/SubscriberAndUserManager/controlUnit.cs

1049 lines
41 KiB
C#
Raw 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 Telerik.WinControls.UI;
using System.Collections;
using SafeMobileLib.DBmanagers;
using Telerik.WinControls.Data;
using System.IO;
using Telerik.WinControls.UI.Localization;
namespace SubscriberAndUserManager
{
public partial class controlUnit : UserControl
{
private DBuserManager DBusr;
private DBvehiclesManager DBveh;
private DBiconsManager DBIcons;
public static List<Vehicles> vehs;
public Vehicles selectedVeh;
public EditVehicleParams parms;
private DBgroupsManager DBgrp;
private DBcontactsManager DBcontacts;
private String AssignUnit = "";
private String Toword = "";
public static bool isCheckboxChecked = false;
private void setLanguage()
{
//gbUserForVehicle.Text = MainForm.returnLNGString("assusetounit");
lbVehicleAssignedUsers.Text = MainForm.returnLNGString("assignuser");
AssignUnit = MainForm.returnLNGString("assignuser");
Toword = MainForm.returnLNGString("to");
//Japan
if (MainForm.Langidx == 6) Toword = "";
lbVehicleOtherUsers.Text = MainForm.returnLNGString("unassignuser");
GridViewUnitsList.Columns["Icon"].HeaderText = "";
GridViewUnitsList.Columns["Imei"].HeaderText = MainForm.returnLNGString("radid") + "//" + MainForm.returnLNGString("imei");
GridViewUnitsList.Columns["IntImei"].HeaderText = MainForm.returnLNGString("radid") + "//" + MainForm.returnLNGString("imei");
GridViewUnitsList.Columns["VehName"].HeaderText = MainForm.returnLNGString("name");
GridViewUnitsList.Columns["GpsInterval"].HeaderText = MainForm.returnLNGString("gpsinv");
GridViewUnitsList.Columns["GroupName"].HeaderText = MainForm.returnLNGString("category");
GridViewUnitsList.Columns["gvIsStolen"].HeaderText = MainForm.returnLNGString("stolen");
GridViewUnitsList.Columns["ArsInterval"].HeaderText = MainForm.returnLNGString("arsinv");
GridViewUnitsList.Columns["Email"].HeaderText = MainForm.returnLNGString("u_email");
GridViewUnitsList.Columns["Email"].IsVisible = MainForm.IS_SIERRA_WIRELESS;
GridViewUnitsList.Columns["Phone"].HeaderText = MainForm.returnLNGString("u_phone");
GridViewUnitsList.Columns["Phone"].IsVisible = MainForm.IS_SIERRA_WIRELESS;
GridViewUnitsList.Columns["Active"].HeaderText = MainForm.returnLNGString("active"); ;
radPageUsers.Text = MainForm.returnLNGString("AssignUserstoUnit");
radPageContacts.Text = MainForm.returnLNGString("AssignContactstoUnit");
radPageGroups.Text = MainForm.returnLNGString("AssignGroupstoUnit");
radPageCanBeCalled.Text = MainForm.returnLNGString("CanBeCalledBy");
lbVehicleOtherContacts.Text = MainForm.returnLNGString("UnassignedContacts");
lbVehicleAssignedContacts.Text = MainForm.returnLNGString("AssignedContacts");
lbVehicleOtherGroups.Text = MainForm.returnLNGString("UnassignedGroups");
lbVehicleAssignedGroups.Text = MainForm.returnLNGString("AssignedGroups");
lbVehicleAssignedTo.Text = MainForm.returnLNGString("assAsContact");
lbVehicleUnassignedTo.Text = MainForm.returnLNGString("unassAsContact");
new ToolTip().SetToolTip(radPageAssigned, MainForm.returnLNGString("availablePg"));
}
public controlUnit(DBuserManager DBuser, DBvehiclesManager DBveh, DBgroupsManager DBgrp, DBiconsManager DBIcons, DBcontactsManager DBcontacts)
{
RadGridLocalizationProvider.CurrentProvider = new GridLanguageProvider();
InitializeComponent();
this.DBusr = DBuser;
this.DBveh = DBveh;
this.DBgrp = DBgrp;
this.DBIcons = DBIcons;
this.DBcontacts = DBcontacts;
cbDeletedUnits.Checked = isCheckboxChecked;
cbDeletedUnits.ToggleStateChanged += this.cbDeletedUnits_ToggleStateChanged;
ShowVehs(cbDeletedUnits.Checked);
if (selectedVeh != null)
{
showCurrentUser(selectedVeh);
showOtherUsers(selectedVeh);
if (selectedVeh.Type == (int)DeviceType.SMARTPHONE)
{
showCurrentGroups(selectedVeh);
showOtherGroups(selectedVeh);
showCurrentContacts(selectedVeh);
showOtherContacts(selectedVeh);
ShowWhichContactsCanCallUnit(selectedVeh);
ShowWhichContactsCannotCallUnit(selectedVeh);
}
}
setLanguage();
if ((MainForm.radioType == RADIOTYPE.HARRIS) || (MainForm.radioType == RADIOTYPE.HYT))
{
GridViewUnitsList.TableElement.CellSpacing = -1;
GridViewUnitsList.TableElement.RowSpacing = -1;
if (GridViewUnitsList.Columns.Contains("ArsInterval"))
{
GridViewUnitsList.Columns["ArsInterval"].IsVisible = false;
//GridViewUnitsList.Columns["ArsInterval"].IsVisible = true;
//GridViewUnitsList.Columns["ArsInterval"].Width = 50;
}
}
if ((MainForm.radioType == RADIOTYPE.HARRIS)||(MainForm.radioType == RADIOTYPE.ATLAS))
{
this.lbVehicleAssignedUsers.ForeColor = MainForm.HarTextColor;
this.lbVehicleOtherUsers.ForeColor = MainForm.HarTextColor;
this.gbUserForVehicle.GroupBoxElement.ForeColor = MainForm.HarTextColor;
}
if (MainForm.radioType == RADIOTYPE.SIMOCO)
{
//decide after we see all idea of desing
}
// set the row height
GridViewUnitsList.TableElement.RowHeight = 43;
this.GridViewUnitsList.EnableAlternatingRowColor = true;
this.GridViewUnitsList.TableElement.GridViewElement.TableElement.AlternatingRowColor = Color.LightYellow;
// remove border for grid
this.GridViewUnitsList.GridViewElement.DrawBorder = false;
this.GridViewUnitsList.GridViewElement.GroupPanelElement.DrawBorder = false;
}
public void ShowVehs(Boolean showOnlyDeleted)
{
try
{
Boolean hasOnlyIntegerValues = false;
// find if Sierra Wireless options should be enabled
if (MainForm.IS_SIERRA_WIRELESS)
vehs = DBveh.getAllSierraVehicles(out hasOnlyIntegerValues, MainForm.selectedItemDDSierra, showOnlyDeleted);
else
vehs = DBveh.getAllVehicles(out hasOnlyIntegerValues, showOnlyDeleted);
GridViewUnitsList.Columns["Imei"].IsVisible = !hasOnlyIntegerValues;
GridViewUnitsList.Columns["IntImei"].IsVisible = hasOnlyIntegerValues;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("dberr"), MainForm.returnLNGString("err"));
return;
}
MainForm.VehNameList.Clear();
MainForm.ImeiList.Clear();
GridViewUnitsList.DataSource = vehs;
foreach (Vehicles obj in vehs)
{
MainForm.VehNameList.Add(obj.VehName);
MainForm.ImeiList.Add(obj.Imei);
}
if (vehs.Count > 0)
selectedVeh = vehs[0];
//car icons
MainForm.imgList = DBveh.get_all_car_picture();
int count = 0;
foreach (Vehicles veh in vehs)
{
try
{
// add the car to the dictionary if not exists
if (!MainForm.carImages.ContainsKey(veh.ImgID))
MainForm.GetCustomIcon(veh.ImgID);
// set the icon for the grid
GridViewUnitsList.Rows[count].Cells["Icon"].Value = MainForm.carImages[veh.ImgID];
}
catch (Exception ex)
{
Utils.WriteLine("\nBmp " + veh.ImgID + " exception " + ex.ToString(), ConsoleColor.Red);
}
try
{
if (veh.IsStolen == 0)
{
GridViewUnitsList.Rows[count].Cells["gvIsStolen"].Value = MainForm.returnLNGString("no");
}
else
{
GridViewUnitsList.Rows[count].Cells["gvIsStolen"].Value = MainForm.returnLNGString("yes");
}
}
catch (Exception ex)
{
Utils.WriteLine("ex.ToString(): " + ex.ToString(), ConsoleColor.Red);
}
count++;
}
if (vehs.Count == 0)
radPageContacts.Item.Visibility = radPageGroups.Item.Visibility = radPageCanBeCalled.Item.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
}
#region VEHICLE GROUP RELATION
private void showCurrentGroups(Vehicles veh)
{
listBoxCurrentGroups.DataSource = null;
if (veh != null)
{
try
{
List<Group> grpList = DBgrp.getAllGroupsForCurrentUnit(veh.Id.ToString());
listBoxCurrentGroups.DataSource = grpList;
listBoxCurrentGroups.DisplayMember = "Name";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
private void showOtherGroups(Vehicles veh)
{
listBoxOtherGroups.DataSource = null;
if (veh != null)
{
try
{
List<Group> grpList = DBgrp.getAllOtherGroupsForCurrentUnit(veh.Id.ToString());
listBoxOtherGroups.DataSource = grpList;
listBoxOtherGroups.DisplayMember = "Name";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
private void btnRemoveGroupFromVehicle_Click(object sender, EventArgs e)
{
foreach (RadListDataItem tmp in listBoxCurrentGroups.SelectedItems)
{
Group grpSelected = (Group)tmp.Value;
DBgrp.removeVehicleGroupConnection(selectedVeh.Id.ToString(), grpSelected.Id.ToString());
}
showCurrentGroups(selectedVeh);
showOtherGroups(selectedVeh);
((MainForm)this.Parent.Parent).setVisibleSipRestartNotification();
}
private void btnAddGroupToVehicle_Click(object sender, EventArgs e)
{
foreach (RadListDataItem tmp in listBoxOtherGroups.SelectedItems)
{
Group grpSelected = (Group)tmp.Value;
DBgrp.addVehicleGroupConnection(selectedVeh.Id.ToString(), grpSelected.Id.ToString());
}
showCurrentGroups(selectedVeh);
showOtherGroups(selectedVeh);
((MainForm)this.Parent.Parent).setVisibleSipRestartNotification();
}
private void listBoxCurrentGroups_MouseDoubleClick(object sender, MouseEventArgs e)
{
RadListVisualItem clickedItem = listBoxCurrentGroups.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
if (clickedItem != null)
{
RadListDataItem dataItem = clickedItem.Data;
btnRemoveGroupFromVehicle.PerformClick();
}
}
private void listBoxOtherGroups_MouseDoubleClick(object sender, MouseEventArgs e)
{
RadListVisualItem clickedItem = listBoxOtherGroups.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
if (clickedItem != null)
{
RadListDataItem dataItem = clickedItem.Data;
btnAddGroupToVehicle.PerformClick();
}
}
private void listBoxGroups_ItemDataBound(object sender, ListItemDataBoundEventArgs args)
{
Group view = (Group)args.NewItem.DataBoundItem;
args.NewItem.Text = "<html>" +
"<b>" + view.Name + "</b>";
args.NewItem.Image = groupImage;
}
#endregion
#region VEHICLE CONTACTS RELATION
private void showCurrentContacts(Vehicles veh)
{
listBoxCurrentContacts.DataSource = null;
if (veh != null)
{
try
{
List<ContactLinx> contactsList = DBcontacts.getAllContactsForCurrentUnit(veh.Id.ToString());
listBoxCurrentContacts.DataSource = contactsList;
listBoxCurrentContacts.DisplayMember = "Name";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
private void showOtherContacts(Vehicles veh)
{
listBoxOtherContacts.DataSource = null;
if (veh != null)
{
try
{
List<ContactLinx> contactsList = DBcontacts.getAllOtherContactsForCurrentUnit(veh.Id.ToString());
listBoxOtherContacts.DataSource = contactsList;
listBoxOtherContacts.DisplayMember = "Name";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
private void ShowWhichContactsCanCallUnit(Vehicles veh)
{
listBoxAssignedAsContactsTo.DataSource = null;
if (veh != null)
{
try
{
List<ContactLinx> assignedascontactTo = DBcontacts.getAllContactsCanCallUnit(veh.Id.ToString());
listBoxAssignedAsContactsTo.DataSource = assignedascontactTo;
listBoxAssignedAsContactsTo.DisplayMember = "Name";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
private void ShowWhichContactsCannotCallUnit(Vehicles veh)
{
listBoxUnssignedAsContactsTo.DataSource = null;
if (veh != null)
{
try
{
List<ContactLinx> unassignedascontactTo = DBcontacts.getAllContactsCannotCallUnit(veh.Id.ToString());
listBoxUnssignedAsContactsTo.DataSource = unassignedascontactTo;
listBoxUnssignedAsContactsTo.DisplayMember = "Name";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
private void btnRemoveContactFromVehicle_Click(object sender, EventArgs e)
{
List<ContactLinx> contacts = new List<ContactLinx>();
foreach (RadListDataItem tmp in listBoxCurrentContacts.SelectedItems)
{
contacts.Add((ContactLinx)tmp.Value);
}
DBcontacts.removeVehicleContactConnection(selectedVeh.Id.ToString(), contacts);
showCurrentContacts(selectedVeh);
showOtherContacts(selectedVeh);
((MainForm)this.Parent.Parent).setVisibleReloadNotification();
}
private void btnAddContactToVehicle_Click(object sender, EventArgs e)
{
List<ContactLinx> contacts = new List<ContactLinx>();
foreach (RadListDataItem tmp in listBoxOtherContacts.SelectedItems)
{
contacts.Add((ContactLinx)tmp.Value);
}
DBcontacts.addVehicleContactConnection(selectedVeh.Id.ToString(), contacts);
showCurrentContacts(selectedVeh);
showOtherContacts(selectedVeh);
((MainForm)this.Parent.Parent).setVisibleReloadNotification();
}
private void listBoxCurrentContact_MouseDoubleClick(object sender, MouseEventArgs e)
{
RadListVisualItem clickedItem = listBoxCurrentContacts.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
if (clickedItem != null)
{
RadListDataItem dataItem = clickedItem.Data;
btnRemoveContactFromVehicle.PerformClick();
}
}
private void listBoxOtherContact_MouseDoubleClick(object sender, MouseEventArgs e)
{
RadListVisualItem clickedItem = listBoxOtherContacts.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
if (clickedItem != null)
{
RadListDataItem dataItem = clickedItem.Data;
btnAddContactToVehicle.PerformClick();
}
}
//brainfuck
private void btnRemoveVehicleAsContact_Click(object sender, EventArgs e)
{
List<ContactLinx> contacts = new List<ContactLinx>();
foreach (RadListDataItem tmp in listBoxAssignedAsContactsTo.SelectedItems)
{
contacts.Add((ContactLinx)tmp.Value);
}
DBcontacts.removeContactVehicleConnection(selectedVeh.Id.ToString(), contacts);
ShowWhichContactsCanCallUnit(selectedVeh);
ShowWhichContactsCannotCallUnit(selectedVeh);
((MainForm)this.Parent.Parent).setVisibleReloadNotification();
}
private void btnAddVehicleAsContact_Click(object sender, EventArgs e)
{
List<ContactLinx> contacts = new List<ContactLinx>();
foreach (RadListDataItem tmp in listBoxUnssignedAsContactsTo.SelectedItems)
{
contacts.Add((ContactLinx)tmp.Value);
}
DBcontacts.addContactVehicleConnection(selectedVeh.Id.ToString(), contacts);
ShowWhichContactsCanCallUnit(selectedVeh);
ShowWhichContactsCannotCallUnit(selectedVeh);
((MainForm)this.Parent.Parent).setVisibleReloadNotification();
}
private void listBoxAssignedAsContactsTo_MouseDoubleClick(object sender, MouseEventArgs e)
{
RadListVisualItem clickedItem = listBoxAssignedAsContactsTo.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
if (clickedItem != null)
{
RadListDataItem dataItem = clickedItem.Data;
btnRemoveVehicleAsContact.PerformClick();
}
}
private void listBoxUnssignedAsContactsTo_MouseDoubleClick(object sender, MouseEventArgs e)
{
RadListVisualItem clickedItem = listBoxUnssignedAsContactsTo.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
if (clickedItem != null)
{
RadListDataItem dataItem = clickedItem.Data;
btnAddVehicleAsContact.PerformClick();
}
}
private void listBoxContacts_ItemDataBound(object sender, ListItemDataBoundEventArgs args)
{
ContactLinx view = (ContactLinx)args.NewItem.DataBoundItem;
args.NewItem.Text = "<html>" +
"<b>" + view.Name + "</b>" +
"<br>" + "<i>" +
" " + view.Type + " " + "</i>";
switch (view.Type)
{
case ContactType.GROUP:
args.NewItem.Image = groupImage;
break;
case ContactType.USER:
args.NewItem.Image = dispatcherImage;
break;
case ContactType.UNIT:
if (MainForm.carImages.ContainsKey(view.ImageID))
args.NewItem.Image = MainForm.carImages[view.ImageID];
break;
}
}
#endregion
private void btnAddVehicle_Click(object sender, EventArgs e)
{
if (GridViewUnitsList.SelectedRows.Count > 0)
{
foreach (GridViewRowInfo item in GridViewUnitsList.SelectedRows)
{
String vehID = item.Cells["Id"].Value.ToString();
foreach (RadListDataItem tmp in listBoxOtherUsers.SelectedItems)
{
User userSelected = (User)tmp.Value;
DBveh.addVehicleUserConnection(vehID, userSelected.Id.ToString());
}
}
showCurrentUser(selectedVeh);
showOtherUsers(selectedVeh);
}
}
private void btnRemoveVehicle_Click(object sender, EventArgs e)
{
if (GridViewUnitsList.SelectedRows.Count > 0)
{
foreach (GridViewRowInfo item in GridViewUnitsList.SelectedRows)
{
String vehID = item.Cells["Id"].Value.ToString();
foreach (RadListDataItem tmp in listBoxCurrentUsers.SelectedItems)
{
User userSelected = (User)tmp.Value;
DBveh.removeVehicleUserConnection(vehID, userSelected.Id.ToString());
}
}
showCurrentUser(selectedVeh);
showOtherUsers(selectedVeh);
}
}
//show current users for vehicle
private void showCurrentUser(Vehicles veh)
{
if (veh != null)
{
try
{
List<User> usrlIST = DBusr.getAllUsersForCurrentVehicle(veh.Id.ToString());
List<DataRowView> rowviewUsers = new List<DataRowView>();
listBoxCurrentUsers.DataSource = usrlIST;
listBoxCurrentUsers.DisplayMember = "UserName";
lbVehicleAssignedUsers.Text = AssignUnit + " "+Toword+"\n" + veh.VehName;
/*if ((MainForm.culture.Name.StartsWith("en")))
lbVehicleAssignedUsers.Text = AssignUnit + " to " + veh.VehName;
else lbVehicleAssignedUsers.Text = AssignUnit + " " + veh.VehName;*/
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
//show other users
private void showOtherUsers(Vehicles veh)
{
if (veh != null)
{
try
{
List<User> usrlIST = DBusr.getAllOtherUsersForCurrentVehicle(veh.Id.ToString());
listBoxOtherUsers.DataSource = usrlIST;
listBoxOtherUsers.DisplayMember = "UserName";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
private void GridViewUnitsList_CellClick(object sender, GridViewCellEventArgs e)
{
if (e.RowIndex > -1)
{
selectedVeh = (Vehicles)vehs[e.RowIndex];
//add current vehicles for user
showCurrentUser(selectedVeh);
//add vehicles that ar not asigned
showOtherUsers(selectedVeh);
//if(selectedVeh.Type == (int)DeviceType.MOBILE)
//{
// showCurrentGroups(selectedVeh);
// showOtherGroups(selectedVeh);
// showCurrentContacts(selectedVeh);
// showOtherContacts(selectedVeh);
//}
}
}
private void gbUserForVehicle_Resize(object sender, EventArgs e)
{
//listBoxCurrentUsers.MaximumSize = new Size(gbUserForVehicle.Height/2 - 20, 0);
}
private void GridViewUnitsList_CellFormatting(object sender, CellFormattingEventArgs e)
{
/*
if (MainForm.radioType==RADIOTYPE.HYT)
{
e.CellElement.DrawBorder = true;
e.CellElement.BorderColor = Color.FromArgb(255, 207, 207, 207);
e.CellElement.BorderGradientStyle = Telerik.WinControls.GradientStyles.Solid;
e.CellElement.BorderBoxStyle = Telerik.WinControls.BorderBoxStyle.SingleBorder;
}*/
GridCellElement cellElement = e.CellElement;
GridViewDataColumn columnInfo = e.CellElement.ColumnInfo as GridViewDataColumn;
if (cellElement == null || columnInfo == null)
return;
// do not draw border
cellElement.DrawBorder = false;
// do not highlight the cell on which was clicked
if (e.CellElement.IsCurrent)
{
e.CellElement.IsCurrent = false;
}
if (e.CellElement.ColumnInfo.Name == "VehName")
{
cellElement.DrawText = true;
Font font3 = new Font(
"Segoe UI",
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
cellElement.ForeColor = Color.FromArgb(0, 0, 0);
cellElement.Font = font3;
}
else if (e.CellElement.ColumnInfo.Name == "gvIsStolen")
{
cellElement.DrawText = true;
Font fontStolen = new Font(
cellElement.Font.FontFamily,
11,
FontStyle.Bold,
GraphicsUnit.Pixel);
Font fontNotStole = new Font(
cellElement.Font.FontFamily,
11,
FontStyle.Regular,
GraphicsUnit.Pixel);
if (e.CellElement.Text.Equals("YES") || e.CellElement.Text.Equals(MainForm.returnLNGString("yes")))
{
cellElement.ForeColor = Color.FromArgb(212, 35, 40);
cellElement.Font = fontStolen;
cellElement.Text = MainForm.returnLNGString("yes");
}
else
{
cellElement.ForeColor = Color.FromArgb(0x66, 0x66, 0x66);
cellElement.Font = fontNotStole;
cellElement.Text = MainForm.returnLNGString("no");
}
}
else if (e.CellElement.ColumnInfo.Name == "Active")
{
cellElement.DrawText = true;
if (cellElement.Text == null)
return;
if(cellElement.Text.Equals("TRUE") || cellElement.Text.Equals(MainForm.returnLNGString("true")))
{
cellElement.Text = MainForm.returnLNGString("true");
}
else
{
cellElement.Text = MainForm.returnLNGString("false");
}
}
if (e.CellElement.ColumnInfo.Name == "Icon")
cellElement.Padding = new Padding(2, 0, 2, 0);
else
cellElement.Padding = new Padding(10, 0, 10, 0);
}
private void GridViewUnitsList_SelectionChanged(object sender, EventArgs e)
{
if (GridViewUnitsList.SelectedRows.Count > 1)
{
parms.imeiList = "";
parms.IdList = "";
parms.vehicleList = "";
List<string> checkIcon = new List<string>();
List<string> checkGroup = new List<string>();
List<string> checkGpsInterval = new List<string>();
List<string> ActiveList = new List<string>();
List<string> TypeList = new List<string>();
parms.Group = "";
parms.GpsInterval = "";
foreach (GridViewRowInfo item in GridViewUnitsList.SelectedRows)
{
parms.imeiList += string.Format("'{0}',", item.Cells["Imei"].Value.ToString());
parms.IdList += string.Format("{0},", item.Cells["Id"].Value.ToString());
parms.vehicleList += string.Format("{0},", item.Cells["VehName"].Value.ToString());
checkGroup.Add(item.Cells["GroupName"].Value.ToString());
checkGpsInterval.Add(item.Cells["GpsInterval"].Value.ToString());
checkIcon.Add(item.Cells["ImgID"].Value.ToString());
ActiveList.Add(item.Cells["Active"].Value.ToString());
TypeList.Add(item.Cells["Type"].Value.ToString());
}
parms.Group = (checkGroup.Distinct().Count() > 1) ? MainForm.returnLNGString("multiple") : checkGroup[0];
parms.GpsInterval = (checkGpsInterval.Distinct().Count() > 1) ? "0" : checkGpsInterval[0];
parms.Icon = (checkIcon.Distinct().Count() > 1) ? MainForm.returnLNGString("multiple") : checkIcon[0];
parms.ActiveList = (ActiveList.Distinct().Count() > 1) ? MainForm.returnLNGString("multiple") : ActiveList[0];
parms.TypeList = (TypeList.Distinct().Count() > 1) ? MainForm.returnLNGString("multiple") : TypeList[0];
parms.imeiList = string.Format("({0})", parms.imeiList.Substring(0, parms.imeiList.Length - 1));
parms.IdList = string.Format("({0})", parms.IdList.Substring(0, parms.IdList.Length - 1));
parms.vehicleList = parms.vehicleList.Substring(0, parms.vehicleList.Length - 1);
radPageContacts.Item.Visibility = radPageGroups.Item.Visibility = radPageCanBeCalled.Item.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
}
else
{
if ((((RadGridView)sender).SelectedRows).Count() > 0)
{
radPageContacts.Item.Visibility = radPageGroups.Item.Visibility =
radPageCanBeCalled.Item.Visibility = ((Vehicles)((RadGridView)sender).SelectedRows[0].DataBoundItem).Type == 1 ?
Telerik.WinControls.ElementVisibility.Visible :
Telerik.WinControls.ElementVisibility.Collapsed;
//add current vehicles for user
selectedVeh = ((Vehicles)((RadGridView)sender).SelectedRows[0].DataBoundItem);
}
if (selectedVeh != null)
{
showCurrentUser(selectedVeh);
//add vehicles that ar not asigned
showOtherUsers(selectedVeh);
if (selectedVeh.Type == (int)DeviceType.SMARTPHONE)
{
showCurrentGroups(selectedVeh);
showOtherGroups(selectedVeh);
showCurrentContacts(selectedVeh);
showOtherContacts(selectedVeh);
ShowWhichContactsCanCallUnit(selectedVeh);
ShowWhichContactsCannotCallUnit(selectedVeh);
}
}
}
//radPageAssigned.SelectedPage = radPageUsers;
}
/// <summary>
/// Change background color for the row according to its state and theme
/// </summary>
private void GridViewUnitsList_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);
}
private Image themeGroupDisabled = Utils.MakeGrayscale3(SubscriberAndUserManager.Properties.Resources.l_user_n, 0.7f);
private Image themeGroupTheme = Utils.ChangeColor(SubscriberAndUserManager.Properties.Resources.l_user_n, MainForm.ButtonColor);
/// <summary>
/// Event Handler for when a filter picture box is clicked
/// This should group the grid based on its status
/// </summary>
private void pbFilter_Click(object sender, EventArgs e)
{
if ((PictureBox)sender == pbGroup)
{
// add the groupname grouping option
if (pbGroup.Tag.Equals("disabled"))
{
pbGroup.Image = themeGroupTheme;
pbGroup.Tag = "enabled";
// clear previous filters and add the new one
GridViewUnitsList.GroupDescriptors.Clear();
GroupDescriptor groupDescriptor = new GroupDescriptor(new SortDescriptor[] { new SortDescriptor("GroupName", ListSortDirection.Ascending) });
GridViewUnitsList.GroupDescriptors.Add(groupDescriptor);
}
else
{
GroupDescriptor gd = GridViewUnitsList.GroupDescriptors[0];
// if the new sort direction should be back ASC I will remove the filters
if (gd.Expression.Contains("DESC"))
{
// clear previous filters=
GridViewUnitsList.GroupDescriptors.Clear();
pbGroup.Image = themeGroupDisabled;
pbGroup.Tag = "disabled";
}
else
{
// clear previous filters and add the new one
GridViewUnitsList.GroupDescriptors.Clear();
GroupDescriptor groupDescriptor = new GroupDescriptor(new SortDescriptor[] { new SortDescriptor("GroupName", ListSortDirection.Descending) });
GridViewUnitsList.GroupDescriptors.Add(groupDescriptor);
}
}
// expand all groups
foreach (DataGroup group in this.GridViewUnitsList.Groups)
group.Expand();
}
}
/// <summary>
/// remove the group indent in the left
/// </summary>
private void GridViewUnitsList_CreateCell(object sender, GridViewCreateCellEventArgs e)
{
// format live column
if (e.Row is GridDataRowElement)
{
if (e.Column is GridViewIndentColumn)
{
e.Column.IsVisible = false;
}
}
}
/// <summary>
/// Format the group name when the grid is grouped by 'Group Name'
/// </summary>
private void GridViewUnitsList_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
{
try
{
// remove the filter name
if (e.FormatString.Contains(":"))
{
e.FormatString = e.FormatString.Replace("{0}:", "");
// check if units have or not a group assigned
if (e.FormatString.Trim().Length != 0)
e.FormatString = "GROUP " + e.FormatString;
else
e.FormatString = "NOT ASSIGNED TO ANY GROUP";
}
}
catch (Exception) { }
}
/// <summary>
/// Format the Group Header font and fore color
/// </summary>
private void GridViewUnitsList_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
if (e.CellElement is GridGroupContentCellElement)
{
e.CellElement.Font = new Font("Segoe UI",
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
e.CellElement.ForeColor = Color.FromArgb(0x66, 0x66, 0x66);
}
}
private Image dispatcherImage = Utils.ScaleImage(SubscriberAndUserManager.Properties.Resources.i_dispatch, 32, 32);
private Image groupImage = Utils.ScaleImage(SubscriberAndUserManager.Properties.Resources.i_group, 32, 32);
private Image adminImage = Utils.ScaleImage(SubscriberAndUserManager.Properties.Resources.i_admin, 32, 32);
private void listBoxCurrentUsers_ItemDataBound(object sender, ListItemDataBoundEventArgs args)
{
User view = (User)args.NewItem.DataBoundItem;
args.NewItem.Text = "<html>" +
"<b>" + view.UserName + "</b>" +
"<br>" + "<i>" +
" " + view.FirstName +
" " + view.Lastname + "</i>";
if (view.UType == USERTYPE.Dispatcher)
args.NewItem.Image = dispatcherImage;
else
args.NewItem.Image = adminImage;
}
private void listBoxCurrentUsers_CreatingVisualListItem(object sender, CreatingVisualListItemEventArgs args)
{
RadListVisualItem visualItem = new RadListVisualItem();
visualItem.Padding = new Padding(5, 5, 0, 5);
args.VisualItem = visualItem;
}
/// <summary>
/// Remove a user to the list when double click on a user
/// </summary>
private void listBoxCurrentUsers_MouseDoubleClick(object sender, MouseEventArgs e)
{
RadListVisualItem clickedItem = listBoxCurrentUsers.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
if (clickedItem != null)
{
RadListDataItem dataItem = clickedItem.Data;
btnRemoveUserFromVehicle.PerformClick();
}
}
/// <summary>
/// Add a user to the list when double click on a user
/// </summary>
private void listBoxOtherUsers_MouseDoubleClick(object sender, MouseEventArgs e)
{
RadListVisualItem clickedItem = listBoxOtherUsers.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
if (clickedItem != null)
{
RadListDataItem dataItem = clickedItem.Data;
btnAddUserToVehicle.PerformClick();
}
}
private void listBox_VisualItemFormatting(object sender, VisualItemFormattingEventArgs e)
{
e.VisualItem.DrawFill = true;
e.VisualItem.NumberOfColors = 1;
if (e.VisualItem.Selected)
e.VisualItem.BackColor = MainForm.GridSelectedRow;
else
e.VisualItem.BackColor = Color.White;
}
private void GridViewUnitsList_CellDoubleClick(object sender, GridViewCellEventArgs e)
{
((MainForm)this.Parent.Parent).btnUnitEdit.PerformClick();
}
internal void RefreshGrid(Vehicles veh)
{
try
{
GridViewUnitsList.Rows[0].IsSelected = false;
this.selectedVeh = veh;
int rowid = GetGridIndex(veh);
if (GridViewUnitsList.Rows.Count >= rowid)
{
GridViewUnitsList.Rows[rowid].IsSelected = true;
GridViewUnitsList.TableElement.ScrollToRow(rowid);
if (selectedVeh != null)
{
showCurrentUser(selectedVeh);
showOtherUsers(selectedVeh);
if (selectedVeh.Type == (int)DeviceType.SMARTPHONE)
{
showCurrentGroups(selectedVeh);
showOtherGroups(selectedVeh);
showCurrentContacts(selectedVeh);
showOtherContacts(selectedVeh);
ShowWhichContactsCanCallUnit(selectedVeh);
ShowWhichContactsCannotCallUnit(selectedVeh);
}
}
}
}
catch
{ }
}
private int GetGridIndex(Vehicles veh)
{
int counter = 0;
foreach (var item in GridViewUnitsList.Rows)
{
if (((Vehicles)item.DataBoundItem).Id == veh.Id)
return counter;
counter++;
}
return counter;
}
private void cbDeletedUnits_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
isCheckboxChecked = cbDeletedUnits.Checked;
ShowVehs(cbDeletedUnits.Checked);
}
}
public struct EditVehicleParams
{
public string imeiList;
public string IdList;
public string vehicleList;
public string Group;
public string GpsInterval;
public string Icon;
public string ActiveList;
public string TypeList;
}
}