SafeDispatch/Safedispatch_4_0/maptab/LandZoneCfgGIS.cs
2024-02-22 18:43:59 +02:00

2763 lines
130 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls;
using Telerik.WinControls.UI.Docking;
using System.Net.NetworkInformation;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.EngineCore;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using System.Threading;
using SafeMobileLib;
using Dispatcher.maptab.UIClasses;
using System.Drawing.Imaging;
using System.IO;
namespace Safedispatch_4_0
{
public partial class LandZoneCfgGIS : UserControl
{
private SMdb_access smdbObj;
private Boolean Loaddata = true;
private Boolean PointForZone = false;
private Boolean LandMarkNotSpecPoint = false;
private Int32 RowToUpdate = -1;
String col0, col1, col2, col3, col4, mess1, mess2, mess5, mess4,mess6, messaddlatlongout, messadd, messaddquiz, messaddname, msgNotSave, msgWar;
String mess11, mess12, mess15, messWill, msgNotSaveZone, mess16, messPointToDel, need3Points, msgSplitEmail, msgInvalidEmail;
Color color = Color.Red;
private Boolean OnNewLandMark = false;
private IMapControl3 m_mapControl = null;
public IGraphicTracker m_graphicTracker = null;
public IGraphicTracker PINSET = null;
private Boolean loadfinish = false;
private String password = "";
private ArrayList vehicleListNames = new ArrayList();
// Colors list
private List<Color> colorsList;
public static Dictionary<Int32, LandmarkType> landmarkTypesList;
private static String safemobileDirPath = System.Windows.Forms.Application.StartupPath;
private void setLanguage()
{
toolWindow1.Text = MainForm2.returnLNGString("lands");
toolWindow4.Text = MainForm2.returnLNGString("zones");
toolWindow3.Text = MainForm2.returnLNGString("tabPage1");
col0 = MainForm2.returnLNGString("colum0");
col1 = MainForm2.returnLNGString("lbDescript");
col2 = MainForm2.returnLNGString("colum2");
col3 = MainForm2.returnLNGString("colum3");
col4 = MainForm2.returnLNGString("colum4");
lbName.Text = MainForm2.returnLNGString("colum0") + ':';
lbDesc.Text = MainForm2.returnLNGString("lbDescript") + ':';
lbLat.Text = MainForm2.returnLNGString("colum2") + ':';
lbLng.Text = MainForm2.returnLNGString("colum3") + ':';
//lbType.Text = MainForm2.returnLNGString("colum4") + ':';
btSave.Text = MainForm2.returnLNGString("save");
btDelete.Text = MainForm2.returnLNGString("SMSDelete");
btNew.Text = MainForm2.returnLNGString("newname");
btZoneDel.Text = MainForm2.returnLNGString("SMSDelete");
btZoneNew.Text = MainForm2.returnLNGString("newname");
btZoneEdit.Text = MainForm2.returnLNGString("edit");
lbAddress.Text = MainForm2.returnLNGString("tableVehiclesListColumns2") + ':';
//lbEditLand.Text = MainForm2.returnLNGString("editLand") + ':';
//lbEditZone.Text = MainForm2.returnLNGString("zonename") + ':';
//lbColor.Text = MainForm2.returnLNGString("Ilabel4");
ckHide.Text = MainForm2.returnLNGString("hideOth");
mess1 = MainForm2.returnLNGString("messdelete");
messPointToDel = MainForm2.returnLNGString("messdeletePoint");
mess2 = MainForm2.returnLNGString("messdeletequiz");
mess4 = MainForm2.returnLNGString("zonename");
mess5 = MainForm2.returnLNGString("messdeletename");
mess6 = MainForm2.returnLNGString("geoNameExist2");
messaddlatlongout = MainForm2.returnLNGString("messaddlatlongout");
messadd = MainForm2.returnLNGString("messadd");
messaddname = MainForm2.returnLNGString("messaddname");
messaddquiz = MainForm2.returnLNGString("messaddquiz");
msgWar = MainForm2.returnLNGString("msgWar");
msgNotSave = MainForm2.returnLNGString("msgNotSave");
msgNotSaveZone = MainForm2.returnLNGString("msgNotSaveZone");
need3Points = MainForm2.returnLNGString("need3Points");
mess11 = MainForm2.returnLNGString("zone");
mess12 = MainForm2.returnLNGString("messdeletequizzone");
mess15 = MainForm2.returnLNGString("messdeletenamezone");
mess16 = MainForm2.returnLNGString("messdeletenamePoint");
messWill = MainForm2.returnLNGString("willdelete");
msgInvalidEmail = MainForm2.returnLNGString("msgInvalidEmail");
msgSplitEmail = MainForm2.returnLNGString("msgSplitEmail");
ckSpeedLimit.Text = MainForm2.returnLNGString("speedLimitInGeofence"); //Speed limit in geofence [km/h]
ckSpeedLimit.Text = (MainForm2.isInMile) ? string.Format(ckSpeedLimit.Text, (MainForm2.returnLNGString("kmh"))) : string.Format(ckSpeedLimit.Text, (MainForm2.returnLNGString("milesh")));
PointList.Columns[0].HeaderText = "";
PointList.Columns[1].HeaderText = "";
PointList.Columns[2].HeaderText = lbLat.Text;
PointList.Columns[3].HeaderText = lbLng.Text;
PointList.Columns[5].HeaderText = "";
toolWindow1.ToolCaptionButtons = Telerik.WinControls.UI.Docking.ToolStripCaptionButtons.None;
//toolWindow1.DocumentButtons &= ~Telerik.WinControls.UI.Docking.DocumentStripButtons.Close;
toolWindow1.DocumentButtons = Telerik.WinControls.UI.Docking.DocumentStripButtons.None;
toolWindow1.AllowedDockState = AllowedDockState.Docked | AllowedDockState.AutoHide;
toolWindow4.ToolCaptionButtons = Telerik.WinControls.UI.Docking.ToolStripCaptionButtons.None;
toolWindow4.DocumentButtons = Telerik.WinControls.UI.Docking.DocumentStripButtons.None;
toolWindow4.AllowedDockState = AllowedDockState.Docked | AllowedDockState.AutoHide;
toolWindow3.ToolCaptionButtons = Telerik.WinControls.UI.Docking.ToolStripCaptionButtons.None;
toolWindow3.DocumentButtons = Telerik.WinControls.UI.Docking.DocumentStripButtons.None;
lbSpeedName.Text = MainForm2.kmh;
if (MainForm2.isInMile)
lbSpeedName.Text = MainForm2.milesh;
}
IGraphicsContainer graphicsContainer = null;
private String tabName;
public LandZoneCfgGIS(String _tabName)
{
try
{
tabName = _tabName;
smdbObj = new SMdb_access();
InitializeComponent();
#region THEMING
labelGeofences.ForeColor = MainForm2.LabelColor;
labelLandmarks.ForeColor = MainForm2.LabelColor;
labelAlerts.ForeColor = MainForm2.LabelColor;
labelStyle.ForeColor = MainForm2.LabelColor;
btAddPoint.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
btDelete.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
btNew.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
btSave.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
btZoneDel.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
btZoneEdit.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
btZoneNew.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
documentTabStrip2.TabStripElement.BorderTopColor = MainForm2.ButtonColor;
documentTabStrip2.TabStripElement.BorderTopShadowColor = MainForm2.ButtonColor;
documentTabStrip2.SplitPanelElement.Border.TopShadowColor = MainForm2.ButtonColor;
documentTabStrip2.SplitPanelElement.Border.TopColor = MainForm2.ButtonColor;
rgbStyle.GroupBoxElement.Header.Border.TopColor = MainForm2.ButtonColor;
rgbStyle.GroupBoxElement.Header.Border.TopShadowColor = MainForm2.ButtonColor;
rgbStyle.GroupBoxElement.Header.TextPrimitive.ForeColor = MainForm2.ButtonColor;
rgbStyle.GroupBoxElement.Header.ImagePrimitive.Image =
pbStyle.Image = Utils.ChangeColor(Dispatcher.Properties.Resources.i_style_24, MainForm2.ButtonColor);
rgbAlerts.GroupBoxElement.Header.Border.TopColor = MainForm2.ButtonColor;
rgbAlerts.GroupBoxElement.Header.Border.TopShadowColor = MainForm2.ButtonColor;
rgbAlerts.GroupBoxElement.Header.TextPrimitive.ForeColor = MainForm2.ButtonColor;
rgbAlerts.GroupBoxElement.Header.ImagePrimitive.Image =
pbAlerts.Image = Utils.ChangeColor(Dispatcher.Properties.Resources.i_alert_24, MainForm2.ButtonColor);
rgbDetails.GroupBoxElement.Header.Border.TopColor = MainForm2.ButtonColor;
rgbDetails.GroupBoxElement.Header.Border.TopShadowColor = MainForm2.ButtonColor;
rgbDetails.GroupBoxElement.Header.TextPrimitive.ForeColor = MainForm2.ButtonColor;
rgbDetails.GroupBoxElement.Header.ImagePrimitive.Image = Utils.ChangeColor(Dispatcher.Properties.Resources.i_details_24, MainForm2.ButtonColor);
rgbStyleLand.GroupBoxElement.Header.Border.TopColor = MainForm2.ButtonColor;
rgbStyleLand.GroupBoxElement.Header.Border.TopShadowColor = MainForm2.ButtonColor;
rgbStyleLand.GroupBoxElement.Header.TextPrimitive.ForeColor = MainForm2.ButtonColor;
rgbStyleLand.GroupBoxElement.Header.ImagePrimitive.Image = Utils.ChangeColor(Dispatcher.Properties.Resources.i_style_24, MainForm2.ButtonColor);
rgbDetailsLand.GroupBoxElement.Header.Border.TopColor = MainForm2.ButtonColor;
rgbDetailsLand.GroupBoxElement.Header.Border.TopShadowColor = MainForm2.ButtonColor;
rgbDetailsLand.GroupBoxElement.Header.TextPrimitive.ForeColor = MainForm2.ButtonColor;
rgbDetailsLand.GroupBoxElement.Header.ImagePrimitive.Image = Utils.ChangeColor(Dispatcher.Properties.Resources.i_details_24, MainForm2.ButtonColor);
#endregion
// set theme for the Message Box
RadMessageBox.SetThemeName("TelerikMetroBlue");
setLanguage();
///HIDE address
//lbAddress.Visible = false;
//txAddress.Visible = false;
//lbType.Location = new System.Drawing.Point(lbType.Location.X, lbType.Location.Y - 30);
//cbPlaceType.Location = new System.Drawing.Point(cbPlaceType.Location.X, cbPlaceType.Location.Y - 30);
//pictureBox1.Location = new System.Drawing.Point(pictureBox1.Location.X, pictureBox1.Location.Y - 30);
//btNew.Location = new System.Drawing.Point(btNew.Location.X, btNew.Location.Y - 30);
//btSave.Location = new System.Drawing.Point(btSave.Location.X, btSave.Location.Y - 30);
//btDelete.Location = new System.Drawing.Point(btDelete.Location.X, btDelete.Location.Y - 30);
#region COLORS LIST
// create the list of colors for the Landmarks
colorsList = new List<Color>() {
System.Drawing.ColorTranslator.FromHtml("#efed4f"),
System.Drawing.ColorTranslator.FromHtml("#d3e4ab"),
System.Drawing.ColorTranslator.FromHtml("#b7e64b"),
System.Drawing.ColorTranslator.FromHtml("#8ee247"),
System.Drawing.ColorTranslator.FromHtml("#52c144"),
System.Drawing.ColorTranslator.FromHtml("#61c1a3"),
System.Drawing.ColorTranslator.FromHtml("#97c8e3"),
System.Drawing.ColorTranslator.FromHtml("#3ea8e5"),
System.Drawing.ColorTranslator.FromHtml("#1796d9"),
System.Drawing.ColorTranslator.FromHtml("#007cb8"),
System.Drawing.ColorTranslator.FromHtml("#2636cb"),
System.Drawing.ColorTranslator.FromHtml("#4f6aa1"),
System.Drawing.ColorTranslator.FromHtml("#856dc3"),
System.Drawing.ColorTranslator.FromHtml("#ac70dd"),
System.Drawing.ColorTranslator.FromHtml("#cd567a"),
System.Drawing.ColorTranslator.FromHtml("#c7282a"),
System.Drawing.ColorTranslator.FromHtml("#f94040"),
System.Drawing.ColorTranslator.FromHtml("#e2635c"),
System.Drawing.ColorTranslator.FromHtml("#fe5011"),
System.Drawing.ColorTranslator.FromHtml("#fa7746"),
System.Drawing.ColorTranslator.FromHtml("#f3b24b"),
System.Drawing.ColorTranslator.FromHtml("#e4aa63"),
System.Drawing.ColorTranslator.FromHtml("#e3e3e3"),
System.Drawing.ColorTranslator.FromHtml("#b6b6b6"),
System.Drawing.ColorTranslator.FromHtml("#606060"),
System.Drawing.ColorTranslator.FromHtml("#414141"),
System.Drawing.ColorTranslator.FromHtml("#000000") };
// style for the Colors ListView
rlvLandmarkColors.ItemSize = new System.Drawing.Size(25, 25);
rlvLandmarkColors.ItemSpacing = 0;
// style the Visual Item for the Colors ListView
rlvLandmarkColors.VisualItemCreating += delegate(object sender, Telerik.WinControls.UI.ListViewVisualItemCreatingEventArgs e)
{
e.VisualItem = new ColorCellElement();
};
// set the data source of the Colors ListView
rlvLandmarkColors.DataSource = colorsList;
// style for the Colors ListView
rlvGeofenceBorderColors.ItemSize = new System.Drawing.Size(29, 29);
rlvGeofenceBorderColors.ItemSpacing = 0;
// style the Visual Item for the Colors ListView
rlvGeofenceBorderColors.VisualItemCreating += delegate(object sender, Telerik.WinControls.UI.ListViewVisualItemCreatingEventArgs e)
{
e.VisualItem = new ColorCellElement();
};
// set the data source of the Colors ListView
rlvGeofenceBorderColors.DataSource = colorsList;
#endregion
#region LANDMARKS ICONS LIST
// Process the list of files found in the directory.
if (landmarkTypesList == null)
landmarkTypesList = smdbObj.GetAllLandmarkTypes();
// style for the Icons ListView
rlvIcons.ItemSize = new System.Drawing.Size(27, 27);
rlvIcons.ItemSpacing = 0;
// style the Visual Item for the Icons ListView
rlvIcons.VisualItemCreating += delegate(object sender, Telerik.WinControls.UI.ListViewVisualItemCreatingEventArgs e)
{
e.VisualItem = new IconCellElement();
};
// set the data source of the Icons ListView
rlvIcons.DataSource = landmarkTypesList;
#endregion
}
catch(Exception ex)
{
SM.Debug("Error1:"+ex.ToString());
}
try
{
ReloadCombo("");
ReloadComboZone("");
}
catch (Exception ex)
{
SM.Debug("Error place1: " + ex.ToString());
}
try
{
Loaddata = false;
if (cbLandEdit.Items.Count > 1)
{
cbLandEdit.SelectedIndex = 1;
cbLandEdit.SelectedIndex = 0;
}
else if (cbLandEdit.Items.Count == 1) { try { SelectionLand(); } catch (Exception ex) { SM.Debug("EX:" + ex.ToString()); } }
if (cbZoneEdit.Items.Count > 1)
{
cbZoneEdit.SelectedIndex = 1;
cbZoneEdit.SelectedIndex = 0;
}
else
{
/*cbColor.SelectedIndex = 0;*/
rlvGeofenceBorderColors.SelectedIndex = 0;
}
foreach (String obj in MainForm2.vehicleHT.Keys)
vehicleListNames.Add(new VehandID(((Vehicle)MainForm2.vehicleHT[obj]).busName, ((Vehicle)MainForm2.vehicleHT[obj]).sc_id, ((Vehicle)MainForm2.vehicleHT[obj]).IMEI));
foreach (VehandID obj in vehicleListNames)
cbVehNameFleet.Items.Add(new CustomListDataItem(obj.Name));
//txNameZone.Location = new System.Drawing.Point(cbZoneEdit.Location.X, cbZoneEdit.Location.Y);
txNameZone.Visible = radLabel2.Visible = false;
pb_DeleteGeofence.Enabled = cbZoneEdit.Enabled = true;
/*cbColor.Enabled = false;*/
rlvGeofenceBorderColors.Enabled = false;
btZoneNew.Enabled = false;
ckEmail.Enabled = false;
ckTextMessage.Enabled = false;
ckSingleText.Enabled = false;
txBody.Enabled = false;
txEmail.Enabled = false;
txMsgbody.Enabled = false;
txMsgbody2.Enabled = false;
txSubj.Enabled = false;
cbVehNameFleet.Enabled = false;
rcbddAlertType.Enabled = false;
ckSpeedLimit.Enabled = false;
tbSpeed.Enabled = false;
lbSpeedName.Enabled = false;
//toolWindow1.ToolCaptionButtons = ToolStripCaptionButtons.AutoHide | ToolStripCaptionButtons.SystemMenu;
//toolWindow4.ToolCaptionButtons = ToolStripCaptionButtons.AutoHide | ToolStripCaptionButtons.SystemMenu;
ContextMenuService menuService = this.radDock1.GetService<ContextMenuService>();
menuService.ContextMenuDisplaying += menuService_ContextMenuDisplaying;
//this disables the context menu
menuService.AllowActiveWindowListContextMenu = false;
menuService.AllowDocumentContextMenu = false;
menuService.AllowToolContextMenu = false;
RadCheckedListDataItem radCheckedListDataItem1 = new RadCheckedListDataItem(MainForm2.returnLNGString("g_in"), true);
RadCheckedListDataItem radCheckedListDataItem2 = new RadCheckedListDataItem(MainForm2.returnLNGString("g_out"), true);
this.rcbddAlertType.Items.Add(radCheckedListDataItem1);
this.rcbddAlertType.Items.Add(radCheckedListDataItem2);
}
catch(Exception ex)
{
SM.Debug("Error2:"+ex.ToString());
}
try
{
switch (MainForm2.radioType)
{
case RADIOTYPE.HYT:
radDock1.BackColor = MainForm2.HyteraColor;
radSplitContainer1.BackColor = MainForm2.HyteraColor;
//radSplitContainer2.BackColor = MainForm2.HyteraColor;
documentTabStrip2.BackColor = MainForm2.HyteraColor;
documentTabStrip3.BackColor = MainForm2.HyteraColor;
//splitPanel1.BackColor = MainForm2.HyteraColor;
splitPanel3.BackColor = MainForm2.HyteraColor;
toolWindow4.BackColor = MainForm2.HyteraColor;
toolWindow3.BackColor = MainForm2.HyteraColor;
toolWindow1.BackColor = MainForm2.HyteraColor;
break;
case RADIOTYPE.HARRIS:
radDock1.BackColor = MainForm2.HarrisColor;
radSplitContainer1.BackColor = MainForm2.HarrisColor;
//radSplitContainer2.BackColor = MainForm2.HarrisColor;
documentTabStrip2.BackColor = MainForm2.HarrisColor;
documentTabStrip3.BackColor = MainForm2.HarrisColor;
toolTabStrip5.BackColor = MainForm2.HarrisColor;
toolWindow4.BackColor = MainForm2.HarrisColor;
toolWindow3.BackColor = MainForm2.HarrisColor;
toolWindow1.BackColor = MainForm2.HarrisColor;
lbAddress.ForeColor = MainForm2.HarTextColor;
lbDesc.ForeColor = MainForm2.HarTextColor;
//lbEditLand.ForeColor = MainForm2.HarTextColor;
lbLat.ForeColor = MainForm2.HarTextColor;
lbLng.ForeColor = MainForm2.HarTextColor;
lbName.ForeColor = MainForm2.HarTextColor;
//lbType.ForeColor = MainForm2.HarTextColor;
break;
case RADIOTYPE.ATLAS:
radDock1.BackColor = MainForm2.HarrisColor; //ATLASCHANGE no neccesary
radSplitContainer1.BackColor = MainForm2.HarrisColor;
//radSplitContainer2.BackColor = MainForm2.HarrisColor;
documentTabStrip2.BackColor = MainForm2.HarrisColor;
documentTabStrip3.BackColor = MainForm2.HarrisColor;
toolTabStrip5.BackColor = MainForm2.HarrisColor;
toolWindow4.BackColor = MainForm2.HarrisColor;
toolWindow3.BackColor = MainForm2.HarrisColor;
toolWindow1.BackColor = MainForm2.HarrisColor;
lbAddress.ForeColor = MainForm2.HarTextColor;
lbDesc.ForeColor = MainForm2.HarTextColor;
//lbEditLand.ForeColor = MainForm2.HarTextColor;
lbLat.ForeColor = MainForm2.HarTextColor;
lbLng.ForeColor = MainForm2.HarTextColor;
lbName.ForeColor = MainForm2.HarTextColor;
//lbType.ForeColor = MainForm2.HarTextColor;
break;
case RADIOTYPE.SIMOCO:
//we don't need this probably
break;
case RADIOTYPE.EXCERA:
//we don't need this probably
break;
}
}
catch (Exception ex)
{
SM.Debug("Error on change color constructor:" + ex.ToString());
}
}
private void menuService_ContextMenuDisplaying(object sender, ContextMenuDisplayingEventArgs e)
{
if (e.MenuType == ContextMenuType.DockWindow &&
e.DockWindow.DockTabStrip is DocumentTabStrip)
{
for (int i = 0; i < e.MenuItems.Count; i++)
{
RadMenuItemBase menuItem = e.MenuItems[i];
if (menuItem.Name == "CloseWindow" ||
menuItem.Name == "CloseAllButThis" ||
menuItem.Name == "CloseAll" ||
menuItem.Name == "Hidden" ||
menuItem is RadMenuSeparatorItem)
{
menuItem.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
}
}
}
}
public void ReloadCombo(String focus)
{
try
{
ArrayList tmpName = new ArrayList();
OldtxName = "";
foreach (Int32 obj in MainForm2.LandIDHash.Keys)
tmpName.Add(new Zone_type((String)MainForm2.LandIDHash[obj], obj, 0));
tmpName.Sort(new DefineSMSComparer());
cbLandEdit.DataSource = tmpName;
cbLandEdit.DisplayMember = "Name";
OldtxName = "";
if (cbLandEdit.Items.Count == 0)
{
cbLandEdit.Text = "";
btSave.Enabled = false;
btDelete.Enabled = false;
MapPanelLand.Enabled = false;
txAddress.Clear();
txName.Clear();
txDesc.Clear();
//txLat.Clear();
//txLng.Clear();
}
else
{
btDelete.Enabled = true;
btSave.Enabled = true;
MapPanelLand.Enabled = true;
}
if (focus == "") cbLandEdit.SelectedIndex = 0;
else
{
int cnt = 0;
foreach (RadListDataItem obj in cbLandEdit.Items)
{
if (((Zone_type)(obj.Value)).name.CompareTo(focus) == 0)
{
cbLandEdit.SelectedIndex = cnt;
break;
}
cnt++;
}
}
}
catch (Exception ex)
{
SM.Debug("Ex:"+ex.ToString());
}
}
public void ReloadComboZone(String focus)
{
try
{
ArrayList tmpName = new ArrayList();
foreach (Int32 obj in MainForm2.ZoneIDHash.Keys)
tmpName.Add((ZoneClass)MainForm2.ZoneIDHash[obj]);
tmpName.Sort(new ZoneClassComparer());
cbZoneEdit.DataSource = tmpName;
cbZoneEdit.DisplayMember = "Name";
if (tmpName.Count <= 0)
{
cbZoneEdit.Text = "";
Newarr.Clear();
/*color = (new GetColorID()).getColorid(cbColor.SelectedIndex);*/
color = (Color)rlvGeofenceBorderColors.SelectedItem.DataBoundItem;
idxzone = 0;
useridxzone = MainForm2.userIDX;
populateList();
txNameZone.Text = "";
btZoneDel.Enabled = false;
btZoneEdit.Enabled = false;
}
else
{
btZoneDel.Enabled = true;
btZoneEdit.Enabled = true;
if (focus == "") cbZoneEdit.SelectedIndex = 0;
else
{
int cnt = 0;
foreach (RadListDataItem obj in cbZoneEdit.Items)
{
if (((ZoneClass)(obj.Value)).name.CompareTo(focus) == 0)
{
cbZoneEdit.SelectedIndex = cnt;
break;
}
cnt++;
}
}
}
}
catch (Exception ex)
{
SM.Debug("EX:"+ex.ToString());
}
}
private void PutAllLandmarks()
{
try
{
if (loadfinish)
m_graphicTracker.RemoveAll();
ArrayList tmp = smdbObj.get_all_places_GIS("");
IPoint point = null;
Int32 Idgen = 0;
Double LNGMAX = -181; Double LNGMIN = 181;
Double LATMAX = -91; Double LATMIN = 90;
if (loadfinish)
{
foreach (Place obj in tmp)
{
point = new ESRI.ArcGIS.Geometry.Point();
point.X = obj.lng;
point.Y = obj.lat;
if (LNGMAX < obj.lng) LNGMAX = obj.lng;
if (LNGMIN > obj.lng) LNGMIN = obj.lng;
if (LATMAX < obj.lat) LATMAX = obj.lat;
if (LATMIN > obj.lat) LATMIN = obj.lat;
point.SpatialReference = MainForm2.CreateGeoCoordSys();
Idgen = m_graphicTracker.Add(point as IGeometry, ((IGraphicTrackerSymbol)((Place)MainForm2.PlaceTypesGIS[obj.type + obj.color + obj.iconSize]).SymbGIS[tabName]));
MainForm2.simpleTextSymbol.YOffset = 20;
m_graphicTracker.SetTextSymbol(Idgen, MainForm2.simpleTextSymbol);
m_graphicTracker.SetLabel(Idgen, obj.name);
foreach (RadListDataItem cb in cbLandEdit.Items)
if (((Zone_type)cb.Value).name == obj.name) ((Zone_type)cb.Value).driver_id = Idgen;
}
mapControl.Extent = MainForm2.ZoomTo(LNGMIN, LATMIN, LNGMAX, LATMAX);
}
}
catch (Exception ex)
{
SM.Debug("Error on put place on live:" + ex.ToString());
}
}
private void btSave_Click(object sender, EventArgs e)
{
Place res = new Place();
String idxchange = "0";
Boolean saveOK = true;
double lat = 0;
double lng = 0;
if (!OnNewLandMark) idxchange = ((Zone_type)((RadListDataItem)cbLandEdit.SelectedItem).Value).idx.ToString();
if ((txName.Text.Trim().Length >= 1) && (txName.Text.Trim() != "\\"))
{
try
{
res = smdbObj.test_place_exist(txName.Text, idxchange);
}
catch (Exception ex)
{
SM.Debug("Error Test on save from add new place:" + ex.ToString());
if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(MainForm2.returnLNGString("database"), MainForm2.returnLNGString("war"), MessageBoxButtons.OK, RadMessageIcon.Exclamation);
return;
}
try
{
saveOK = true;
lat = Convert.ToDouble(txLat.Value);
lng = Convert.ToDouble(txLng.Value);
}
catch (Exception ex2)
{
SM.Debug("File: AddPlace.cs Meth: btaddnewplace: " + ex2.ToString());
saveOK = false;
}
if (saveOK)
{
if ((lat > 90) || (lat < -90) || (lng > 180) || (lng < -180))
{
saveOK = false;
if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(messaddlatlongout);
}
}
if (saveOK)
{
if (res != null)
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
DialogResult dr2 = RadMessageBox.Show(this, messadd + "\r\n" +
lbDesc.Text + " = " + res.desc + "\r\n" +
lbLat.Text + " = " + res.lat.ToString() + "\r\n" +
lbLng.Text + " = " + res.lng.ToString() + "\r\n" +
messaddquiz, messaddname, MessageBoxButtons.YesNo, RadMessageIcon.Exclamation);
if (dr2 == DialogResult.No)
saveOK = false;
}
}
if (saveOK)
{
try
{
// get landmark type
KeyValuePair<Int32, LandmarkType> landType = (KeyValuePair<Int32, LandmarkType>)rlvIcons.SelectedItem.DataBoundItem;
if (idxchange != "0") smdbObj.Delete_Place(idxchange);
smdbObj.Insert_Place_GIS(txName.Text, txDesc.Text, Convert.ToDouble(txLat.Value), Convert.ToDouble(txLng.Value), /*((Place)((RadListDataItem)cbPlaceType.SelectedItem).Value).idx.ToString()*/ (landType.Value != null ? landType.Value.Idx + "" : "1") + "", txAddress.Text, MainForm2.userIDX/*, colorsList[rlvLandmarkColors.SelectedIndex], GetIconSize()*/);
Color color = Color.Black;
color = colorsList[rlvLandmarkColors.SelectedIndex];
String iconSize = rrbSmall.IsChecked ? "small" : (rrbMedium.IsChecked ? "medium" : "large");
// get landmark type
String iconName = landType.Value.IconName;
int iconIndex = landType.Value.Idx;
if (!CheckIfExistsIcon(color, iconSize, iconName, iconIndex))
{
CreateIcon(color, iconSize, iconName, iconIndex);
};
if (idxchange != "0")
{
Int32 tmp = smdbObj.Get_Last_Place_Insert();
smdbObj.Update_all_old_alarms(tmp.ToString(), idxchange);
smdbObj.Update_all_old_Reports(tmp.ToString(), idxchange,false);
}
smdbObj.get_land_and_ID_Hash();
EnabledNEW();
ReloadCombo(txName.Text);
PutAllLandmarks();
}
catch (Exception ex)
{
SM.Debug("Error on save from add new place:" + ex.ToString());
if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(MainForm2.returnLNGString("database"), MainForm2.returnLNGString("war"), MessageBoxButtons.OK, RadMessageIcon.Exclamation);
}
}
}
else
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(msgNotSave, msgWar, MessageBoxButtons.OK, RadMessageIcon.Error);
}
}
private void EnabledNEW()
{
OnNewLandMark = false;
cbLandEdit.Enabled = true;
btNew.Enabled = true;
btDelete.Text = MainForm2.returnLNGString("SMSDelete");
}
private Int32 forceID = -1;
private String FixLandName(String Name)
{
String ret = Name;
ret = ret.ToLower();
ret = ret.Replace(" ", "_");
ret = ret.Insert(ret.Length, ".png");
return ret;
}
private String OldtxLat = "";
private String OldtxLng = "";
private String OldtxName = "";
private String OldtxPlaceType = "";
private void SelectionLand()
{
if (!Loaddata)
{
if (((OldtxLat != "") && (OldtxLng != "") && (OldtxName != "") && (OldtxPlaceType != "")) && ((OldtxLat != txLat.Value.ToString()) || (OldtxLng != txLng.Value.ToString()) /*|| (OldtxPlaceType != cbPlaceType.Text)*/))
{
//mapGoogles.Navigate("javascript:void(GWTcallback('updateDataset,LandView," + MainForm2.FixDouble(OldtxLat) + "," + MainForm2.FixDouble(OldtxLng) + "," + MainForm2.FixComma(OldtxName) + "," + MainForm2.FixComma(txDesc.Text) + "," + FixLandName(OldtxPlaceType) + "'))");
//mapGoogles.Navigate("javascript:void(GWTcallback('putOnMap,false,LandView'))");
//put place on the map OR UDPATE made on save or delete
SM.Debug("OLD SELECTION UPDATE");
}
try
{
if (cbLandEdit.SelectedItem == null) return;
SM.Debug("NEW SELECTION UPDATE");
ArrayList values = smdbObj.get_place(((Zone_type)((RadListDataItem)cbLandEdit.SelectedItem).Value).idx);
txName.Text = values[0] as String;
txDesc.Text = values[1] as String;
//txLat.Text = ((Double)values[2]).ToString();
txLat.Value = (decimal)((double)values[2]);
txLng.Value = (decimal)((double)values[3]);
//txLng.Text = ((Double)values[3]).ToString();
txAddress.Text = values[4] as String;
OldtxLat = txLat.Text;
OldtxLng = txLng.Text;
OldtxName = cbLandEdit.Text;
//int cont = -1;
//String NameType = "";
//foreach (RadListDataItem obj in cbPlaceType.Items)
//{
// cont++;
// Place tmp = (Place)obj.Value;
// if (tmp.idx == (Int32)values[5])
// {
// cbPlaceType.SelectedIndex = cont;
// NameType = tmp.type;
// break;
// }
//}
//OldtxPlaceType = NameType;
List<LandmarkUI> allLandmarks = smdbObj.GetAllLandmarks();
foreach (LandmarkUI land in allLandmarks)
{
if (land.Name == txName.Text)
{
// set color, icon and icon size
rlvLandmarkColors.SelectedIndex = colorsList.IndexOf(land.Color);
// check to see if the type of landmark exists and then get the index of landmark type
// from the alfabethicall order
rlvIcons.SelectedIndex = landmarkTypesList.ContainsKey(land.TypeIdx) ? landmarkTypesList[land.TypeIdx].CrtIdx : 0;
// change the toggle buttons state
ChangeIconSizeToggleButtons(land.Size);
break;
}
}
}
catch (Exception ex)
{
SM.Debug("Error load zone:" + ex.ToString());
}
if (loadfinish) mapControl.Extent = MainForm2.ZoomTo(Convert.ToDouble(txLng.Value), Convert.ToDouble(txLat.Value), Convert.ToDouble(txLng.Value), Convert.ToDouble(txLat.Value));
}
}
private void btDelete_Click(object sender, EventArgs e)
{
if (OnNewLandMark)
{
EnabledNEW();
ReloadCombo("");
}
else
{
if (cbLandEdit.Items.Count > 0)
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
DialogResult dr2 = RadMessageBox.Show(this, mess1 + "\r\n" +
col0 + " = " + txName.Text + "\r\n" +
col1 + " = " + txDesc.Text + "\r\n" +
col2 + " = " + txLat.Value.ToString() + "\r\n" +
col3 + " = " + txLng.Value.ToString() + "\r\n" +
//col4 + " = " + cbPlaceType.Text + "\r\n" +
mess2, mess5, MessageBoxButtons.YesNo, RadMessageIcon.Exclamation);
if (dr2 == DialogResult.Yes)
{
try
{
smdbObj.Delete_Place(((Zone_type)((RadListDataItem)cbLandEdit.SelectedItem).Value).idx.ToString());
MainForm2.LandIDHash.Remove(((Zone_type)((RadListDataItem)cbLandEdit.SelectedItem).Value).idx);
PutAllLandmarks();
}
catch (Exception ex)
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(MainForm2.returnLNGString("database"), MainForm2.returnLNGString("war"), MessageBoxButtons.OK, RadMessageIcon.Exclamation);
SM.Debug("EX:"+ex.ToString());
}
EnabledNEW();
ReloadCombo("");
}
}
}
}
private void SafeConvertStringToDouble(String slat,String slng,out Double lat,out Double lng)
{
Double tmplat = 0;
Double tmplng = 0;
try
{
tmplat = Convert.ToDouble(slat);
tmplng = Convert.ToDouble(slng);
}
catch (Exception ex)
{
SM.Debug("Error convert double for google" + ex.ToString());
}
if ((tmplat > 90) || (tmplng > 180) || (tmplat < -90) || (tmplng < -180))
{
try
{
tmplat = Convert.ToDouble(slat.Replace('.', ','));
tmplng = Convert.ToDouble(slng.Replace('.', ','));
}
catch (Exception ex)
{
SM.Debug("Error convert double for google after convert . with ," + ex.ToString());
}
}
lat = tmplat;
lng = tmplng;
}
private void MapPanelLand_Click(object sender, EventArgs e)
{
LandMarkNotSpecPoint = true;
PointForZone = false;
}
private object Missing = Type.Missing;
private IElement element = null;
private volatile Hashtable ElementsZone = new Hashtable();
private volatile float LNGMAX = -181;
private volatile float LNGMIN = 181;
private volatile float LATMAX = -91;
private volatile float LATMIN = 90;
private ArrayList PositionList = new ArrayList();
private void populateList()
{
IGraphicsContainer graphicsContainer = (IGraphicsContainer)mapControl.ActiveView;
PointList.Rows.Clear();
LNGMAX = -181; LNGMIN = 181; LATMAX = -91; LATMIN = 90;
int cont = 0;
IPolyline newPath = new PolylineClass();
IPointCollection newPointCollection = newPath as IPointCollection;
Boolean first = true;
Double LAT = 0, LNG = 0;
Double FirstLAT = 0, FirstLNG = 0;
try
{
if (loadfinish)
{
PINSET.RemoveAll();
PositionList.Clear();
}
foreach (PointonZone obj in Newarr)
{
if (first)
{
FirstLAT = obj.lat;
FirstLNG = obj.lng;
first = false;
}
LAT = obj.lat;
LNG = obj.lng;
PointList.Rows.AddNew();
PointList.Rows[cont].Cells[0].Value = (cont + 1).ToString();
PointList.Rows[cont].Cells[1].Value = global::Dispatcher.Properties.Resources.map;
PointList.Rows[cont].Cells[2].Value = Math.Round(obj.lat, 5).ToString();
PointList.Rows[cont].Cells[3].Value = Math.Round(obj.lng, 5).ToString();
PointList.Rows[cont].Cells[4].Value = obj.idx;
PointList.Rows[cont].Cells[5].Value = global::Dispatcher.Properties.Resources.trashmic1;
ESRI.ArcGIS.Geometry.IPoint fromPoint = new ESRI.ArcGIS.Geometry.PointClass();
fromPoint.PutCoords(obj.lng, obj.lat);
fromPoint.SpatialReference = MainForm2.CreateGeoCoordSys();
newPointCollection.AddPoint(fromPoint, ref Missing, ref Missing);
if (loadfinish)
{
if (PINSYM == null) Create_a_PINSYM();
Int32 GISID = PINSET.Add(fromPoint as IGeometry, PINSYM);
PINSET.SetLabel(GISID, (cont + 1).ToString());
PositionList.Add(new POSIDGIS(GISID, new SMposition(Math.Round(obj.lat, 5), Math.Round(obj.lng, 5),0)));
}
cont++;
LNGMAX = Math.Max(LNGMAX, (float)obj.lng);
LNGMIN = Math.Min(LNGMIN, (float)obj.lng);
LATMAX = Math.Max(LATMAX, (float)obj.lat);
LATMIN = Math.Min(LATMIN, (float)obj.lat);
}
PointList.TableElement.ScrollToRow(0);
if (loadfinish)
{
if ((LAT != FirstLAT) || (LNG != FirstLNG))
{
ESRI.ArcGIS.Geometry.IPoint fromPoint = new ESRI.ArcGIS.Geometry.PointClass();
fromPoint.PutCoords(FirstLNG, FirstLAT);
fromPoint.SpatialReference = MainForm2.CreateGeoCoordSys();
newPointCollection.AddPoint(fromPoint, ref Missing, ref Missing);
}
foreach (String obj in ElementsZone.Keys)
graphicsContainer.DeleteElement((IElement)ElementsZone[obj]);
ElementsZone.Clear();
if (!ckHide.Checked) showOtherZone();
System.Threading.Thread.Sleep(10);
//if (cbZoneEdit.SelectedItem != null)
// {
ESRI.ArcGIS.Display.IColor colorX = new RgbColorClass() { Red = color.R, Green = color.G, Blue = color.B }; // Implicit Cast
ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
simpleLineSymbol.Color = colorX;
simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
simpleLineSymbol.Width = 3;
ILineElement lineElement = new LineElementClass();
lineElement.Symbol = simpleLineSymbol;
element = (IElement)lineElement; // Explicit Cast
element.Geometry = (IPolyline)newPointCollection;
graphicsContainer.AddElement(element, 0);
if (!ElementsZone.Contains(ZoneActiv))
ElementsZone.Add(ZoneActiv, element);
mapControl.ActiveView.Refresh();
if (!StopTimer) mapControl.Extent = MainForm2.ZoomTo(LNGMIN, LATMIN, LNGMAX, LATMAX);
// }
}
}
catch (Exception ex)
{
SM.Debug("Unable to populate list:"+ex.ToString());
}
}
private String FixInt(Int32 nr)
{
if (nr < 10) return "0" + nr.ToString();
else return nr.ToString();
}
private String ZoneActiv="tmpPol";
private void SelectZone()
{
try
{
if (cbZoneEdit.SelectedItem == null) return;
Newarr.Clear();
foreach (PointonZone obj in (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).arrSc_id)
Newarr.Add(obj);
rlvGeofenceBorderColors.SelectedIndex = (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).color;
color = getColorid(colorsList, (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).color);
idxzone = (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).id;
useridxzone = (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).useridx;
populateList();
txNameZone.Text = cbZoneEdit.Text;
// select alert type
rcbddAlertType.Items[0].Checked = ((((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).AlarmType == (int)GeofenceUI.AlertType.IN
|| (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).AlarmType == (int)GeofenceUI.AlertType.IN_OUT);
rcbddAlertType.Items[1].Checked = ((((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).AlarmType == (int)GeofenceUI.AlertType.OUT
|| (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).AlarmType == (int)GeofenceUI.AlertType.IN_OUT);
if ((((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).sentmsg) ckTextMessage.Checked = true;
else ckTextMessage.Checked = false;
if ((((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).sentemail) ckEmail.Checked = true;
else ckEmail.Checked = false;
txMsgbody.Text = (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).msgbody;
txEmail.Text = (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).email;
txSubj.Text = (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).subj;
txBody.Text = (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).body;
txMsgbody2.Text = (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).msgbody2;
if ((((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).sentmsg2) ckSingleText.Checked = true;
else ckSingleText.Checked = false;
if ((((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).speed != 0) ckSpeedLimit.Checked = true;
else ckSpeedLimit.Checked = false;
tbSpeed.Value = (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).speed;
String listOfUnits = (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).unitids;
String[] tmp = listOfUnits.Split(',');
Hashtable tmpHashName = new Hashtable();
if (tmp.Count() > 1)
{
for (Int32 i = 0; i < tmp.Count() - 1; i++)
tmpHashName.Add((String)MainForm2.VehIDHash[Convert.ToInt32(tmp[i])], "somedata");
}
cbVehNameFleet.Text = "";
string unitsName = "";
for (Int32 i = 0; i < cbVehNameFleet.Items.Count; i++)
{
if (tmpHashName[(String)((CustomListDataItem)cbVehNameFleet.Items[i]).Text] != null)
{
((CustomListDataItem)cbVehNameFleet.Items[i]).Checked = true;
Console.WriteLine("Pune un check");
unitsName += (cbVehNameFleet.Items[i]).Text + ";";
}
else ((CustomListDataItem)cbVehNameFleet.Items[i]).Checked = false;
}
cbVehNameFleet.Text = unitsName;
}
catch (Exception ex)
{
SM.Debug("Error on select zone:" + ex.ToString());
}
}
private void changeSelection()
{
if ((OnNew)&&(loadfinish))
{
if (Newarr.Count >= 2)
{
try
{
IPolyline newPath = new PolylineClass();
IPointCollection newPointCollection = newPath as IPointCollection;
if (ElementsZone[ZoneActiv] != null)
{
graphicsContainer.DeleteElement((IElement)ElementsZone[ZoneActiv]);
ElementsZone.Remove(ZoneActiv);
}
Boolean first = true;
Double LAT = 0, LNG = 0;
Double FirstLAT = 0, FirstLNG = 0;
Int32 cont = 0;
PositionList.Clear();
PINSET.RemoveAll();
foreach (PointonZone obj in Newarr)
{
if (first)
{
FirstLAT = obj.lat;
FirstLNG = obj.lng;
first = false;
}
LAT = obj.lat;
LNG = obj.lng;
ESRI.ArcGIS.Geometry.IPoint fromPoint = new ESRI.ArcGIS.Geometry.PointClass();
fromPoint.PutCoords(obj.lng, obj.lat);
fromPoint.SpatialReference = MainForm2.CreateGeoCoordSys();
newPointCollection.AddPoint(fromPoint, ref Missing, ref Missing);
if (loadfinish)
{
if (PINSYM == null) Create_a_PINSYM();
Int32 GISID = PINSET.Add(fromPoint as IGeometry, PINSYM);
PINSET.SetLabel(GISID, (cont + 1).ToString());
PositionList.Add(new POSIDGIS(GISID, new SMposition(Math.Round(obj.lat, 5), Math.Round(obj.lng, 5),0)));
}
cont++;
}
if ((LAT != FirstLAT) || (LNG != FirstLNG))
{
ESRI.ArcGIS.Geometry.IPoint fromPoint = new ESRI.ArcGIS.Geometry.PointClass();
fromPoint.PutCoords(FirstLNG, FirstLAT);
fromPoint.SpatialReference = MainForm2.CreateGeoCoordSys();
newPointCollection.AddPoint(fromPoint, ref Missing, ref Missing);
}
ESRI.ArcGIS.Display.IColor colorX = new RgbColorClass() { Red = color.R, Green = color.G, Blue = color.B }; // Implicit Cast
ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
simpleLineSymbol.Color = colorX;
simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
simpleLineSymbol.Width = 3;
ILineElement lineElement = new LineElementClass();
lineElement.Symbol = simpleLineSymbol;
element = (IElement)lineElement; // Explicit Cast
element.Geometry = (IPolyline)newPointCollection;
graphicsContainer.AddElement(element, 0);
if (!ElementsZone.Contains(ZoneActiv))
ElementsZone.Add(ZoneActiv, element);
mapControl.ActiveView.Refresh();
System.Threading.Thread.Sleep(10);
}
catch (Exception ex)
{
SM.Debug("Erorr in change select:"+ex.ToString());
}
}
}
}
private void PointList_CellClick(object sender, GridViewCellEventArgs e)
{
if (OnNew)
{
if (e.ColumnIndex == 1)
{
RowToUpdate = e.RowIndex;
//mapControl.MousePointer = GeoPointer.geoPointerCrosshair;
LandMarkNotSpecPoint = false;
PointForZone = true;
}
if (e.ColumnIndex == 5)
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
DialogResult dr2 = RadMessageBox.Show(this, messPointToDel + "\r\n" +
lbLat.Text + " = " + PointList.Rows[e.RowIndex].Cells[2].Value.ToString() + "\r\n" +
lbLng.Text + " = " + PointList.Rows[e.RowIndex].Cells[3].Value.ToString() + "\r\n" +
mess12, mess16, MessageBoxButtons.YesNo, RadMessageIcon.Exclamation);
if (dr2 == DialogResult.Yes)
{
try
{
Newarr.RemoveAt(e.RowIndex);
PointList.Rows[e.RowIndex].Delete();
for (int i = 0; i < PointList.Rows.Count; i++)
PointList.Rows[i].Cells[0].Value = (i + 1).ToString();
changeSelection();
}
catch (Exception ex)
{ SM.Debug("Error on delete point:" + ex.ToString()); }
}
}
}
}
private void ShowAllZone()
{
try
{
foreach (RadListDataItem obj2 in cbZoneEdit.Items)
{
IPolyline newPath = new PolylineClass();
IPointCollection newPointCollection = newPath as IPointCollection;
Boolean first = true;
Double LAT = 0, LNG = 0;
Double FirstLAT = 0, FirstLNG = 0;
foreach (PointonZone obj in (((ZoneClass)obj2.Value)).new_arrSc_id)
{
if (first)
{
FirstLAT = obj.lat;
FirstLNG = obj.lng;
first = false;
}
LAT = obj.lat;
LNG = obj.lng;
ESRI.ArcGIS.Geometry.IPoint fromPoint = new ESRI.ArcGIS.Geometry.PointClass();
fromPoint.PutCoords(obj.lng, obj.lat);
fromPoint.SpatialReference = MainForm2.CreateGeoCoordSys();
newPointCollection.AddPoint(fromPoint, ref Missing, ref Missing);
}
if ((LAT != FirstLAT) || (LNG != FirstLNG))
{
ESRI.ArcGIS.Geometry.IPoint fromPoint = new ESRI.ArcGIS.Geometry.PointClass();
fromPoint.PutCoords(FirstLNG, FirstLAT);
fromPoint.SpatialReference = MainForm2.CreateGeoCoordSys();
newPointCollection.AddPoint(fromPoint, ref Missing, ref Missing);
}
//Color colortmp = (new GetColorID()).getColorid(((ZoneClass)obj2.Value).color, true);
Color colortmp = getColorid(colorsList, ((ZoneClass)obj2.Value).color);
ESRI.ArcGIS.Display.IColor colorX = new RgbColorClass() { Red = colortmp.R, Green = colortmp.G, Blue = colortmp.B }; // Implicit Cast
ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
simpleLineSymbol.Color = colorX;
simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
simpleLineSymbol.Width = 3;
ILineElement lineElement = new LineElementClass();
lineElement.Symbol = simpleLineSymbol;
element = (IElement)lineElement; // Explicit Cast
element.Geometry = (IPolyline)newPointCollection;
graphicsContainer.AddElement(element, 0);
ElementsZone.Add(((ZoneClass)obj2.Value).Name, element);
System.Threading.Thread.Sleep(10);
}
}
catch (Exception ex)
{
SM.Debug("Ex:"+ex.ToString());
}
}
private void showOtherZone()
{
try
{
foreach (RadListDataItem obj2 in cbZoneEdit.Items)
{
if (((ZoneClass)obj2.Value).id != idxzone)
{
IPolyline newPath = new PolylineClass();
IPointCollection newPointCollection = newPath as IPointCollection;
Boolean first = true;
Double LAT = 0, LNG = 0;
Double FirstLAT = 0, FirstLNG = 0;
foreach (PointonZone obj in (((ZoneClass)obj2.Value)).new_arrSc_id)
{
if (first)
{
FirstLAT = obj.lat;
FirstLNG = obj.lng;
first = false;
}
LAT = obj.lat;
LNG = obj.lng;
ESRI.ArcGIS.Geometry.IPoint fromPoint = new ESRI.ArcGIS.Geometry.PointClass();
fromPoint.PutCoords(obj.lng, obj.lat);
fromPoint.SpatialReference = MainForm2.CreateGeoCoordSys();
newPointCollection.AddPoint(fromPoint, ref Missing, ref Missing);
}
if ((LAT != FirstLAT) || (LNG != FirstLNG))
{
ESRI.ArcGIS.Geometry.IPoint fromPoint = new ESRI.ArcGIS.Geometry.PointClass();
fromPoint.PutCoords(FirstLNG, FirstLAT);
fromPoint.SpatialReference = MainForm2.CreateGeoCoordSys();
newPointCollection.AddPoint(fromPoint, ref Missing, ref Missing);
}
//Color colortmp = (new GetColorID()).getColorid(((ZoneClass)obj2.Value).color, true);
Color colortmp = getColorid(colorsList, ((ZoneClass)obj2.Value).color);
ESRI.ArcGIS.Display.IColor colorX = new RgbColorClass() { Red = colortmp.R, Green = colortmp.G, Blue = colortmp.B }; // Implicit Cast
ESRI.ArcGIS.Display.ISimpleLineSymbol simpleLineSymbol = new ESRI.ArcGIS.Display.SimpleLineSymbolClass();
simpleLineSymbol.Color = colorX;
simpleLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;
simpleLineSymbol.Width = 3;
ILineElement lineElement = new LineElementClass();
lineElement.Symbol = simpleLineSymbol;
element = (IElement)lineElement; // Explicit Cast
element.Geometry = (IPolyline)newPointCollection;
graphicsContainer.AddElement(element, 0);
ElementsZone.Add(((ZoneClass)obj2.Value).Name, element);
System.Threading.Thread.Sleep(10);
}
}
}
catch (Exception ex)
{
SM.Debug("Ex:"+ex.ToString());
}
}
private void ckHide_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
populateList();
}
private Boolean realNEW = false;
private void btZoneNew_Click(object sender, EventArgs e)
{
btZoneDel.Enabled = true;
btZoneEdit.Enabled = true;
PointList.Rows.Clear();
PointList.Refresh();
ZoneActiv = "tmpPol";
MainForm2.ForceSaveZone = true;
Newarr.Clear();
idxzone = 0;
useridxzone = MainForm2.userIDX;
if (loadfinish)
{
try
{
foreach (String obj in ElementsZone.Keys)
graphicsContainer.DeleteElement((IElement)ElementsZone[obj]);
ElementsZone.Clear();
if (!ckHide.Checked) showOtherZone();
}
catch (Exception ex)
{
SM.Debug("Ex:"+ex.ToString());
}
}
txNameZone.Text = MainForm2.returnLNGString("newname");
foreach (RadListDataItem item in rcbddAlertType.Items)
item.Selected = true;
ckTextMessage.Checked = false;
ckSingleText.Checked = false;
ckEmail.Checked = false;
txMsgbody.Text = "";
txMsgbody2.Text = "";
txEmail.Text = "";
txSubj.Text = "";
txBody.Text = "";
ckSpeedLimit.Checked = false;
tbSpeed.Value = 0;
cbVehNameFleet.Text = "";
for (Int32 i = 0; i < cbVehNameFleet.Items.Count; i++)
((CustomListDataItem)cbVehNameFleet.Items[i]).Checked = false;
NewDisable();
realNEW = true;
}
private Boolean OnNew = false;
private void btZoneEdit_Click(object sender, EventArgs e)
{
if (OnNew)
{
if (loadfinish)
{
try
{
graphicsContainer.DeleteElement((IElement)ElementsZone[ZoneActiv]);
ElementsZone.Remove(ZoneActiv);
}
catch (Exception ex)
{
SM.Debug("Eroror on delete zone:"+ex.ToString());
}
}
NewEnabled();
ReloadComboZone(ZoneActiv);
realNEW = false;
StopTimer = false;
PointForNewZone = false;
btAddPoint.Text = "Add Points";
}
else
{
ZoneActiv = txNameZone.Text;
// Newarr = (((ZoneClass)((RadComboBoxItem)cbZoneEdit.SelectedItem).Value)).arrSc_id;
NewDisable(true);
}
MainForm2.ForceSaveZone = true;
}
private void NewEnabled()
{
/* cbZoneEdit.Visible = true;
txNameZone.Visible = false;
btZoneNew.Enabled = true;
btZoneEdit.Text = MainForm2.returnLNGString("edit");
btZoneDel.Text = MainForm2.returnLNGString("SMSDelete");
OnNew = false;
cbColor.Enabled = false;
//splitPanel1.MinimumSize = new Size(splitPanel2.Width, 113);
//splitPanel1.MaximumSize = new Size(splitPanel2.Width, 113);*/
StopTimer = false;
PointForNewZone = false;
cbZoneEdit.Visible = true;
txNameZone.Visible = radLabel2.Visible = false;
pb_DeleteGeofence.Enabled = cbZoneEdit.Enabled = true;
btZoneNew.Enabled = true;
btZoneEdit.Text = MainForm2.returnLNGString("edit");
btZoneDel.Text = MainForm2.returnLNGString("SMSDelete");
OnNew = false;
/*cbColor.Enabled = false;*/
rlvGeofenceBorderColors.Enabled = false;
ckHide.Enabled = true;
ckEmail.Enabled = false;
ckTextMessage.Enabled = false;
ckSingleText.Enabled = false;
txBody.Enabled = false;
txEmail.Enabled = false;
txMsgbody.Enabled = false;
txMsgbody2.Enabled = false;
txSubj.Enabled = false;
cbVehNameFleet.Enabled = false;
btAddPoint.Enabled = false;
rcbddAlertType.Enabled = false;
ckSpeedLimit.Enabled = false;
tbSpeed.Enabled = false;
lbSpeedName.Enabled = false;
}
private void NewDisable(bool editMode = false)
{
/* cbZoneEdit.Visible = false;
txNameZone.Visible = true;
btZoneNew.Enabled = false;
btZoneDel.Text = MainForm2.returnLNGString("save");
btZoneEdit.Text = MainForm2.returnLNGString("cancel");
OnNew = true;
cbColor.Enabled = true;
//splitPanel1.MinimumSize = new Size(splitPanel2.Width, 138);
//splitPanel1.MaximumSize = new Size(splitPanel2.Width, 138);*/
//stop timer comment
//StopTimer = true;
txNameZone.Visible = radLabel2.Visible = true;
pb_DeleteGeofence.Enabled = cbZoneEdit.Enabled = false;
btZoneNew.Enabled = false;
btZoneDel.Text = MainForm2.returnLNGString("save");
btZoneEdit.Text = MainForm2.returnLNGString("cancel");
OnNew = true;
/*cbColor.Enabled = true;*/
rlvGeofenceBorderColors.Enabled = true;
ckHide.Enabled = false;
ckEmail.Enabled = true;
ckTextMessage.Enabled = true;
ckSingleText.Enabled = true;
txBody.Enabled = true;
txEmail.Enabled = true;
txMsgbody.Enabled = true;
txMsgbody2.Enabled = true;
txSubj.Enabled = true;
cbVehNameFleet.Enabled = true;
btAddPoint.Enabled = true;
rcbddAlertType.Enabled = true;
ckSpeedLimit.Enabled = true;
tbSpeed.Enabled = true;
lbSpeedName.Enabled = true;
ckSingleText.Enabled = true;
ckSpeedLimit.Enabled = true;
ckTextMessage.Enabled = true;
ckEmail.Enabled = true;
if (!editMode)
{
ckSingleText.Checked = false;
ckSpeedLimit.Checked = false;
ckTextMessage.Checked = false;
ckEmail.Checked = false;
tbSpeed.Enabled = false;
lbSpeedName.Enabled = false;
txMsgbody2.Enabled = false;
txMsgbody.Enabled = false;
cbVehNameFleet.Enabled = false;
txEmail.Enabled = false;
txSubj.Enabled = false;
txBody.Enabled = false;
}
tbSpeed.Enabled = lbSpeedName.Enabled = ckSpeedLimit.Checked;
txMsgbody2.Enabled = ckSingleText.Checked;
txMsgbody.Enabled = cbVehNameFleet.Enabled = ckTextMessage.Checked;
txEmail.Enabled = txSubj.Enabled = txBody.Enabled = ckEmail.Checked;
}
private Int32 idxzone =0;
private Int32 useridxzone = 0;
private Int32 alarmtypeINT = 3;
private ArrayList Newarr = new ArrayList();
private void btZoneDel_Click(object sender, EventArgs e)
{
if (OnNew)
{
//save zone
String MsgBody = "";
String MsgBody2 = "";
String Email = "";
String Body = "";
String Subject = "";
Boolean saveOK = true;
foreach (Int32 obj in MainForm2.ZoneIDHash.Keys)
{
if (((ZoneClass)MainForm2.ZoneIDHash[obj]).name.ToUpper() == txNameZone.Text.ToUpper())
if (idxzone != 0)
{
if (idxzone != obj)
{
saveOK = false;
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(mess4 + " " + '"' + txNameZone.Text + '"' + " " + mess6);
break;
}
}
else
{
saveOK = false;
RadMessageBox.Show(mess4 + " " + '"' + txNameZone.Text + '"' + " " + mess6);
break;
}
}
if ((saveOK) && (Newarr.Count < 3))
{
RadMessageBox.Show(need3Points, msgWar, MessageBoxButtons.OK, RadMessageIcon.Error);
saveOK = false;
}
if (ckEmail.Checked && saveOK)
{
if (txEmail.Text.Contains('@') && txEmail.Text.Contains('.'))
{
SM.Debug("Valid email address");
if (txEmail.Text.IndexOf('@') != txEmail.Text.LastIndexOf('@'))
{
if (!txEmail.Text.Contains(';'))
{
SM.Debug("Be sure you split the email's");
RadMessageBox.Show(msgSplitEmail);
saveOK = false;
}
}
}
else
{
RadMessageBox.Show(msgInvalidEmail);
SM.Debug("Invalid email address");
saveOK = false;
}
if (saveOK)
{
Body = txBody.Text;
Subject = txSubj.Text;
Email = txEmail.Text;
}
}
if (saveOK)
{
if ((txNameZone.Text.Trim().Length >= 1) && (txNameZone.Text.Trim() != "\\"))
{
NewEnabled();
try
{
if (idxzone != 0) smdbObj.Delete_Zone(idxzone.ToString());
alarmtypeINT = (int)GeofenceUI.AlertType.NONE;
if (rcbddAlertType.Items[0].Checked && rcbddAlertType.Items[1].Checked)
alarmtypeINT = (int)GeofenceUI.AlertType.IN_OUT;
else if (rcbddAlertType.Items[0].Checked)
alarmtypeINT = (int)GeofenceUI.AlertType.IN;
else if (rcbddAlertType.Items[1].Checked)
alarmtypeINT = (int)GeofenceUI.AlertType.OUT;
if (ckSingleText.Checked) MsgBody2 = txMsgbody2.Text;
String listOfUnits = "";
String imeilist = "";
cbVehNameFleet.Text = "";
for (Int32 i = 0; i < cbVehNameFleet.Items.Count; i++)
{
if (((CustomListDataItem)cbVehNameFleet.Items[i]).Checked)
{
listOfUnits += ((Vehicle)MainForm2.vehicleHT[(String)((CustomListDataItem)cbVehNameFleet.Items[i]).Text]).sc_id.ToString() + ",";
imeilist += ((Vehicle)MainForm2.vehicleHT[(String)((CustomListDataItem)cbVehNameFleet.Items[i]).Text]).IMEI + ",";
}
}
if (ckTextMessage.Checked) MsgBody = txMsgbody.Text;
else
{
listOfUnits = "";
imeilist = "";
}
Int32 Speedval = 0;
if (!ckSpeedLimit.Checked) tbSpeed.Value = 0;
Speedval = (Int32)tbSpeed.Value;
if (MainForm2.isInMile) Speedval = (Int32)Math.Round(Speedval * 1.60934);
/// foreach ot put ID's
String newIdx = smdbObj.Insert_Zone(txNameZone.Text.Replace("\'", "\'\'"), /*cbColor.SelectedIndex*/ rlvGeofenceBorderColors.SelectedIndex, Newarr, MainForm2.userIDX, alarmtypeINT, ckTextMessage.Checked, MsgBody.Replace("\'", "\'\'"), listOfUnits, ckEmail.Checked, Email.Replace("\'", "\'\'"), Subject.Replace("\'", "\'\'"), Body.Replace("\'", "\'\'"), imeilist, ckSingleText.Checked, MsgBody2.Replace("\'", "\'\'"), Speedval);
if (idxzone != 0)
{
smdbObj.Update_all_old_alarms(newIdx, idxzone.ToString());
smdbObj.Update_all_old_Reports(newIdx, idxzone.ToString(), true);
}
MainForm2.ZoneIDHash = smdbObj.get_all_zone();
if (loadfinish)
{
if (ElementsZone[ZoneActiv] != null)
{
graphicsContainer.DeleteElement((IElement)ElementsZone[ZoneActiv]);
ElementsZone.Remove(ZoneActiv);
}
}
ReloadComboZone(txNameZone.Text);
// trebuei sa updatez alarme si Reports
// update the name
StopTimer = false;
PointForNewZone = false;
btAddPoint.Text = "Add Points";
}
catch (Exception ex)
{
SM.Debug("Erorr insert zone:" + ex.ToString());
}
}
else
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(msgNotSaveZone, msgWar, MessageBoxButtons.OK, RadMessageIcon.Exclamation);
}
MainForm2.ForceSaveZone = false;
}
//end save zone
}
else //delete comanda
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
Boolean validanswer = true;
if (MainForm2.userIDX != useridxzone)
{
validanswer = false;
TabName tmp = new TabName((String)MainForm2.userIDHash[useridxzone], true);
tmp.ShowDialog();
password = tmp.Name;
if (password.ToUpper().CompareTo(((String)MainForm2.passUserHash[useridxzone]).ToUpper()) == 0)
validanswer = true;
else RadMessageBox.Show(MainForm2.returnLNGString("passIsWrong"), MainForm2.returnLNGString("error"), MessageBoxButtons.OK, RadMessageIcon.Error);
}
if (validanswer)
{
DialogResult dr2 = RadMessageBox.Show(this, mess11 + " " + '"' + cbZoneEdit.Text + '"' + " " + messWill + "\r\n" + mess12, mess15, MessageBoxButtons.YesNo, RadMessageIcon.Exclamation);
if (dr2 == DialogResult.Yes)
{
try
{
smdbObj.Delete_Zone(((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value).id.ToString());
smdbObj.Delete_Zone_Alarm(((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value).id.ToString());
smdbObj.Delete_Zone_Reports(((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value).id.ToString());
MainForm2.ZoneIDHash.Remove(((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value).id);
}
catch (Exception ex)
{
RadMessageBox.Show(MainForm2.returnLNGString("database"), MainForm2.returnLNGString("war"), MessageBoxButtons.OK, RadMessageIcon.Exclamation);
SM.Debug("Ex:" + ex.ToString());
}
ReloadComboZone("");
}
}
}
}
public void ForceSave()
{
Console.WriteLine("Force Save GIS");
try
{
if (!StopClicked)
{
StopTimer = false;
PointForNewZone = false;
btAddPoint.Text = "Add Points";
populateList();
StopClicked = true;
}
}
catch (Exception ex)
{
Console.WriteLine("Error on stop add points:" + ex.ToString());
}
if ((Newarr.Count >= 3))
{
if ((txNameZone.Text.Trim().ToUpper().Length < 1) || (txNameZone.Text.Trim().ToUpper().CompareTo("NEW") == 0))
txNameZone.Text = "TempSave_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Second;
Console.WriteLine("Force Save GIS step2");
if ((txNameZone.Text.Trim().Length >= 1) && (txNameZone.Text.Trim() != "\\"))
{
NewEnabled();
try
{
if (idxzone != 0) smdbObj.Delete_Zone(idxzone.ToString());
String newIdx = smdbObj.Insert_Zone(txNameZone.Text, /*cbColor.SelectedIndex*/ rlvGeofenceBorderColors.SelectedIndex, Newarr, MainForm2.userIDX, 3, false, "", "", false, "", "", "", "", false, "", 0);
if (idxzone != 0)
{
smdbObj.Update_all_old_alarms(newIdx, idxzone.ToString());
smdbObj.Update_all_old_Reports(newIdx, idxzone.ToString(),true);
}
MainForm2.ZoneIDHash = smdbObj.get_all_zone();
if (loadfinish)
{
if (ElementsZone[ZoneActiv] != null)
{
graphicsContainer.DeleteElement((IElement)ElementsZone[ZoneActiv]);
ElementsZone.Remove(ZoneActiv);
}
}
ReloadComboZone(txNameZone.Text);
}
catch (Exception ex)
{
SM.Debug("Erorr insert zone:" + ex.ToString());
}
}
}
MainForm2.ForceSaveZone = false;
}
private Boolean putNewOnMapBool = false;
private void btNew_Click(object sender, EventArgs e)
{
OldtxName = "";
txName.Text = MainForm2.returnLNGString("newname");
txDesc.Text = MainForm2.returnLNGString("newname");
txLat.Text = "";
txLng.Text = "";
txAddress.Text = "";
//cbPlaceType.SelectedIndex = 0;
OnNewLandMark = true;
putNewOnMapBool = false;
cbLandEdit.Enabled = false;
btNew.Enabled = false;
btSave.Enabled = true;
btDelete.Enabled = true;
MapPanelLand.Enabled = true;
btDelete.Text = MainForm2.returnLNGString("cancel");
}
private void txNameZone_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsLetterOrDigit(e.KeyChar))
{
// Digits are OK
}
else if (e.KeyChar == '\b')
{
// Backspace key is OK
}
else if (e.KeyChar == ' ')
{
}
else
{
e.Handled = true;
}
}
private void txName_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsLetterOrDigit(e.KeyChar))
{
// Digits are OK
}
else if (e.KeyChar == '\b')
{
// Backspace key is OK
}
else if (e.KeyChar == ' ')
{
}
else
{
e.Handled = true;
}
}
private void txDesc_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsLetterOrDigit(e.KeyChar))
{
// Digits are OK
}
else if (e.KeyChar == '\b')
{
// Backspace key is OK
}
else if (e.KeyChar == ' ')
{
}
else
{
e.Handled = true;
}
}
private IGraphicTrackerSymbol PINSYM = null;
private PlaceSymbolsGIS placeSymb = null;
private void Create_a_PINSYM()
{
IColor color = new RgbColorClass() { Red = 0, Green = 0, Blue = 0 };
//stdole.IFontDisp symbolFont = new stdole.StdFontClass() as stdole.IFontDisp;
//symbolFont.Name = "ESRI Default Marker";
ICharacterMarkerSymbol characterMarkerSymbol = new CharacterMarkerSymbolClass();
characterMarkerSymbol.Color = color;
characterMarkerSymbol.CharacterIndex = 98;//pin
characterMarkerSymbol.Size = 20.0;
characterMarkerSymbol.XOffset = 0;
characterMarkerSymbol.YOffset = -5;
PINSYM = m_graphicTracker.CreateSymbol(characterMarkerSymbol as ISymbol, null);
}
private void LandZoneCfg_Load(object sender, EventArgs e)
{
// change color for the toggle button
if (rtbLarge.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
rtbLarge.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
else if (rtbMedium.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
rtbMedium.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
else if (rtbSmall.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
rtbSmall.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
//lbLat.Location = new System.Drawing.Point(txLat.Location.X - 5 - lbLat.Size.Width, lbLat.Location.Y);
//lbLng.Location = new System.Drawing.Point(txLng.Location.X - 5 - lbLng.Size.Width, lbLng.Location.Y);
//lbName.Location = new System.Drawing.Point(txName.Location.X - 5 - lbName.Size.Width, lbName.Location.Y);
//lbDesc.Location = new System.Drawing.Point(txDesc.Location.X - 5 - lbDesc.Size.Width, lbDesc.Location.Y);
//lbEditLand.Location = new System.Drawing.Point(cbLandEdit.Location.X - 5 - lbEditLand.Size.Width, lbEditLand.Location.Y);
//lbAddress.Location = new System.Drawing.Point(txAddress.Location.X - 5 - lbAddress.Size.Width, lbAddress.Location.Y);
//lbColor.Location = new System.Drawing.Point(cbColor.Location.X - 5 - lbColor.Size.Width, lbColor.Location.Y);
//lbEditZone.Location = new System.Drawing.Point(cbZoneEdit.Location.X - 5 - lbEditZone.Size.Width, lbEditZone.Location.Y);
//Load a pre-authored map document into the PageLayoutControl using relative paths.
//string fileName = @"E:\Cape Girardeau\GIS data\workspace.mxd";
if (mapControl.CheckMxFile(MainForm2.ArcGisFileName)) mapControl.LoadMxFile(MainForm2.ArcGisFileName);
mapControl.SpatialReference = MainForm2.CreateGeoCoordSys();
//Get the MapControl
m_mapControl = (IMapControl3)mapControl.Object;
m_graphicTracker = new GraphicTrackerClass();
m_graphicTracker.Initialize(m_mapControl.Map as IBasicMap);
PINSET = new GraphicTrackerClass();
PINSET.Initialize(m_mapControl.Map as IBasicMap);
graphicsContainer = (IGraphicsContainer)mapControl.ActiveView;
loadfinish = true;
placeSymb = new PlaceSymbolsGIS(m_graphicTracker, tabName);
PutAllLandmarks();
if (onLandMark) ShowAllZone();
else
{
if (cbZoneEdit.Items.Count > 1)
{
cbZoneEdit.SelectedIndex = 1;
cbZoneEdit.SelectedIndex = 0;
}
else
{
ShowAllZone();
SelectZone();
}
}
btZoneNew.Enabled = true;
}
private Boolean onLandMark = true;
private void toolWindow1_Enter(object sender, EventArgs e)
{
//lbLat.Location = new System.Drawing.Point(txLat.Location.X - 5 - lbLat.Size.Width, lbLat.Location.Y);
//lbLng.Location = new System.Drawing.Point(txLng.Location.X - 5 - lbLng.Size.Width, lbLng.Location.Y);
//lbName.Location = new System.Drawing.Point(txName.Location.X - 5 - lbName.Size.Width, lbName.Location.Y);
//lbDesc.Location = new System.Drawing.Point(txDesc.Location.X - 5 - lbDesc.Size.Width, lbDesc.Location.Y);
//lbEditLand.Location = new System.Drawing.Point(cbLandEdit.Location.X - 5 - lbEditLand.Size.Width, lbEditLand.Location.Y);
//lbAddress.Location = new System.Drawing.Point(txAddress.Location.X - 5 - lbAddress.Size.Width, lbAddress.Location.Y);
if (!onLandMark)
{
onLandMark = true;
if (loadfinish)
PutAllLandmarks();
}
if (MainForm2.ForceSaveZone)
ForceSave();
}
private void toolWindow4_Enter(object sender, EventArgs e)
{
//lbColor.Location = new System.Drawing.Point(cbColor.Location.X - 5 - lbColor.Size.Width, lbColor.Location.Y);
//lbEditZone.Location = new System.Drawing.Point(cbZoneEdit.Location.X - 5 - lbEditZone.Size.Width, lbEditZone.Location.Y);
if (onLandMark)
{
onLandMark = false;
if (loadfinish)
{
if (cbZoneEdit.Items.Count > 1)
{
cbZoneEdit.SelectedIndex = 1;
cbZoneEdit.SelectedIndex = 0;
}
else if (cbZoneEdit.Items.Count == 1)
{
SelectZone();
}
}
}
}
private Int32 newIdgen = -1;
private Boolean StopTimer = false;
private Boolean PointForNewZone = false;
private Boolean StopClicked = false;
private void btAddPoint_Click(object sender, EventArgs e)
{
if (!StopTimer)
{
StopTimer = true;
PointForNewZone = true;
LandMarkNotSpecPoint = false;
btAddPoint.Text = "Stop Adding";
StopClicked = false;
}
else
{
StopTimer = false;
PointForNewZone = false;
btAddPoint.Text = "Add Points";
populateList();
StopClicked = true;
}
MainForm2.ForceSaveZone = true;
}
private void mapControl_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
{
try
{
if (!PointForNewZone)
{
if ((LandMarkNotSpecPoint) || (PointForZone))
{
IPoint point = new ESRI.ArcGIS.Geometry.Point();
point.X = e.mapX;
point.Y = e.mapY;
point.SpatialReference = MainForm2.CreateGeoCoordSys();
if (LandMarkNotSpecPoint)
{
m_graphicTracker.SuspendUpdate = true;
txLat.Value = (decimal)((double)e.mapY);
txLng.Value = (decimal)((double)e.mapX);
if (OnNewLandMark)
{
if (putNewOnMapBool)
m_graphicTracker.SetGeometry(newIdgen, point);
else
{
// get landmark type
KeyValuePair<Int32, LandmarkType> landType = (KeyValuePair<Int32, LandmarkType>)rlvIcons.SelectedItem.DataBoundItem;
Color color = Color.Black;
color = colorsList[rlvLandmarkColors.SelectedIndex];
String iconSize = rrbSmall.IsChecked ? "s" : (rrbMedium.IsChecked ? "m" : "l");
// get landmark type
String iconName = landType.Value.IconName;
int iconIndex = landType.Value.Idx;
if (!CheckIfExistsIcon(color, iconSize, iconName, iconIndex))
{
iconSize = (iconSize == "s") ? "small" : (iconSize == "m" ? "medium" : "large");
CreateIcon(color, iconSize, iconName, iconIndex);
};
string type = iconName.Replace(".png", "");
string colorString = System.Drawing.ColorTranslator.ToHtml(color);
newIdgen = m_graphicTracker.Add(point as IGeometry, ((IGraphicTrackerSymbol)((Place)MainForm2.PlaceTypesGIS[type+colorString+iconSize]).SymbGIS[tabName]));
MainForm2.simpleTextSymbol.YOffset = 20;
m_graphicTracker.SetTextSymbol(newIdgen, MainForm2.simpleTextSymbol);
m_graphicTracker.SetLabel(newIdgen, "newLandmark");
}
putNewOnMapBool = true;
}
else
m_graphicTracker.SetGeometry(((Zone_type)((RadListDataItem)cbLandEdit.SelectedItem).Value).driver_id, point);
m_graphicTracker.SuspendUpdate = false;
LandMarkNotSpecPoint = false;
}
else //PointForZone
{
//Location locTemp = mapControl.ActiveMap.XYToLocation(e.x, e.y);
//mapControl.MousePointer = GeoPointer.geoPointerDefault;
PointList.Rows[RowToUpdate].Cells[2].Value = Math.Round(point.Y, 5).ToString();
PointList.Rows[RowToUpdate].Cells[3].Value = Math.Round(point.X, 5).ToString();
PointList.Refresh();
if (!realNEW)
{
((PointonZone)(((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).new_arrSc_id[RowToUpdate]).lat = point.Y;
((PointonZone)(((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).new_arrSc_id[RowToUpdate]).lng = point.X;
Newarr.Clear();
foreach (PointonZone obj in (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).new_arrSc_id)
Newarr.Add(obj);
}
else
{
((PointonZone)Newarr[RowToUpdate]).lat = point.Y;
((PointonZone)Newarr[RowToUpdate]).lng = point.X;
}
RowToUpdate = -1;
//RefreshZone();
changeSelection();
}
}
}
else //point for new zone
{
IPoint point = new ESRI.ArcGIS.Geometry.Point();
point.X = e.mapX;
point.Y = e.mapY;
point.SpatialReference = MainForm2.CreateGeoCoordSys();
if (!realNEW)
{
((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value).new_arrSc_id.Add(new PointonZone(point.Y, point.X, 0));
Newarr.Clear();
foreach (PointonZone obj in (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value)).new_arrSc_id)
Newarr.Add(obj);
}
else
{
Newarr.Add(new PointonZone(point.Y, point.X, 0));
}
populateList();
if (cbZoneEdit.SelectedItem != null)
if (((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value).new_arrSc_id.Count > 2)
PointList.TableElement.ScrollToRow(((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value).new_arrSc_id.Count - 1);
}
}
catch (Exception ex)
{
SM.Debug("EX:" + ex.ToString());
}
}
private void cbLandEdit_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
SelectionLand();
}
private void cbZoneEdit_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
if (!Loaddata)
SelectZone();
}
private void ckTextMessage_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (OnNew)
{
if (ckTextMessage.Checked)
{
txMsgbody.Enabled = true;
cbVehNameFleet.Enabled = true;
}
else
{
txMsgbody.Enabled = false;
cbVehNameFleet.Enabled = false;
}
}
}
private void ckTextMessage2_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (OnNew)
{
if (ckSingleText.Checked)
txMsgbody2.Enabled = true;
else
txMsgbody2.Enabled = false;
}
}
private void ckEmail_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (OnNew)
{
if (ckEmail.Checked)
{
txEmail.Enabled = true;
txSubj.Enabled = true;
txBody.Enabled = true;
}
else
{
txEmail.Enabled = false;
txSubj.Enabled = false;
txBody.Enabled = false;
}
}
}
private void txEmail_TextChanged(object sender, EventArgs e)
{
}
private void txSubj_TextChanged(object sender, EventArgs e)
{
}
private void ckSpeedLimit_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
if (OnNew)
{
if (ckSpeedLimit.Checked)
{
tbSpeed.Enabled = true;
lbSpeedName.Enabled = true;
}
else
{
tbSpeed.Enabled = false;
lbSpeedName.Enabled = false;
}
}
}
private void pb_DeleteLandmark_Click(object sender, EventArgs e)
{
if (OnNewLandMark)
{
EnabledNEW();
ReloadCombo("");
}
else
{
if (cbLandEdit.Items.Count > 0)
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
DialogResult dr2 = RadMessageBox.Show(this, mess1 + "\r\n" +
col0 + " = " + txName.Text + "\r\n" +
col1 + " = " + txDesc.Text + "\r\n" +
col2 + " = " + txLat.Value.ToString() + "\r\n" +
col3 + " = " + txLng.Value.ToString() + "\r\n" +
//col4 + " = " + cbPlaceType.Text + "\r\n" +
mess2, mess5, MessageBoxButtons.YesNo, RadMessageIcon.Exclamation);
if (dr2 == DialogResult.Yes)
{
try
{
smdbObj.Delete_Place(((Zone_type)((RadListDataItem)cbLandEdit.SelectedItem).Value).idx.ToString());
MainForm2.LandIDHash.Remove(((Zone_type)((RadListDataItem)cbLandEdit.SelectedItem).Value).idx);
PutAllLandmarks();
}
catch (Exception ex)
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(MainForm2.returnLNGString("database"), MainForm2.returnLNGString("war"), MessageBoxButtons.OK, RadMessageIcon.Exclamation);
SM.Debug("EX:" + ex.ToString());
}
EnabledNEW();
ReloadCombo("");
}
}
}
}
private void pb_DeleteAction_MouseEnter(object sender, EventArgs e)
{
if ((PictureBox)sender == pb_DeleteLandmark)
{
pb_DeleteLandmark.Image = global::Dispatcher.Properties.Resources.trash_over;
label_DeleteLandmark.ForeColor = Color.Black;
}
else if ((PictureBox)sender == pb_DeleteGeofence)
{
pb_DeleteGeofence.Image = global::Dispatcher.Properties.Resources.trash_over;
}
}
private void pb_DeleteAction_MouseLeave(object sender, EventArgs e)
{
if ((PictureBox)sender == pb_DeleteLandmark)
{
pb_DeleteLandmark.Image = global::Dispatcher.Properties.Resources.trash_activ;
label_DeleteLandmark.ForeColor = Color.FromArgb(158, 158, 158);
}
else if ((PictureBox)sender == pb_DeleteGeofence)
{
pb_DeleteGeofence.Image = global::Dispatcher.Properties.Resources.trash_activ;
}
}
private void pb_DeleteGeofence_Click(object sender, EventArgs e)
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS) || (MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
Boolean validanswer = true;
if (MainForm2.userIDX != useridxzone)
{
validanswer = false;
TabName tmp = new TabName((String)MainForm2.userIDHash[useridxzone], true);
tmp.ShowDialog();
password = tmp.Name;
if (password.ToUpper().CompareTo(((String)MainForm2.passUserHash[useridxzone]).ToUpper()) == 0)
validanswer = true;
else RadMessageBox.Show(MainForm2.returnLNGString("passIsWrong"), MainForm2.returnLNGString("error"), MessageBoxButtons.OK, RadMessageIcon.Error);
}
if (validanswer)
{
DialogResult dr2 = RadMessageBox.Show(this, mess11 + " " + '"' + cbZoneEdit.Text + '"' + " " + messWill + "\r\n" + mess12, mess15, MessageBoxButtons.YesNo, RadMessageIcon.Exclamation);
if (dr2 == DialogResult.Yes)
{
try
{
smdbObj.Delete_Zone(((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value).id.ToString());
smdbObj.Delete_Zone_Alarm(((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value).id.ToString());
smdbObj.Delete_Zone_Reports(((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value).id.ToString());
MainForm2.ZoneIDHash.Remove(((ZoneClass)((RadListDataItem)cbZoneEdit.SelectedItem).Value).id);
}
catch (Exception ex)
{
RadMessageBox.Show(MainForm2.returnLNGString("database"), MainForm2.returnLNGString("war"), MessageBoxButtons.OK, RadMessageIcon.Exclamation);
SM.Debug("Ex:" + ex.ToString());
}
ReloadComboZone("");
}
}
}
/// <summary>
/// Event handler for when the Alerts pictureBox or Label are pressed
/// This will cause the Alerts GroupBox to be brought to front
/// </summary>
private void AlertsMenu_Click(object sender, EventArgs e)
{
rgbAlerts.BringToFront();
}
/// <summary>
/// Event handler for when the Style pictureBox or Label are pressed
/// This will cause the Style GroupBox to be brought to front
/// </summary>
private void StyleMenu_Click(object sender, EventArgs e)
{
rgbStyle.BringToFront();
}
private void rlvGeofenceBorderColors_SelectedIndexChanged(object sender, EventArgs e)
{
if(rlvGeofenceBorderColors.SelectedItem !=null)
color = (Color)rlvGeofenceBorderColors.SelectedItem.DataBoundItem;
changeSelection();
}
private void toggleButton_StateChanged(object sender, StateChangedEventArgs args)
{
if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
((RadToggleButton)sender).ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
else
((RadToggleButton)sender).ButtonElement.ButtonFillElement.BackColor = Color.White;
}
/// <summary>
/// Intercept the mouse up event on the Toggle Buttons in order to
/// prevent setting the toggle button to unchecked state and to
/// change the radio buttons when a new toggle button becames active
/// </summary>
private void rtb_MouseUp(object sender, MouseEventArgs e)
{
RadToggleButton toggleSender = sender as RadToggleButton;
if (toggleSender == null)
return;
if ((toggleSender.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On))
{
// this means that I have now on state and I can change the state
Telerik.WinControls.Enumerations.ToggleState state = Telerik.WinControls.Enumerations.ToggleState.On;
// change the state of the radio buttons according to the
// radio button
if (toggleSender == rtbSmall)
rrbSmall.ToggleState = state;
else if (toggleSender == rtbMedium)
rrbMedium.ToggleState = state;
else if (toggleSender == rtbLarge)
rrbLarge.ToggleState = state;
}
else
{
// force the state to be on because I don't need the user to set this toggle button
// to off state
toggleSender.ToggleState = Telerik.WinControls.Enumerations.ToggleState.On;
}
}
/// <summary>
/// Event when the color had changed for a landmark
/// </summary>
private void rlvLandmarkColors_SelectedIndexChanged(object sender, EventArgs e)
{
OnSomethingChangedForLandmark(txName.Text, txName.Text);
}
/// <summary>
/// Event when the icon had changed for a landmark
/// </summary>
private void rlvIcons_SelectedIndexChanged(object sender, EventArgs e)
{
OnSomethingChangedForLandmark(txName.Text, txName.Text);
}
/// <summary>
/// Event which will handle every change of the landmark, meaning color,
/// latitude/longitude, type, name
/// </summary>
/// <param name="landmarkName">Name of the landmark which will be </param>
private void OnSomethingChangedForLandmark(String prevLandmarkName, String crtlandmarkName)
{
if (rlvIcons.SelectedIndex < 0 || rlvIcons.SelectedItem.DataBoundItem == null)
return;
if (rlvLandmarkColors.SelectedIndex < 0 || rlvLandmarkColors.SelectedItem.DataBoundItem == null)
return;
// do not change the icon if the latitude and longitude ar false
if (txLng.Value == 0 && txLat.Value == 0)
return;
KeyValuePair<Int32, LandmarkType> landType = (KeyValuePair<Int32, LandmarkType>)rlvIcons.SelectedItem.DataBoundItem;
Color color = (Color)rlvLandmarkColors.SelectedItem.DataBoundItem;
string dataSetName = "LandView";
if (cbLandEdit.SelectedIndex == 0)
dataSetName = "NewLandView";
//UpdateLandmarkOnMap(dataSetName, (prevLandmarkName.Length > 0 ? prevLandmarkName : "Unnamed"),
// (double)rseLatitude.Value, (double)rseLongitude.Value,
// crtlandmarkName.Length > 0 ? crtlandmarkName : "Unnamed",
// rtbLandDesc.Text, landType.Value.Idx, color, GetIconSize());
}
/// <summary>
/// Event Handler for when the size of the icon had changed.
/// This will cause the Toggle Buttons to change the values
/// and to trigger the ChangeLandmark event
/// </summary>
private void rrb_CheckStateChanged(object sender, EventArgs e)
{
RadRadioButton senderButton = sender as RadRadioButton;
if (senderButton == null)
return;
// get current state
CheckState state = (senderButton.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On ? CheckState.Checked : CheckState.Unchecked);
// change the toggle button
if (senderButton == rrbSmall)
rtbSmall.CheckState = state;
else if (senderButton == rrbMedium)
rtbMedium.CheckState = state;
else if (senderButton == rrbLarge)
rtbLarge.CheckState = state;
// change on the map the size of the landmark
if (state == CheckState.Checked)
OnSomethingChangedForLandmark(txName.Text, txName.Text);
}
/// <summary>
/// Get the icon name and relative path for a specific landmark
/// </summary>
/// <param name="landmarkTypeID">The landmark icon type id for which the icon
/// needs to be returned</param>
/// <param name="color">Color for the desired landmark</param>
/// <param name="iconSize">Desired size of the landmark</param>
/// <returns></returns>
public static String GetLandmarkIcon(Int32 landmarkTypeID, Color color, LandmarkUI.IconSize iconSize)
{
int width = 36;
int heigth = 48;
if (iconSize == LandmarkUI.IconSize.MEDIUM)
{
width = 27;
heigth = 36;
}
else if (iconSize == LandmarkUI.IconSize.SMALL)
{
width = 20;
heigth = 26;
}
//36,48; 27,36; 20,26;
// get the hex colors for the desired color
String hexColor = color.R.ToString("X2") + color.G.ToString("X2") + color.B.ToString("X2");
LandmarkType lt = null;
if (landmarkTypesList.ContainsKey(landmarkTypeID))
{
lt = landmarkTypesList[landmarkTypeID];
// generate the name and the path of the desired icon
string iconNameAndPath = System.Windows.Forms.Application.StartupPath
+ @"\resource\landmarks\" + lt.IconName.Replace(".png", "") + "_" + hexColor + "_" + iconSize.ToString() + ".png";
// check if the icon exists on the hdd
if (System.IO.File.Exists(iconNameAndPath))
{
// we are ok, and the icon doesn't need to be recreated
}
else
{
float r = (float)((1.0 / 256) * color.R);// / 256;
float g = (float)((1.0 / 256) * color.G);// / 256;
float b = (float)((1.0 / 256) * color.B);// / 256;
// create the landmark icon
using (Bitmap landmarkPin = new Bitmap(System.Windows.Forms.Application.StartupPath
+ @"\resource\landmarks\_pin_02.png"))
{
Bitmap bitmap = new Bitmap(landmarkPin.Width, landmarkPin.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
ImageAttributes imageAttributes = new ImageAttributes();
// create a color matrix in order to change the color
float[][] colorMatrixElements = {
new float[] {1, 0, 0, 0, 0}, // Red scaling [multiply]
new float[] {0, 1, 0, 0, 0}, // Green scaling [multiply]
new float[] {0, 0, 1, 0, 0}, // Blue scaling [multiply]
new float[] {r, g, b, 1, 0}, // this will add values to R,G,B,A
new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2
ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(
colorMatrix,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
// Create a Graphics object
using (Graphics gr = Graphics.FromImage(bitmap))
{
// Draw image with no affects
gr.DrawImage(landmarkPin, 0, 0, landmarkPin.Width, landmarkPin.Height);
// Draw image with ImageAttributes
gr.DrawImage(landmarkPin, new Rectangle(0, 0, landmarkPin.Width, landmarkPin.Height), 0, 0,
landmarkPin.Width, landmarkPin.Height, GraphicsUnit.Pixel, imageAttributes);
// add landmark type icon
string iconPath = safemobileDirPath + @"\resource\landmarks\" + lt.IconName;
using (Image img = Utils.ScaleImage(Bitmap.FromFile(iconPath), 44, 44))
{
gr.DrawImage(img, 19, 18);
}
Image resizedImage = Utils.ScaleImage(bitmap, width, heigth);
resizedImage.Save(iconNameAndPath);
//bitmap.Save(iconNameAndPath);
// Dispose
bitmap.Dispose();
resizedImage.Dispose();
}
}
}
return lt.IconName.Replace(".png", "") + "_" + hexColor + "_" + iconSize.ToString() + ".png";
}
return @"landmarks\default.png";
}
public Color getColorid(List<Color> colorList, int id)
{
Color ret = Color.Black;
if (id > colorList.Count) return ret;
return colorList[id];
}
/// <summary>
/// Determin the size of the icon as displayed in the UI
/// </summary>
/// <returns>Returns the size of the icon</returns>
private LandmarkUI.IconSize GetIconSize()
{
// determin the icon size
return rrbMedium.IsChecked ? LandmarkUI.IconSize.MEDIUM :
(rrbLarge.IsChecked ? LandmarkUI.IconSize.LARGE : LandmarkUI.IconSize.SMALL);
}
#region CHANGE TABS BACKGROUND
private DockWindow oldDockWindow = null;
private void radDock1_ActiveWindowChanging(object sender, DockWindowCancelEventArgs e)
{
// reset the background icon for the previous tab
e.OldWindow.TabStripItem.BackColor = Color.White;
e.OldWindow.TabStripItem.DrawFill = true;
e.OldWindow.TabStripItem.NumberOfColors = 1;
// reset the background for the new window
e.NewWindow.TabStripItem.DrawFill = true;
e.NewWindow.TabStripItem.NumberOfColors = 1;
e.NewWindow.TabStripItem.BackColor = MainForm2.TabSelectedColor;
// save old dock window
oldDockWindow = e.OldWindow;
}
private void radDock1_ActiveWindowChanged(object sender, DockWindowEventArgs e)
{
// reset the background icon for the previous tab
oldDockWindow.TabStripItem.BackColor = Color.White;
oldDockWindow.TabStripItem.DrawFill = true;
oldDockWindow.TabStripItem.NumberOfColors = 1;
e.DockWindow.TabStripItem.DrawFill = true;
e.DockWindow.TabStripItem.NumberOfColors = 1;
e.DockWindow.TabStripItem.BackColor = MainForm2.TabSelectedColor;
}
#endregion
/// <summary>
/// Event handler for when the left tab panel needs to be docked/transfor in floating state.
/// This will cancel this event in order to prevent the stupid case with hiding the dock window
/// </summary>
private void radDock1_DockStateChanging(object sender, DockStateChangingEventArgs e)
{
e.Cancel = true;
}
/// <summary>
/// Change the toggle button which is on depending on the state received
/// as a parameter
/// </summary>
/// <param name="size">The desired icon size which needs to be selected</param>
private void ChangeIconSizeToggleButtons(Safedispatch_4_0.LandmarkUI.IconSize size)
{
// find out which value needs to be on
if (size == Safedispatch_4_0.LandmarkUI.IconSize.SMALL)
rrbSmall.CheckState = CheckState.Checked;
else if (size == Safedispatch_4_0.LandmarkUI.IconSize.MEDIUM)
rrbMedium.CheckState = CheckState.Checked;
else if (size == Safedispatch_4_0.LandmarkUI.IconSize.LARGE)
rrbLarge.CheckState = CheckState.Checked;
}
private bool CheckIfExistsIcon(Color Color, String iconSize, String iconName, int iconIndex)
{
String hexColor = Color.R.ToString("X2") + Color.G.ToString("X2") + Color.B.ToString("X2");
// check if resource directory exists
if (!Directory.Exists("resource"))
{
Directory.CreateDirectory("resource");
}
// check if resource directory exists
if (!Directory.Exists("resource/landmarks"))
{
Directory.CreateDirectory("resource/landmarks");
}
// generate the name and the path of the desired icon
string iconNameAndPath = System.Windows.Forms.Application.StartupPath
+ @"\resource\landmarks\" + iconName.Replace(".png", "") + "_" + hexColor + "_" + iconSize.Substring(0, 1) + ".png";
//obj.pic = iconNameAndPath.Replace(".png", ".bmp");
// check if the icon exists on the hdd
if (System.IO.File.Exists(iconNameAndPath))
{
// we are ok, and the icon doesn't need to be recreated
//if exists check if hash table contains it
string type = iconName.Replace(".png", "");
if (!MainForm2.PlaceTypesGIS.Contains(type + "#" + hexColor + iconSize))
{
int size = 48;
if (iconSize.Substring(0, 1) == LandmarkUI.IconSize.MEDIUM.ToString())
size = 32;
else if (iconSize.Substring(0, 1) == LandmarkUI.IconSize.SMALL.ToString())
size = 24;
try
{
ESRI.ArcGIS.Display.IPictureMarkerSymbol bitmapPictureMarkerSymbolCls = new
ESRI.ArcGIS.Display.PictureMarkerSymbolClass();
Image ArcgisImage = Image.FromFile(iconNameAndPath);
ArcgisImage.Save(iconNameAndPath.Replace(".png", ".bmp"), ImageFormat.Bmp);
//var ArcgisImage = new Bitmap(iconNameAndPath);
//ArcgisImage.MakeTransparent(Color.Black);
//ArcgisImage.Save(iconNameAndPath.Replace(".png", ".bmp"));
ArcgisImage.Dispose();
bitmapPictureMarkerSymbolCls.CreateMarkerSymbolFromFile
(ESRI.ArcGIS.Display.esriIPictureType.esriIPictureBitmap, iconNameAndPath.Replace(".png", ".bmp"));
bitmapPictureMarkerSymbolCls.Angle = 0;//Minicar
RgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColor();
rgbColor.Red = 255;
rgbColor.Green = 255;
rgbColor.Blue = 255;
bitmapPictureMarkerSymbolCls.BitmapTransparencyColor = rgbColor;
bitmapPictureMarkerSymbolCls.Size = size;
bitmapPictureMarkerSymbolCls.XOffset = -12;
bitmapPictureMarkerSymbolCls.YOffset = -12;
//create place
Place obj = new Place();
obj.type = iconName.Replace(".png", "");
obj.idx = iconIndex;
obj.pic = iconNameAndPath.Replace(".png", ".bmp");
obj.iconSize = iconSize;
obj.color = "#" + hexColor;
obj.iconName = iconName;
obj.GISsymb = bitmapPictureMarkerSymbolCls;
//Add place to PlaceTypesGIS
MainForm2.PlaceTypesGIS.Add(obj.type + obj.color + obj.iconSize, obj);
placeSymb = new PlaceSymbolsGIS(m_graphicTracker, tabName);
}
catch (Exception ex)
{
SM.Debug("Error load cars for ARCGIS" + ex.ToString() + "\n" /*+ obj.name*/);
/*obj.GISsymb = null;*/
}
}
return true;
}
return false;
}
private bool CreateIcon(Color Color, String iconSize, String iconName, int iconIndex)
{
int width = 36;
int heigth = 48;
int size = 48;
if (iconSize.Substring(0,1) == LandmarkUI.IconSize.MEDIUM.ToString())
{
width = 27;
heigth = 36;
size = 32;
}
else if(iconSize.Substring(0,1) == LandmarkUI.IconSize.SMALL.ToString())
{
width = 20;
heigth = 26;
size = 24;
}
String hexColor = Color.R.ToString("X2") + Color.G.ToString("X2") + Color.B.ToString("X2");
// check if resource directory exists
if (!Directory.Exists("resource"))
{
Directory.CreateDirectory("resource");
}
// check if resource directory exists
if (!Directory.Exists("resource/landmarks"))
{
Directory.CreateDirectory("resource/landmarks");
}
// generate the name and the path of the desired icon
string iconNameAndPath = System.Windows.Forms.Application.StartupPath
+ @"\resource\landmarks\" + iconName.Replace(".png", "") + "_" + hexColor + "_" + iconSize.Substring(0, 1) + ".png";
//obj.pic = iconNameAndPath.Replace(".png", ".bmp");
float r = (float)((1.0 / 256) * Color.R);// / 256;
float g = (float)((1.0 / 256) * Color.G);// / 256;
float b = (float)((1.0 / 256) * Color.B);// / 256;
// create the landmark icon
using (Bitmap landmarkPin = new Bitmap(System.Windows.Forms.Application.StartupPath
+ @"\resource\landmarks\_pin_02.png"))
{
Bitmap bitmap = new Bitmap(landmarkPin.Width, landmarkPin.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
ImageAttributes imageAttributes = new ImageAttributes();
// create a color matrix in order to change the color
float[][] colorMatrixElements = {
new float[] {1, 0, 0, 0, 0}, // Red scaling [multiply]
new float[] {0, 1, 0, 0, 0}, // Green scaling [multiply]
new float[] {0, 0, 1, 0, 0}, // Blue scaling [multiply]
new float[] {r, g, b, 1, 0}, // this will add values to R,G,B,A
new float[] {0, 0, 0, 0, 1}}; // three translations of 0.2
ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);
imageAttributes.SetColorMatrix(
colorMatrix,
ColorMatrixFlag.Default,
ColorAdjustType.Bitmap);
// Create a Graphics object
using (Graphics gr = Graphics.FromImage(bitmap))
{
// Draw image with no affects
gr.DrawImage(landmarkPin, 0, 0, landmarkPin.Width, landmarkPin.Height);
// Draw image with ImageAttributes
gr.DrawImage(landmarkPin, new Rectangle(0, 0, landmarkPin.Width, landmarkPin.Height), 0, 0,
landmarkPin.Width, landmarkPin.Height, GraphicsUnit.Pixel, imageAttributes);
// add landmark type icon
String safemobileDirPath = System.Windows.Forms.Application.StartupPath;
string iconPath = safemobileDirPath + @"\resource\landmarks\" + iconName;
using (Image img = Utils.ScaleImage(Bitmap.FromFile(iconPath), 44, 44))
{
gr.DrawImage(img, 19, 18);
}
Image resizedImage = Utils.ScaleImage(bitmap, width, heigth);
resizedImage.Save(iconNameAndPath);
//bitmap.Save(iconNameAndPath);
// Dispose
bitmap.Dispose();
resizedImage.Dispose();
}
}
try
{
ESRI.ArcGIS.Display.IPictureMarkerSymbol bitmapPictureMarkerSymbolCls = new
ESRI.ArcGIS.Display.PictureMarkerSymbolClass();
Image ArcgisImage = Image.FromFile(iconNameAndPath);
ArcgisImage.Save(iconNameAndPath.Replace(".png", ".bmp"), ImageFormat.Bmp);
//var ArcgisImage = new Bitmap(iconNameAndPath);
//ArcgisImage.MakeTransparent(Color.Black);
//ArcgisImage.Save(iconNameAndPath.Replace(".png", ".bmp"));
ArcgisImage.Dispose();
bitmapPictureMarkerSymbolCls.CreateMarkerSymbolFromFile
(ESRI.ArcGIS.Display.esriIPictureType.esriIPictureBitmap, iconNameAndPath.Replace(".png", ".bmp"));
bitmapPictureMarkerSymbolCls.Angle = 0;//Minicar
RgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColor();
rgbColor.Red = 255;
rgbColor.Green = 255;
rgbColor.Blue = 255;
bitmapPictureMarkerSymbolCls.BitmapTransparencyColor = rgbColor;
bitmapPictureMarkerSymbolCls.Size = size;
bitmapPictureMarkerSymbolCls.XOffset = -12;
bitmapPictureMarkerSymbolCls.YOffset = -12;
//create place
Place obj = new Place();
obj.type = iconName.Replace(".png", "");
obj.idx = iconIndex;
obj.pic = iconNameAndPath.Replace(".png", ".bmp");
obj.iconSize = iconSize;
obj.color = "#" + hexColor;
obj.iconName = iconName;
obj.GISsymb = bitmapPictureMarkerSymbolCls;
//Add place to PlaceTypesGIS
MainForm2.PlaceTypesGIS.Add(obj.type + obj.color + obj.iconSize, obj);
placeSymb = new PlaceSymbolsGIS(m_graphicTracker, tabName);
}
catch (Exception ex)
{
SM.Debug("Error load cars for ARCGIS" + ex.ToString() + "\n");
}
return true;
}
private void labelAlerts_Click(object sender, EventArgs e)
{
}
}
}