SafeDispatch/SubscriberAndUserManager/GroupsForm.cs

979 lines
44 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using SafeMobileLib;
using Telerik.WinControls.UI;
using System.Linq;
namespace SubscriberAndUserManager
{
public partial class GroupsForm : Telerik.WinControls.UI.RadForm
{
private DBgroupsManager DBgrp;
private DBgatewaysManager DBgateways;
private DBcontactsManager DBcontact = new DBcontactsManager(MainForm.DBServer, MainForm.DBSchema, MainForm.DBUser, MainForm.DBPass, MainForm.DBPort);
private List<Group> grps;
private string action;
private controlUnit parent;
List<RadioGateway> radioGWList;
public static GroupsForm Instance;
private void setLanguage(String action)
{
//switch (action)
//{
// case "add":
// this.Text = MainForm.returnLNGString("addnewgrp");
// lbGroupName.Text = MainForm.returnLNGString("newgrp") + ":";
// lbGroupType.Text = MainForm.returnLNGString("grpType") + ":";
// btnSave.Text = MainForm.returnLNGString("addgrp");
// break;
// case "edit":
// this.Text = MainForm.returnLNGString("editgrp");
// lbGroupName.Text = MainForm.returnLNGString("editgrpname") + ":";
// cbGroupType.Enabled = false;
// btnSave.Text = MainForm.returnLNGString("editgrp");
// break;
// case "delete":
// this.Text = MainForm.returnLNGString("delgrp");
// tbGroupName.Enabled = false;
// cbGroupType.Enabled = false;
// cbGatewayAndRadioGW.Enabled = false;
// lbGroupName.Text = MainForm.returnLNGString("grpname") + ":";
// btnSave.Text = MainForm.returnLNGString("delgrp");
// break;
//}
this.Text = MainForm.returnLNGString("lbGrp");
lbGroupName.Text = MainForm.returnLNGString("name") + ":";
cbGroupType.Enabled = false;
btnSave.Text = MainForm.returnLNGString("save");
btnExit.Text = MainForm.returnLNGString("exit");
lbGroups.Text = MainForm.returnLNGString("lbGrp");
lbGroupType.Text = MainForm.returnLNGString("grpType");
lbAssignedMembers.Text = MainForm.returnLNGString("assignmembers");
lbUnassignedMembers.Text = MainForm.returnLNGString("unassignmembers");
lbGWandRGW.Text = MainForm.returnLNGString("GWAndRadioGW");
GridViewGroupsList.Columns["Name"].HeaderText = MainForm.returnLNGString("name");
GridViewGroupsList.Columns["Type"].HeaderText = MainForm.returnLNGString("type");
GridViewGroupsList.Columns["CPS_Id"].HeaderText = MainForm.returnLNGString("id");
GridViewGroupsList.Columns["GatewayName"].HeaderText = MainForm.returnLNGString("gatewayName");
GridViewGroupsList.Columns["Id"].HeaderText = MainForm.returnLNGString("id");
GridViewGroupsList.Columns["RgwID"].HeaderText = MainForm.returnLNGString("rgwID");
radPageMembers.Text = MainForm.returnLNGString("members");
setGroupTypeLanguageValues();
}
public static GroupsForm GetSingleton(controlUnit _parent, DBgroupsManager DBgrp, DBgatewaysManager DBgw, string action)
{
if (Instance == null)
Instance = new GroupsForm(_parent, DBgrp, DBgw, action);
else
{
if (Instance.IsDisposed)
Instance = new GroupsForm(_parent, DBgrp, DBgw, action);
}
return Instance;
}
private void setGroupTypeLanguageValues()
{
GroupType.SetCategoryLanguageName(MainForm.returnLNGString("category"));
GroupType.SetMobileTalkLanguageName(MainForm.returnLNGString("mobiletalk"));
GroupType.SetRadioTalkLanguageName(MainForm.returnLNGString("radiotalk"));
}
public GroupsForm(controlUnit _parent, DBgroupsManager DBgrp, DBgatewaysManager DBgw, string action)
{
this.parent = _parent;
this.DBgrp = DBgrp;
this.DBgateways = DBgw;
this.action = action;
InitializeComponent();
setGroupTypeLanguageValues();
cbGroupType.Items.Add(GroupType.CATEGORY.displayedName);
//if(MainForm.radioType != RADIOTYPE.SIMOCO)
radioGWList = DBgateways.gelAllGatewaysAndRadioGateways();
if (!MainForm.hideLinxFeatures && radioGWList.Where(x => x.Type == (int)GatewayType.Broadband).Count() > 0)
cbGroupType.Items.Add(GroupType.MOBILETALK.displayedName);
if (radioGWList.Where(x => x.Type == (int)GatewayType.Tier2Radio || x.Type == (int)GatewayType.Tier3Radio
|| x.Type == (int)GatewayType.SMCBridge).Count() > 0)
cbGroupType.Items.Add(GroupType.RADIOTALK.displayedName);
cbGroupType.SelectedIndex = 0;
ShowGroups();
setLanguage(action);
switch (MainForm.radioType)
{
case RADIOTYPE.CONECTPLUS:
case RADIOTYPE.LISF:
cbGroupType.Items.RemoveAt(1);
break;
case RADIOTYPE.TETRA:
case RADIOTYPE.REPEATER_TRBO:
//case RADIOTYPE.MOTO:
txCPS.Visible = false;
lbCps.Visible = false;
//tbGroupName.Size = new Size(247, tbGroupName.Size.Height);
break;
case RADIOTYPE.HYT:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.SYTADMIN24x;
this.BackColor = MainForm.HyteraColor;
break;
case RADIOTYPE.HARRIS:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.visionSmall;
this.BackColor = MainForm.HarrisColor;
this.lbCps.ForeColor = MainForm.HarTextColor;
this.lbGroupName.ForeColor = MainForm.HarTextColor;
this.lbGroups.ForeColor = MainForm.HarTextColor;
break;
case RADIOTYPE.ATLAS:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.ATLASadmin32; //ATLASCHANGE
this.BackColor = MainForm.HarrisColor;
this.lbCps.ForeColor = MainForm.HarTextColor;
this.lbGroupName.ForeColor = MainForm.HarTextColor;
this.lbGroups.ForeColor = MainForm.HarTextColor;
break;
case RADIOTYPE.SIMOCO:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.simoco_setup_241;
break;
case RADIOTYPE.EXCERA:
this.Icon = global::SubscriberAndUserManager.Properties.Resources.AXYS_ICON;
break;
}
this.Width = 393;
lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = (MainForm.radioType != RADIOTYPE.SIMOCO && MainForm.radioType != RADIOTYPE.EXCERA);
if (cbGroupType.Text.Equals((GroupType.CATEGORY.displayedName)))
{
lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = lbCps.Visible = txCPS.Visible = false;
txCPS.Value = 0;
}
//radioGWList = DBgateways.gelAllGatewaysAndRadioGateways();
//cbGatewayAndRadioGW.DataSource = radioGWList;
//cbGatewayAndRadioGW.DisplayMember = "name";
//if (cbGroupType.Text != GroupType.CATEGORY.ToString())
//{
// Int32 rgwid = ((Group)((RadListDataItem)listBoxGroups.SelectedItems[0]).Value).RgwID;
// if (radioGWList != null)
// {
// RadioGateway rg = radioGWList.Where(x => x.Id == rgwid).FirstOrDefault();
// cbGatewayAndRadioGW.SelectedValue = rg;
// lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = true;
// }
//}
//else
//{
// cbGatewayAndRadioGW.SelectedIndex = 0;
// lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = false;
//}
//listBoxGroups_SelectedIndexChanged(null, null);
GridViewGroupsList_SelectionChanged(null, null);
}
//groups
private void ShowGroups()
{
grps = DBgrp.GetAllGroups();
if (grps != null)
{
GridViewGroupsList.DataSource = grps;
//listBoxGroups.DataSource = grps;
//listBoxGroups.DisplayMember = "Name";
if (grps.Count() == 0)
EmptyFields();
groupBox1.Enabled = grps.Count() > 0;
}
}
private void setGatewayDropDown()
{
if(!cbGroupType.Text.Equals(GroupType.CATEGORY.displayedName)
&& action != "edit" )
{
txCPS.Value = 1;
}
if (!cbGroupType.Text.Equals(GroupType.MOBILETALK.displayedName))
{
cbGatewayAndRadioGW.Enabled = true;
return;
}
int count = 0;
foreach (var item in cbGatewayAndRadioGW.Items)
{
if (((RadioGateway)((RadListDataItem)item).Value).Type == (int)GatewayType.Broadband)
{
cbGatewayAndRadioGW.SelectedIndex = count;
cbGatewayAndRadioGW.Enabled = false;
}
count++;
}
}
private void AddNewGroup()
{
//foreach (RadListDataItem rdl in listBoxGroups.Items)
//{
// if ((int)txCPS.Value == ((Group)rdl.Value).CPS_Id && cbGroupType.Text != GroupType.CATEGORY.ToString())
// {
// CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("IDalreadyDefined"), MainForm.returnLNGString("err"));
// return;
// }
//}
sqlResponse resp;
string grpName = tbGroupName.Text;
if (grpName != "")
{
//int sipid = (Int32)txCPS.Value;
//if (DBcontact.isSipDuplicate(sipid) && cbGroupType.Text != GroupType.CATEGORY.ToString())
//{
// CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("IdAlreadyUsed"), MainForm.returnLNGString("err"));
// return;
//}
//if ((MainForm.radioType != RADIOTYPE.MOTO) && (MainForm.radioType != RADIOTYPE.ATLAS) && (MainForm.radioType != RADIOTYPE.TETRA) && (MainForm.radioType != RADIOTYPE.CONECTPLUS)) DBgrp.AddNewGroup(grpName, (Int32)txCPS.Value);
Int32 grpType = (GroupType.FromDisplayedName(cbGroupType.Text)).value;
Int32 rgwID = 0;
if (cbGatewayAndRadioGW.SelectedItems.Count > 0)
rgwID = ((RadioGateway)((RadListDataItem)cbGatewayAndRadioGW.SelectedItems[0]).Value).Id;
if ((MainForm.radioType != RADIOTYPE.ATLAS) && (MainForm.radioType != RADIOTYPE.CONECTPLUS) && (MainForm.radioType != RADIOTYPE.REPEATER_TRBO))
DBgrp.AddNewGroup(grpName, (Int32)txCPS.Value, grpType, rgwID, out resp);
else
DBgrp.AddNewGroup(grpName, 1, grpType, rgwID, out resp);
HandleResp(resp);
//MainForm.CallWebServer(MainForm.RestartSipLink);
}
else
{
//RadMessageBox.Show("Group name empty!!1one");
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("grpnameemt"), MainForm.returnLNGString("err"));
}
//ShowGroups();
}
private void EditGroupName()
{
if (GridViewGroupsList.SelectedRows != null)
{
if (GridViewGroupsList.SelectedRows.Count > 0)
{
//foreach (RadListDataItem rdl in listBoxGroups.Items)
//{
// if ((int)txCPS.Value == ((Group)rdl.Value).CPS_Id && txID.Text != ((Group)rdl.Value).Id.ToString() && cbGroupType.Text != GroupType.CATEGORY.ToString())
// {
// CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("IDalreadyDefined"), MainForm.returnLNGString("err"));
// return;
// }
//}
//int grpID = ((Group)((RadListDataItem)listBoxGroups.SelectedItems[0]).Value).Id;//((Group)listBoxGroups.SelectedValue).Id;
int grpID = (int)GridViewGroupsList.SelectedRows[0].Cells["Id"].Value;
string grpName = tbGroupName.Text;
Int32 cps_id = 1;
try
{
cps_id = Convert.ToInt32(txCPS.Text);
}
catch (Exception ex)
{
SM.Debug("Error on convert cps_id:" + ex.ToString());
}
if (grpName != "")
{
sqlResponse resp;
//int sipid = (Int32)txCPS.Value;
//if (DBcontact.isSipDuplicate(sipid, (int)ContactType.GROUP, Convert.ToInt32(txID.Text)) && cbGroupType.Text != GroupType.CATEGORY.ToString())
//{
// CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("IdAlreadyUsed"), MainForm.returnLNGString("err"));
// return;
//}
Int32 rgwID = 0;
if (cbGatewayAndRadioGW.SelectedItems.Count > 0)
rgwID = ((RadioGateway)((RadListDataItem)cbGatewayAndRadioGW.SelectedItems[0]).Value).Id;
//if ((MainForm.radioType != RADIOTYPE.MOTO) && (MainForm.radioType != RADIOTYPE.ATLAS) && (MainForm.radioType != RADIOTYPE.TETRA) && (MainForm.radioType != RADIOTYPE.CONECTPLUS)) DBgrp.EditGroupName(grpID, grpName, cps_id);
if ((MainForm.radioType != RADIOTYPE.ATLAS) && (MainForm.radioType != RADIOTYPE.CONECTPLUS) && (MainForm.radioType != RADIOTYPE.REPEATER_TRBO))
DBgrp.EditGroupName(grpID, grpName, cps_id, rgwID, out resp);
else
DBgrp.EditGroupName(grpID, grpName, 0, rgwID, out resp);
//MainForm.CallWebServer(MainForm.RestartSipLink);
HandleResp(resp);
}
}
}
//ShowGroups();
}
private void HandleResp(sqlResponse resp)
{
switch (resp)
{
case sqlResponse.done:
//RadMessageBox.Show("Unit Added to Database", "Done!", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
CustomMessageBox.Show(CustomMessageBoxType.check, MainForm.returnLNGString("gradd"), MainForm.returnLNGString("done"));
break;
case sqlResponse.noUpdate:
//RadMessageBox.Show("Unit Already in Database", "error!", MessageBoxButtons.OK, RadMessageIcon.Error);
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("allin"), MainForm.returnLNGString("err"));
break;
case sqlResponse.SQLerror:
//RadMessageBox.Show("SQL error", "error!", MessageBoxButtons.OK, RadMessageIcon.Error);
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("dberr"), MainForm.returnLNGString("err"));
break;
}
}
private void DeleteGroup()
{
if (GridViewGroupsList.SelectedRows.Count() > 0)
{
//int grpID = ((Group)((RadListDataItem)listBoxGroups.SelectedItems[0]).Value).Id;//((Group)listBoxGroups.SelectedValue).Id;
int grpID = (int)GridViewGroupsList.SelectedRows[0].Cells["Id"].Value;
DBgrp.DeleteGroup(grpID);
//MainForm.CallWebServer(MainForm.RestartSipLink);
}
//ShowGroups();
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void Save_Click(object sender, EventArgs e)
{
if (txCPS.Value == 0 && !cbGroupType.Text.Equals(GroupType.CATEGORY.displayedName))
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("grpIDGT0"), MainForm.returnLNGString("err"));
return;
}
switch (action)
{
case "add":
ValidateGatewayForSimoco();
if (CheckCPSIDforGateway())
return;
AddNewGroup();
break;
case "edit":
ValidateGatewayForSimoco();
if (CheckCPSIDforGateway())
return;
EditGroupName();
break;
case "delete":
DeleteGroup();
break;
}
if (cbGroupType.Text.Equals(GroupType.MOBILETALK.displayedName))
((MainForm)parent.Parent.Parent).setVisibleSipRestartNotification();
action = "edit";
cbGroupType.Enabled = false;
ShowGroups();
}
private bool CheckCPSIDforGateway()
{
if (cbGroupType.Text.Equals(GroupType.CATEGORY.displayedName))
return false;
if(cbGatewayAndRadioGW.SelectedValue == null)
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("assignGateway"), MainForm.returnLNGString("err"));
return true;
}
Int32 rgwid = ((RadioGateway)cbGatewayAndRadioGW.SelectedValue).Id;
string ID = txID.Text;
bool existsThisCpsIdOnSameGateway = grps.Where(x => x.CPS_Id == txCPS.Value && x.RgwID == rgwid && x.Id.ToString() != ID).Count() > 0;
if (existsThisCpsIdOnSameGateway)
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("duplicateCpsID"), MainForm.returnLNGString("err"));
}
return existsThisCpsIdOnSameGateway;
}
private void ValidateGatewayForSimoco()
{
#region Disable SIP related features for Simoco
if (MainForm.radioType == RADIOTYPE.SIMOCO || MainForm.radioType == RADIOTYPE.EXCERA)
{
if (!cbGroupType.Text.Equals(GroupType.CATEGORY.displayedName))
{
if (cbGatewayAndRadioGW.Items.Count < 1)
{
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("AddGatewayFirst"), MainForm.returnLNGString("err"));
return;
}
else
{
//it will be only one gateway
cbGatewayAndRadioGW.SelectedIndex = 0;
}
}
}
#endregion Disable SIP related features for Simoco
}
//private void listBoxGroups_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
//{
// if (listBoxGroups.SelectedItem != null && action != "add")
// {
// tbGroupName.Text = ((Group)((RadListDataItem)listBoxGroups.SelectedItems[0]).Value).Name;
// txID.Text = ((Group)((RadListDataItem)listBoxGroups.SelectedItems[0]).Value).Id.ToString();
// Int32 type = ((Group)((RadListDataItem)listBoxGroups.SelectedItems[0]).Value).Type;
// cbGroupType.Text = ((GroupType)Enum.ToObject(typeof(GroupType), type)).ToString();
// if (cbGroupType.Text != GroupType.CATEGORY.ToString())
// {
// Int32 rgwid = ((Group)((RadListDataItem)listBoxGroups.SelectedItems[0]).Value).RgwID;
// if (radioGWList != null)
// {
// RadioGateway rg = radioGWList.Where(x => x.Id == rgwid).FirstOrDefault();
// cbGatewayAndRadioGW.SelectedValue = rg;
// lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = true;
// lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = MainForm.radioType != RADIOTYPE.SIMOCO;
// }
// }
// else
// {
// cbGatewayAndRadioGW.SelectedIndex = 0;
// lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = false;
// }
// //if ((MainForm.radioType != RADIOTYPE.MOTO) && (MainForm.radioType != RADIOTYPE.ATLAS) && (MainForm.radioType != RADIOTYPE.TETRA) && (MainForm.radioType != RADIOTYPE.CONECTPLUS)) txCPS.Value = ((Group)((RadListDataItem)listBoxGroups.SelectedItems[0]).Value).CPS_Id;
// if ((MainForm.radioType != RADIOTYPE.ATLAS) && (MainForm.radioType != RADIOTYPE.TETRA) && (MainForm.radioType != RADIOTYPE.CONECTPLUS) && (MainForm.radioType != RADIOTYPE.REPEATER_TRBO)) txCPS.Value = ((Group)((RadListDataItem)listBoxGroups.SelectedItems[0]).Value).CPS_Id;
// }
// if ((listBoxGroups.SelectedItem != null && action != "edit") || listBoxGroups.SelectedItem == null)
// {
// this.Width = 393;
// }
// else
// {
// if (action == "edit" && cbGroupType.Text != GroupType.MOBILETALK.ToString())
// {
// this.Width = 393;
// }
// else
// {
// this.Width = 743;
// Group grpSelected = (Group)listBoxGroups.SelectedItem.Value;
// //add current units for group
// showCurrentUnits(grpSelected.Id);
// //add units that ar not asigned
// showOtherUnits(grpSelected.Id);
// }
// }
// setGatewayDropDown();
//}
private void GroupsForm_FormClosed(object sender, FormClosedEventArgs e)
{
if (action != "add") parent.ShowVehs(controlUnit.isCheckboxChecked);
}
#region assigned units to group
private void btnRemoveUnitFromGroup_Click(object sender, EventArgs e)
{
//Group grpSelected = (Group)listBoxGroups.SelectedItem.Value;
int grpID = (int)GridViewGroupsList.SelectedRows[0].Cells["Id"].Value;
foreach (RadListDataItem tmp in listBoxCurrentMembers.SelectedItems)
{
Vehicles vehSelected = (Vehicles)tmp.Value;
if (vehSelected.Type == 0)
DBgrp.removeVehicleGroupConnection(vehSelected.Id.ToString(), grpID.ToString());
if (vehSelected.Type == 1)
DBgrp.removeUserGroupConnection(vehSelected.Id.ToString(), grpID.ToString());
}
showCurrentUnits(grpID);
showOtherUnits(grpID);
}
private void btnAddUnitToGroup_Click(object sender, EventArgs e)
{
//Group grpSelected = (Group)listBoxGroups.SelectedItem.Value;
int grpID = (int)GridViewGroupsList.SelectedRows[0].Cells["Id"].Value;
foreach (RadListDataItem tmp in listBoxOtherMembers.SelectedItems)
{
Vehicles vehSelected = (Vehicles)tmp.Value;
if (vehSelected.Type == 0)
DBgrp.addVehicleGroupConnection(vehSelected.Id.ToString(), grpID.ToString());
if (vehSelected.Type == 1)
DBgrp.addUserGroupConnection(vehSelected.Id.ToString(), grpID.ToString());
}
showCurrentUnits(grpID);
showOtherUnits(grpID);
}
//show current users for vehicle
private void showCurrentUnits(int grpID)
{
try
{
List<Vehicles> vehList = DBgrp.getAllUnitsAndDispatchersForCurrentGroup(grpID.ToString());
listBoxCurrentMembers.DataSource = vehList;
listBoxCurrentMembers.DisplayMember = "VehName";
lbAssignedMembers.Text = $"{MainForm.returnLNGString("assignmembers")} ({listBoxCurrentMembers.Items.Count})";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
//show other users
private void showOtherUnits(int grpID)
{
try
{
List<Vehicles> vehList = DBgrp.getAllOtherUnitsAndDispatchersForCurrentGroup(grpID.ToString());
listBoxOtherMembers.DataSource = vehList;
listBoxOtherMembers.DisplayMember = "VehName";
lbUnassignedMembers.Text = $"{MainForm.returnLNGString("unassignmembers")} ({listBoxOtherMembers.Items.Count})";
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
private void showCurrentMobiles(int grpID)
{
try
{
List <Vehicles> grpList = DBgrp.getAllMobilesAssignedToRadioGroup(grpID);
listBoxCurrentGroups.DataSource = grpList;
listBoxCurrentGroups.DisplayMember = "VehName";
lbAssignedGroups.Text = $"{MainForm.returnLNGString("assignMobile")} ({listBoxCurrentGroups.Items.Count})";
CheckInsertIntoGroup();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
//show other users
private void showAvailableMobiles(int grpID)
{
try
{
List<Vehicles> grpList = DBgrp.getAllMobileAvailableFoRadioGroup();
listBoxOtherGroups.DataSource = grpList;
listBoxOtherGroups.DisplayMember = "VehName";
lbUnassignedGroups.Text = $"{MainForm.returnLNGString("unassignMobile")} ({listBoxOtherGroups.Items.Count})";
CheckInsertIntoGroup();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
private void showCurrentRadioTalk(int grpID)
{
try
{
List<Vehicles> grpList = DBgrp.getAllRadioTalkGroupsAssignedToMobileGroup(grpID);
listBoxCurrentGroups.DataSource = grpList;
listBoxCurrentGroups.DisplayMember = "VehName";
lbAssignedGroups.Text = $"{MainForm.returnLNGString("assignRadioTalk")} ({listBoxCurrentGroups.Items.Count})";
CheckInsertIntoGroup();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
//show other users
private void showAvailableRadioTalk(int grpID)
{
try
{
List<Vehicles> grpList = DBgrp.getAllRadioTalkGroupsAvailableForMobileGroup();
listBoxOtherGroups.DataSource = grpList;
listBoxOtherGroups.DisplayMember = "VehName";
lbUnassignedGroups.Text = $"{MainForm.returnLNGString("unassignRadioTalk")} ({listBoxOtherGroups.Items.Count})";
CheckInsertIntoGroup();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
private void listBoxUnits_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 listBoxOtherUnits_MouseDoubleClick(object sender, MouseEventArgs e)
{
RadListVisualItem clickedItem = listBoxOtherMembers.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
if (clickedItem != null)
{
RadListDataItem dataItem = clickedItem.Data;
btnAddUnitMember.PerformClick();
}
}
private void listBoxCurrentUnits_MouseDoubleClick(object sender, MouseEventArgs e)
{
RadListVisualItem clickedItem = listBoxCurrentMembers.ElementTree.GetElementAtPoint(e.Location) as RadListVisualItem;
if (clickedItem != null)
{
RadListDataItem dataItem = clickedItem.Data;
btnRemoveMember.PerformClick();
}
}
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 void listBoxUnits_ItemDataBound(object sender, ListItemDataBoundEventArgs args)
{
Vehicles view = (Vehicles)args.NewItem.DataBoundItem;
args.NewItem.Text = "<html>" +
"<b>" + view.VehName + "</b>";
if (view.Type == (int)ContactType.USER)
args.NewItem.Image = dispatcherImage;
if (view.Type == (int)ContactType.GROUP)
args.NewItem.Image = groupImage;
if (MainForm.carImages.ContainsKey(view.ImgID))
args.NewItem.Image = MainForm.carImages[view.ImgID];
}
#endregion
//private void cbGroupType_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
//{
//}
private void cbGroupType_TextChanged(object sender, EventArgs e)
{
lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = lbCps.Visible = txCPS.Visible = !(cbGroupType.Text.Equals(GroupType.CATEGORY.displayedName));
if (action != "edit")
{
if (cbGroupType.Text.Equals(GroupType.CATEGORY.displayedName))
txCPS.Value = 0;
else
txCPS.Value = 1;
}
if (radioGWList == null)
radioGWList = DBgateways.gelAllGatewaysAndRadioGateways();
if (radioGWList != null)
{
//cbGatewayAndRadioGW.Items.Clear();
cbGatewayAndRadioGW.DataSource = null;
if (cbGroupType.Text.Equals(GroupType.MOBILETALK.displayedName))
cbGatewayAndRadioGW.DataSource = radioGWList.Where(x => x.Type == (int)GatewayType.Broadband);
else if (cbGroupType.Text.Equals(GroupType.RADIOTALK.displayedName))
cbGatewayAndRadioGW.DataSource = radioGWList.Where(x => x.Type == (int)GatewayType.Tier2Radio || x.Type == (int)GatewayType.Tier3Radio
|| x.Type == (int)GatewayType.SMCBridge);
cbGatewayAndRadioGW.DisplayMember = "name";
if (!cbGroupType.Text.Equals(GroupType.CATEGORY.displayedName))
{
if (GridViewGroupsList.SelectedRows.Count > 0)
{
int rgwid = (int)GridViewGroupsList.SelectedRows[0].Cells["RgwID"].Value;
//Int32 rgwid = ((Group)((RadListDataItem)listBoxGroups.SelectedItems[0]).Value).RgwID;
if (radioGWList != null)
{
RadioGateway rg = radioGWList.Where(x => x.Id == rgwid).FirstOrDefault();
cbGatewayAndRadioGW.SelectedValue = rg;
lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = true;
}
}
}
else
{
cbGatewayAndRadioGW.SelectedIndex = 0;
lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = false;
}
}
#region Disable SIP related features for Simoco
if (MainForm.radioType == RADIOTYPE.SIMOCO || MainForm.radioType == RADIOTYPE.EXCERA)
{
lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = false;
}
#endregion
}
private void listBoxCurrentUnits_CreatingVisualListItem(object sender, CreatingVisualListItemEventArgs args)
{
RadListVisualItem visualItem = new RadListVisualItem();
visualItem.Padding = new Padding(5, 5, 0, 5);
args.VisualItem = visualItem;
}
private void listBoxOtherUnits_CreatingVisualListItem(object sender, CreatingVisualListItemEventArgs args)
{
RadListVisualItem visualItem = new RadListVisualItem();
visualItem.Padding = new Padding(5, 5, 0, 5);
args.VisualItem = visualItem;
}
private void cbGroupType_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
setGatewayDropDown();
}
private void GridViewGroupsList_CellFormatting(object sender, CellFormattingEventArgs e)
{
int value;
if (e.CellElement.ColumnInfo.Name == "CPS_Id" && e.CellElement.Text == "0")
{
e.CellElement.Text = "";
}
if (e.CellElement.ColumnInfo.Name == "Type" && Int32.TryParse(e.CellElement.Text, out value))
{
try
{
e.CellElement.Text = (GroupType.FromValue(value)).displayedName;
}
catch(Exception ex)
{
Utils.WriteLine(ex.ToString(), ConsoleColor.Red);
}
}
else if (e.CellElement is GridImageCellElement && e.CellElement.ColumnInfo.Name == "delete")
{
if (e.Row.IsSelected)
e.CellElement.BackgroundImage = Properties.Resources.trashmic1;
else
e.CellElement.BackgroundImage = null;
}
}
private void GridViewGroupsList_CellClick(object sender, GridViewCellEventArgs e)
{
//delete group
if (e.Column.Name == "delete" && e.RowIndex != -1)
{
Utils.WriteLine("Nr of rows : " + GridViewGroupsList.RowCount);
int grpID = (int)GridViewGroupsList.SelectedRows[0].Cells["Id"].Value;
string grpName = (string)GridViewGroupsList.SelectedRows[0].Cells["Name"].Value;
string msg = string.Format(MainForm.returnLNGString("aredelgrp"), grpName);
DialogResult dr2 = RadMessageBox.Show(msg, MainForm.returnLNGString("delgrp")
, MessageBoxButtons.YesNo, RadMessageIcon.Exclamation);
if (dr2 == DialogResult.Yes)
{
DBgrp.DeleteGroup(grpID);
ShowGroups();
}
}
}
private void pbAddGroup_Click(object sender, EventArgs e)
{
this.Width = 393;
cbGroupType.Enabled = true;
action = "add";
groupBox1.Enabled = true;
EmptyFields();
}
private void EmptyFields()
{
tbGroupName.Text = "";
txID.Text = "";
txCPS.Value = 0;
cbGroupType.Text = GroupType.CATEGORY.displayedName;
}
private void pbAddGroup_MouseEnter(object sender, EventArgs e)
{
DisplayToolTip();
}
private void pbAddGroup_MouseHover(object sender, EventArgs e)
{
DisplayToolTip();
}
private void pbAddGroup_MouseLeave(object sender, EventArgs e)
{
toolTipAddGroup.Hide(pbAddGroup);
}
private void DisplayToolTip()
{
String hint = MainForm.returnLNGString("toolTipGroups1") + Environment.NewLine +
MainForm.returnLNGString("toolTipGroups2");
toolTipAddGroup.Show(hint, pbAddGroup, 150000);
}
private void GridViewGroupsList_SelectionChanged(object sender, EventArgs e)
{
action = "edit";
if (GridViewGroupsList.SelectedRows.Count() > 0 && action != "add")
{
tbGroupName.Text = (string)GridViewGroupsList.SelectedRows[0].Cells["Name"].Value;
txID.Text = GridViewGroupsList.SelectedRows[0].Cells["Id"].Value.ToString();
cbGroupType.Text = ((GroupType.FromValue((int)GridViewGroupsList.SelectedRows[0].Cells["Type"].Value)).displayedName);
if (!cbGroupType.Text.Equals(GroupType.CATEGORY.displayedName))
{
//Int32 rgwid = ((Group)((RadListDataItem)listBoxGroups.SelectedItems[0]).Value).RgwID;
int rgwid = (int)GridViewGroupsList.SelectedRows[0].Cells["RgwID"].Value;
if (radioGWList != null)
{
RadioGateway rg = radioGWList.Where(x => x.Id == rgwid).FirstOrDefault();
cbGatewayAndRadioGW.SelectedValue = rg;
lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = true;
lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = (MainForm.radioType != RADIOTYPE.SIMOCO && MainForm.radioType != RADIOTYPE.EXCERA);
}
}
else
{
cbGatewayAndRadioGW.SelectedIndex = 0;
lbGWandRGW.Visible = cbGatewayAndRadioGW.Visible = false;
}
//if ((MainForm.radioType != RADIOTYPE.MOTO) && (MainForm.radioType != RADIOTYPE.ATLAS) && (MainForm.radioType != RADIOTYPE.TETRA) && (MainForm.radioType != RADIOTYPE.CONECTPLUS)) txCPS.Value = ((Group)((RadListDataItem)listBoxGroups.SelectedItems[0]).Value).CPS_Id;
if ((MainForm.radioType != RADIOTYPE.ATLAS) && (MainForm.radioType != RADIOTYPE.TETRA) && (MainForm.radioType != RADIOTYPE.CONECTPLUS) && (MainForm.radioType != RADIOTYPE.REPEATER_TRBO))
txCPS.Value = (int)GridViewGroupsList.SelectedRows[0].Cells["CPS_Id"].Value;
}
if ((GridViewGroupsList.SelectedRows.Count() > 0 && action != "edit") || GridViewGroupsList.SelectedRows == null)
{
this.Width = 393;
}
else
{
if (action == "edit" && !cbGroupType.Text.Equals(GroupType.MOBILETALK.displayedName))
{
if (cbGroupType.Text.Equals(GroupType.RADIOTALK.displayedName)
&& MainForm.radioType == RADIOTYPE.LINXB)
{
int grpID = (int)GridViewGroupsList.SelectedRows[0].Cells["Id"].Value;
radPageMembers.Item.Visibility = ElementVisibility.Collapsed;
radPageAssigned.SelectedPage = radPageRadioTalk;
radPageRadioTalk.Text = MainForm.returnLNGString("linkMobileTalk");
showCurrentMobiles(grpID);
showAvailableMobiles(grpID);
this.Width = 743;
}
else
this.Width = 393;
}
else
{
this.Width = 743;
radPageMembers.Item.Visibility = ElementVisibility.Visible;
if(MainForm.radioType != RADIOTYPE.LINXB)
radPageRadioTalk.Item.Visibility = ElementVisibility.Collapsed;
radPageAssigned.SelectedPage = radPageMembers;
int grpID = (int)GridViewGroupsList.SelectedRows[0].Cells["Id"].Value;
//add current units for group
showCurrentUnits(grpID);
//add units that ar not asigned
showOtherUnits(grpID);
//add current units for group
radPageRadioTalk.Text = MainForm.returnLNGString("linkRadioTalk");
showCurrentRadioTalk(grpID);
//add units that ar not asigned
showAvailableRadioTalk(grpID);
}
}
setGatewayDropDown();
}
private void btnAddGroup_Click(object sender, EventArgs e)
{
int grpID = (int)GridViewGroupsList.SelectedRows[0].Cells["Id"].Value;
int type = (int)GridViewGroupsList.SelectedRows[0].Cells["Type"].Value;
if (type == GroupType.MOBILETALK.value)
{
foreach (RadListDataItem tmp in listBoxOtherGroups.SelectedItems)
{
Vehicles vehSelected = (Vehicles)tmp.Value;
if (vehSelected.Type == (int)ContactType.GROUP)
DBgrp.addRadioMobileConnection(vehSelected.Id.ToString(), grpID.ToString());
}
showCurrentRadioTalk(grpID);
showAvailableRadioTalk(grpID);
}
if (type == GroupType.RADIOTALK.value)
{
DBgrp.cleanRadioTalkConnection(grpID.ToString());
foreach (RadListDataItem tmp in listBoxOtherGroups.SelectedItems)
{
Vehicles vehSelected = (Vehicles)tmp.Value;
if (vehSelected.Type == (int)ContactType.GROUP)
DBgrp.addRadioMobileConnection(grpID.ToString(),vehSelected.Id.ToString());
else if (vehSelected.Type == (int)ContactType.UNIT)
DBgrp.addVehicleGroupConnection(vehSelected.Id.ToString(), grpID.ToString());
}
showCurrentMobiles(grpID);
showAvailableMobiles(grpID);
}
}
private void btnRemoveGroup_Click(object sender, EventArgs e)
{
//Group grpSelected = (Group)listBoxGroups.SelectedItem.Value;
int grpID = (int)GridViewGroupsList.SelectedRows[0].Cells["Id"].Value;
int type = (int)GridViewGroupsList.SelectedRows[0].Cells["Type"].Value;
if (type == GroupType.MOBILETALK.value)
{
foreach (RadListDataItem tmp in listBoxCurrentGroups.SelectedItems)
{
Vehicles vehSelected = (Vehicles)tmp.Value;
if (vehSelected.Type == (int)ContactType.GROUP)
DBgrp.removeRadioMobileConnection(vehSelected.Id.ToString(), grpID.ToString());
}
showCurrentRadioTalk(grpID);
showAvailableRadioTalk(grpID);
}
if (type == GroupType.RADIOTALK.value)
{
foreach (RadListDataItem tmp in listBoxCurrentGroups.SelectedItems)
{
Vehicles vehSelected = (Vehicles)tmp.Value;
if (vehSelected.Type == (int)ContactType.GROUP)
DBgrp.removeRadioMobileConnection(grpID.ToString(), vehSelected.Id.ToString());
else if (vehSelected.Type == (int)ContactType.UNIT)
DBgrp.removeUserGroupConnection(vehSelected.Id.ToString(), grpID.ToString());
}
showCurrentMobiles(grpID);
showAvailableMobiles(grpID);
}
}
private void CheckInsertIntoGroup()
{
btnAddGroup.Enabled = listBoxCurrentGroups.Items.Count() == 0;
}
}
}