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

3372 lines
104 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using System.Collections;
using SafeMobileLib;
using Telerik.WinControls;
using Telerik.WinControls.Primitives;
using System.Threading;
using Telerik.WinControls.Data;
using Telerik.WinControls.UI.Docking;
using Dispatcher.maptab.UIClasses;
namespace Safedispatch_4_0
{
public partial class SMSuserControl : UserControl
{
public enum TextStatus
{
SD_NO_GW = 0,
UNREAD_OUT = 1,
READ_OUT = 2,
UNREAD_IN = 3,
READ_IN = 4,
UNREAD_EMAIL = 5,
READ_EMAIL = 7,
UNKNOWN = 6
};
private SMdb_access smdbObj;
public MainForm2 parent;
//language
String msginboxallunit, msgoutboxallunit, msginboxunit, msgoutboxunit, msginboxgrp, msgoutboxgrp, msgRecy;
String wordRecyBin, wordMoveDel,wordInbox, wordOutbox, wordFrom, wordTo, wordMarkRead, wordMarkUnRead, wordDate, wordDelete;
#region Value from SD_LITE
enum NodeType
{
trash = 0,
inbox,
outbox,
grInbox,
grOutbox,
subInbox,
subOutbox
}
ArrayList arVehSCID;
ArrayList arInboxSMS;
ArrayList arInboxSMSLimit2000;
ArrayList arDeletedSMS;
public Hashtable htSUIDwithNewSMS;
private RadTreeNode selectedTreeNode = null;
private NodeType selectedNodeType = NodeType.grInbox;
public int selectedSC_ID = 0;
public bool inboxSelec = true;
private bool trashSelec = false;
public int[] selectedSC_IDlist = null;
//public static ConvertDT convDT;
public static Hashtable htGroupsKeyNAmeValueID;
private int[] slectedSMSidx;
internal static Boolean isSMSLoaded = false;
#endregion
public SMSuserControl(MainForm2 mf2)
{
htGroupsKeyNAmeValueID = new Hashtable(); htSUIDwithNewSMS = new Hashtable(); arVehSCID = new ArrayList(); arInboxSMS = new ArrayList(); arDeletedSMS = new ArrayList();
parent = mf2;
InitializeComponent();
SetLanguage();
#region STYLE THEMING
labelReportName.ForeColor = MainForm2.LabelColor;
labelUser.ForeColor = MainForm2.LabelColor;
rbNewMessage.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
rbtSendQuick.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
pbReportType.Image = Utils.ChangeColor(Dispatcher.Properties.Resources.r_textmessaging, MainForm2.ButtonColor);
SMSGridView.GridNavigator.GridViewElement.PagingPanelElement.ShowFastBackButton = false;
SMSGridView.GridNavigator.GridViewElement.PagingPanelElement.ShowFastForwardButton = false;
//SMSGridView.GridNavigator.GridViewElement.PagingPanelElement.ButtonsStripElement.S = false;
SMSGridView.GridNavigator.GridViewElement.PagingPanelElement.ShowNumericalButtons = false;
#endregion
rlMsgStatus.Text = MainForm2.returnLNGString("msg_status");
rddlFilterMsgStatus.Items.Add(MainForm2.returnLNGString("displayall"));
rddlFilterMsgStatus.Items.Add(MainForm2.returnLNGString("msg_read"));
rddlFilterMsgStatus.Items.Add(MainForm2.returnLNGString("msg_unread"));
rddlFilterMsgStatus.SelectedIndex = 0;
// set theme for the Message Box
RadMessageBox.SetThemeName("TelerikMetroBlue");
// add icons for picture box keys
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("s_key_r_d"))
MainForm2.imagesDictionary.Add("s_key_r_d", Utils.MakeGrayscale3((Bitmap)Dispatcher.Properties.Resources.s_key_r, 0.5f));
if (!MainForm2.imagesDictionary.ContainsKey("s_key_u_d"))
MainForm2.imagesDictionary.Add("s_key_u_d", Utils.MakeGrayscale3((Bitmap)Dispatcher.Properties.Resources.s_key_u, 0.5f));
if (!MainForm2.imagesDictionary.ContainsKey("s_key_del_d"))
MainForm2.imagesDictionary.Add("s_key_del_d", Utils.MakeGrayscale3((Bitmap)Dispatcher.Properties.Resources.s_key_del, 0.5f));
if (!MainForm2.imagesDictionary.ContainsKey("s_key_r"))
MainForm2.imagesDictionary.Add("s_key_r", Dispatcher.Properties.Resources.s_key_r);
if (!MainForm2.imagesDictionary.ContainsKey("s_key_u"))
MainForm2.imagesDictionary.Add("s_key_u", Dispatcher.Properties.Resources.s_key_u);
if (!MainForm2.imagesDictionary.ContainsKey("s_key_del"))
MainForm2.imagesDictionary.Add("s_key_del", Dispatcher.Properties.Resources.s_key_del);
// create the toolTip that will be displayed when the user sets a pattern
// over the hint pictureBox
toolTipHelp = new ToolTip();
toolTipHelp.ToolTipTitle = "";
toolTipHelp.AutoPopDelay = 0;
toolTipHelp.InitialDelay = 0;
toolTipHelp.ReshowDelay = 0;
toolTipHelp.IsBalloon = false;
toolTipHelp.ShowAlways = true;
// set the row height
SMSGridView.TableElement.RowHeight = 43;
this.SMSGridView.EnableAlternatingRowColor = true;
this.SMSGridView.TableElement.GridViewElement.TableElement.AlternatingRowColor = Color.LightYellow;
// remove border for grid
this.SMSGridView.GridViewElement.DrawBorder = false;
this.SMSGridView.GridViewElement.GroupPanelElement.DrawBorder = false;
smdbObj = new SMdb_access();
}
private void SetLanguage()
{
wordInbox = MainForm2.returnLNGString("Inbox");
wordOutbox = MainForm2.returnLNGString("Outbox");
wordRecyBin = MainForm2.returnLNGString("RecycleBin");
wordFrom = MainForm2.returnLNGString("Ilabel1");
wordTo = MainForm2.returnLNGString("Ilabel2");
wordDate = MainForm2.returnLNGString("rapday");
wordMoveDel = MainForm2.returnLNGString("movedel");
wordDelete = MainForm2.returnLNGString("SMSDelete");
msginboxallunit = MainForm2.returnLNGString("msginboxallunit");
msgoutboxallunit = MainForm2.returnLNGString("msgoutboxallunit");
msginboxunit = MainForm2.returnLNGString("msginboxunit");
msgoutboxunit = MainForm2.returnLNGString("msgoutboxunit");
msginboxgrp = MainForm2.returnLNGString("msginboxgrp");
msgoutboxgrp = MainForm2.returnLNGString("msgoutboxgrp");
msgRecy = MainForm2.returnLNGString("msgRecy");
wordMarkRead = MainForm2.returnLNGString("wordMarkRead");
wordMarkUnRead = MainForm2.returnLNGString("wordMarkUnRead");
SMSGridView.Columns["Source"].HeaderText = wordFrom;
SMSGridView.Columns["DisplayMessage"].HeaderText = MainForm2.returnLNGString("Message");
SMSGridView.Columns["Date"].HeaderText = MainForm2.returnLNGString("Received");
SMSGridView.Columns["timeAgo"].HeaderText = MainForm2.returnLNGString("datetimefil");
SMSGridView.Columns["Color"].HeaderText = MainForm2.returnLNGString("Color");
radMenuWriteSMS.Text = MainForm2.returnLNGString("WriteSMS");
radLabelSMSstatus.Text = MainForm2.returnLNGString("SMSStatus");
rbNewMessage.Text = MainForm2.returnLNGString("newText");
tbSearch.NullText = MainForm2.returnLNGString("searchtextmessage");
rcbDeleteConfirmation.Text = MainForm2.returnLNGString("delconfirm");
searchTextBox.NullText = MainForm2.returnLNGString("type2search");
rbtSendQuick.Text = MainForm2.returnLNGString("sendmsg");
documentWindow2.Text = MainForm2.returnLNGString("msg");
labelReportName.Text = MainForm2.returnLNGString("tabSMS");
labelReportDetails.Text = MainForm2.returnLNGString("smstabDetails");
}
#region SMS from SD_LITE
private void btn_refreshSMS_Click(object sender, EventArgs e)
{
RefreshALL(false);
}
private void SMSGridView_KeyUp(object sender, KeyEventArgs e)
{
#region DELETE KEY
if (e.KeyCode == Keys.Delete && pbDelete.Tag.Equals("selected"))
{
// detect if many messages are selected or not
bool multiMessagesSelected = SMSGridView.SelectedRows.Count > 1;
DialogResult dr2 = DialogResult.Yes;
if (rcbDeleteConfirmation.Checked)
{
dr2 = RadMessageBox.Show("Are you sure you want to delete selected " +
(multiMessagesSelected ? "messages" : "message"),
(multiMessagesSelected ? "Delete messages" : "Delete message"),
MessageBoxButtons.YesNo, RadMessageIcon.Info);
}
// only if yes was pressed
if (dr2 == DialogResult.Yes)
{
if (slectedSMSidx != null && slectedSMSidx.Length > 0)
{
GridViewSelectedRowsCollection selectedRows = SMSGridView.SelectedRows;
foreach (GridViewDataRowInfo row in SMSGridView.SelectedRows.ToList())
{
if (!trashSelec)
{
smdbObj.Delete_SMS(Int16.Parse(row.Cells["Idx"].Value.ToString()));
}
else
{
smdbObj.Delete_SMS_from_trash(new int[] { Int16.Parse(row.Cells["Idx"].Value.ToString()) });
}
// remove item from the grid
//if (row.DataBoundItem != null && row.DataBoundItem is SMSDataforGRID)
// ListforGrid.Remove(row.DataBoundItem as SMSDataforGRID);
SMSGridView.Rows.Remove(row);
}
// display no events panel
if (SMSGridView.Rows.Count == 0)
panelNoEvents.Visible = true;
/*
if (selectedSC_IDlist != null)
{
if (selectedSC_IDlist.Length > 0)
{
updateDataGrid(selectedSC_IDlist, inboxSelec, false, false, false);
SelectSMSandDisplay(false);
}
}
RefreshALL(true);*/
}
//update number of message for current node
updateInboxAndOutboxView(true);
// notify that messages has changed
parent.UpdateUnreadMessagesNumber();
}
}
#endregion
#region UNREAD KEY
else if (e.KeyCode == Keys.U && pbU.Tag.Equals("selected"))
{
foreach (GridViewRowInfo r in SMSGridView.SelectedRows)
{
smdbObj.Update_SMS(
(GetTreeLevel() == TreeLevel.INBOX ? (int)TextStatus.UNREAD_IN : (int)TextStatus.UNREAD_OUT),
Convert.ToInt32(r.Cells["Idx"].Value));
SMSDataforGRID gridItem = r.DataBoundItem as SMSDataforGRID;
if (gridItem != null)
{
gridItem.Icon = global::Dispatcher.Properties.Resources.closedEnvelope;
gridItem.Status = 0;
}
r.Cells["Icon"].Value = global::Dispatcher.Properties.Resources.closedEnvelope;
r.Cells["Status"].Value = 0;
}
//update number of message for current node
updateInboxAndOutboxView(true);
// notify that messages has changed
parent.UpdateUnreadMessagesNumber();
}
#endregion
#region READ KEY
else if (e.KeyCode == Keys.R && pbR.Tag.Equals("selected"))
{
foreach (GridViewRowInfo r in SMSGridView.SelectedRows)
{
smdbObj.Update_SMS(
(GetTreeLevel() == TreeLevel.INBOX ? (int)TextStatus.READ_IN : (int)TextStatus.READ_OUT), Convert.ToInt32(r.Cells["Idx"].Value));
SMSDataforGRID gridItem = r.DataBoundItem as SMSDataforGRID;
if (gridItem != null)
{
gridItem.Icon = global::Dispatcher.Properties.Resources.openEnvelope;
gridItem.Status = 1;
}
r.Cells["Icon"].Value = global::Dispatcher.Properties.Resources.openEnvelope;
r.Cells["Status"].Value = 1;
}
//update number of message for current node
updateInboxAndOutboxView(true);
// notify that messages has changed
parent.UpdateUnreadMessagesNumber();
}
#endregion
}
private RadTreeNode getParent(RadTreeNode rtn)
{
RadTreeNode returnNode = rtn;
if (rtn.Parent != null)
{
returnNode = getParent(rtn.Parent);
}
return returnNode;
}
private int[] getChildSC_ID(RadTreeNode rtn)
{
int[] ret = new int[0];
if (rtn != null)
{
if (rtn.Nodes.Count > 0)
{
int x = 0;
int count = 0;
int[][] tempArray = new int[rtn.Nodes.Count][];
foreach (RadTreeNode rtnChild in rtn.Nodes)
{
int[] temp = getChildSC_ID(rtnChild);
tempArray[x] = temp;
x++;
count += temp.Length;
}
ret = new int[count];
int count2 = 0;
for (int i = 0; i < rtn.Nodes.Count; i++)
{
for (int j = 0; j < tempArray[i].Length; j++)
{
ret[count2] = tempArray[i][j];
count2++;
}
}
}
else
{
if (rtn.Name != null && rtn.Name != "")
{
if (MainForm2.vehicleHT.ContainsKey(rtn.Name))
{
ret = new int[1];
ret[0] = ((Vehicle)MainForm2.vehicleHT[rtn.Name]).sc_id;
}
else
{
SM.Debug("Empty group selected3 :" + rtn.Name);
}
}
}
}
return ret;
}
private int[] getChildSC_ID_GroupID(RadTreeNode rtn, out Boolean isAgroup)
{
isAgroup = false;
int[] ret = new int[0];
if (rtn != null)
{
if (rtn.Nodes.Count > 0)
{
if (rtn.Name != null && rtn.Name != "")
{
foreach (GroupClass obj in MainForm2.GroupHash.Values)
{
if (obj.name.CompareTo(rtn.Name) == 0)
{
ret = new int[1];
ret[0] = obj.cps_id;
isAgroup = true;
break;
}
}
}
}
else
{
if (rtn.Name != null && rtn.Name != "")
{
if (MainForm2.vehicleHT.ContainsKey(rtn.Name))
{
ret = new int[1];
ret[0] = ((Vehicle)MainForm2.vehicleHT[rtn.Name]).sc_id;
}
else
{
foreach (GroupClass obj in MainForm2.GroupHash.Values)
{
if (obj.name.CompareTo(rtn.Name) == 0)
{
ret = new int[1];
ret[0] = obj.cps_id;
isAgroup = true;
break;
}
}
if (!isAgroup) SM.Debug("Empty group selected2 :" + rtn.Name);
}
}
}
if (ret.Length == 0)
{
ret = getChildSC_ID(rtn);
}
}
return ret;
}
public String whereCommand = "";
private Boolean Type_Inbox_for_limit2000 = true;
private Int32 PageforInbox = 0;
private void getInboxSMS(int[] sc_id)
{
PageforInbox = 0;
whereCommand = "where deleted=0 AND mess not like 'Linx%.%' AND sc_id_sour IN (";
Type_Inbox_for_limit2000 = true;
for (int i = 0; i < sc_id.Length; i++)
{
if (i != sc_id.Length - 1)
{
whereCommand += sc_id[i].ToString() + ",";
}
else
{
whereCommand += sc_id[i].ToString() + ")";
}
}
try
{
if (sc_id.Length > 0)
{
arInboxSMS = smdbObj.get_SMS(whereCommand, true);
//arInboxSMS = smdbObj.get_SMS_with_limit(whereCommand, true, 0);
}
else
{
arInboxSMS = smdbObj.get_SMS("where deleted=0", true);
whereCommand = "where deleted=0";
//arInboxSMS = smdbObj.get_SMS_with_limit("where deleted=0", true,0);
}
}
catch (Exception ex)
{
SM.Debug("Error getInboxSMS:" + ex.ToString());
}
}
private void getOutboxSMS_ifisGroup(int[] sc_id)
{
PageforInbox = 0;
whereCommand = "where deleted=0 AND mess not like 'Linx%.%' AND sc_id_sour=sc_id_dest and sc_id_sour=" + sc_id[0].ToString();
try
{
if (sc_id.Length > 0)
{
arInboxSMS = smdbObj.get_SMS(whereCommand, true);
//arInboxSMS = smdbObj.get_SMS_with_limit(whereCommand, true, 0);
}
else
{
arInboxSMS = smdbObj.get_SMS("where deleted=0", true);
whereCommand = "where deleted=0";
//arInboxSMS = smdbObj.get_SMS_with_limit("where deleted=0", true,0);
}
}
catch (Exception ex)
{
SM.Debug("Error getInboxSMS:" + ex.ToString());
}
}
private void getOutboxSMS(int[] sc_id)
{
if (sc_id != null)
{
PageforInbox = 0;
Type_Inbox_for_limit2000 = false;
whereCommand = "where deleted=0 AND mess not like 'Linx%.%' and sc_id_dest IN (";
for (int i = 0; i < sc_id.Length; i++)
{
if (i != sc_id.Length - 1)
{
whereCommand += sc_id[i].ToString() + ",";
}
else
{
whereCommand += sc_id[i].ToString() + ")";
}
}
try
{
if (sc_id.Length > 0)
{
arInboxSMS = smdbObj.get_SMS(whereCommand, false);
//arInboxSMS = smdbObj.get_SMS_with_limit(whereCommand, false,0);
}
else
{
arInboxSMS = smdbObj.get_SMS("where deleted=0", false);
whereCommand = "where deleted=0";
//arInboxSMS = smdbObj.get_SMS_with_limit("where deleted=0", false,0);
}
}
catch (Exception ex)
{
SM.Debug("Error getOutboxSMS:" + ex.ToString());
}
}
}
private void SetLabelText(RadTreeNode rtn)
{
NodeType nt = getNodeType(rtn);
if (rtn != null)
{
switch (nt)
{
case NodeType.inbox:
radLabelSMSstatus.Text = msginboxallunit;
break;
case NodeType.outbox:
radLabelSMSstatus.Text = msgoutboxallunit;
break;
case NodeType.trash:
radLabelSMSstatus.Text = msgRecy;
break;
case NodeType.grInbox:
radLabelSMSstatus.Text = msginboxgrp + rtn.Text;
break;
case NodeType.grOutbox:
radLabelSMSstatus.Text = msgoutboxgrp + rtn.Text;
break;
case NodeType.subInbox:
radLabelSMSstatus.Text = msginboxunit + rtn.Text;
break;
case NodeType.subOutbox:
radLabelSMSstatus.Text = msgoutboxunit + rtn.Text;
break;
}
}
}
private NodeType getNodeType(RadTreeNode rtn)
{
NodeType ret = NodeType.inbox;
if (rtn.Nodes.Count > 0)
{
if (rtn.Parent != null)
{
if (inboxSelec)
{
ret = NodeType.grInbox;
}
else
{
ret = NodeType.grOutbox;
}
}
else
{
if (inboxSelec)
{
ret = NodeType.inbox;
}
else
{
ret = NodeType.outbox;
}
if (trashSelec)
{
ret = NodeType.trash;
}
}
}
else
{
if (selectedSC_ID != 0)
{
if (inboxSelec)
{
ret = NodeType.subInbox;
}
else
{
ret = NodeType.subOutbox;
}
}
else
{
if (inboxSelec)
{
ret = NodeType.grInbox;
}
else
{
ret = NodeType.grOutbox;
}
if (trashSelec)
{
ret = NodeType.trash;
}
}
}
return ret;
}
private void CheckAllInbox()
{
int[] scidArray = new int[arVehSCID.Count];
int i = 0;
foreach (VehandID obj in arVehSCID)
{
try
{
scidArray[i] = obj.sc_id;
i++;
}
catch (Exception ex) { SM.Debug("Ex: "+ex.ToString()); }
}
//Console.WriteLine("CheckAllInbox getInboxSMS");
getInboxSMS(scidArray);
htSUIDwithNewSMS.Clear();
if (arInboxSMS.Count > 0)
{
foreach (SMSfromDB obj in arInboxSMS)
{
if (obj.status == (int)TextStatus.SD_NO_GW || obj.status == (int)TextStatus.UNREAD_OUT
|| obj.status == (int)TextStatus.UNREAD_IN || obj.status == (int)TextStatus.UNKNOWN)
{
if (!htSUIDwithNewSMS.Contains(obj.sc_id))
{
htSUIDwithNewSMS.Add(obj.sc_id, 0);
}
int tempI = Convert.ToInt32(htSUIDwithNewSMS[obj.sc_id]);
tempI++;
htSUIDwithNewSMS[obj.sc_id] = tempI;
}
}
}
}
private void update4DeletedSMS()
{
try
{
arDeletedSMS = smdbObj.get_Deleted_SMS();
}
catch (Exception ex)
{
SM.Debug("Error update4DeletedSMS:"+ex.ToString());
}
SMSGridView.Rows.Clear();
SMSGridView.Columns["Dest"].IsVisible = true;
SMSGridView.Columns["Dest"].HeaderText = wordTo;
SMSGridView.Columns["Source"].HeaderText = wordFrom;
Bitmap img = null;
Int32 stat = 0;
String email = "";
ListforGrid.Clear();
foreach (SMSfromDB obj in arDeletedSMS)
{
string content = obj.mes;
if (obj.mes.Length > 25)
{
//content = obj.mes.Substring(0, 25) + "...";
}
if (obj.status == (int)TextStatus.SD_NO_GW || obj.status == (int)TextStatus.UNREAD_OUT
|| obj.status == (int)TextStatus.UNREAD_IN || obj.status == (int)TextStatus.UNKNOWN)
{
img = global::Dispatcher.Properties.Resources.trashmic1;
stat = 0;
email = "";
}
else
{
if (obj.status == (int)TextStatus.UNREAD_EMAIL || obj.status == (int)TextStatus.READ_EMAIL)
{
img = global::Dispatcher.Properties.Resources.trashmic1;
stat = 2;
email = obj.email;
}
else
{
img = global::Dispatcher.Properties.Resources.trashmic1;
stat = 1;
email = "";
}
}
//set corect names
string subNAmeSource = "Unknown unit name1";
if (MainForm2.VehIDHash[obj.sc_id_sour] != null)
{
subNAmeSource = (string)MainForm2.VehIDHash[obj.sc_id_sour];
}
else
{
if (stat != 2)
{
subNAmeSource = "Dispatcher";
}
else
{
subNAmeSource = email;
}
}
string subNAmeDest = "Unknown unit name2";
if (MainForm2.VehIDHash[obj.sc_id_Dest] != null)
{
subNAmeDest = (string)MainForm2.VehIDHash[obj.sc_id_Dest];
}
else
{
if (stat != 2)
{
subNAmeDest = "Dispatcher";
}
else
{
subNAmeDest = email;
}
}
//ListforGrid.Add(new SMSDataforGRID(obj.idx, img, subNAmeSource, subNAmeDest, content, obj.mes, convDT.GetDTLocalFromSeconds(obj.date).ToString("MMM d,yyyy '-' HH:mm:ss"), stat, email));
try
{
String DataString = obj.date.GetRegionalFormat(MainForm2.is24hours, MainForm2.DayFirst);
SMSDataforGRID smsItem = new SMSDataforGRID(obj.idx, img, subNAmeSource, subNAmeDest, content, obj.mes, DataString, stat, email, obj.sc_id_sour, obj.sc_id_Dest,
(new DateTime(1970, 1, 1)).AddSeconds(obj.date));
smsItem.Color = obj.color;
ListforGrid.Add(smsItem);
}
catch (Exception ex)
{
SM.Debug("Error on gridview DateFormat:" + ex.ToString());
}
}
ArrayList positions = new ArrayList();
if (arInboxSMS.Count > 0)
{
try
{
SMSGridView.DataSource = null;
SMSGridView.DataSource = ListforGrid;
}
catch (Exception ex)
{
SM.Debug("Error on populate grid" + ex.ToString());
}
}
else
{
SMSGridView.Rows.Clear();
//SMSGridView.Refresh();
}
SMSGridView.Refresh();
SMSGridView.TableElement.ScrollToRow(0);
}
bool firstTime = true;
volatile List<SMSDataforGRID> ListforGrid = new List<SMSDataforGRID>();
public void updateDataGrid(int[] sc_id, bool inbox, bool trash, Boolean jump_over_select, Boolean ifisGroup)
{
try
{
// ArrayList ar = new ArrayList();
if (!jump_over_select)
{
if (inbox)
{
getInboxSMS(sc_id);
SMSGridView.Columns["Dest"].IsVisible = false;
}
else
{
if (!ifisGroup)
getOutboxSMS(sc_id);
else
getOutboxSMS_ifisGroup(sc_id);
SMSGridView.Columns["Dest"].IsVisible = false;
}
}
if (trash)
{
update4DeletedSMS();
}
else
{
SMSGridView.Rows.Clear();
ListforGrid.Clear();
if (arInboxSMS.Count <= 2000)
{
btn_PrevPage.Visible = false;
btn_NextPage.Visible = false;
foreach (SMSfromDB obj in arInboxSMS)
{
string subNAme = "Unknown unit name";
Bitmap img = null;
Int32 stat = 0;
String email = "";
// if unit is found and not a group node selected
if (MainForm2.VehIDHash[obj.sc_id] != null && SMSTreeView.SelectedNode.Nodes.Count >= 0)
{
subNAme = (string)MainForm2.VehIDHash[obj.sc_id];
}
// set name for group as destination one
else
subNAme = SMSTreeView.SelectedNode.Text;
if (!inbox)
{
/*
if (obj.sc_id_Dest == obj.sc_id_sour)
subNAme = SMSTreeView.SelectedNode.Name;
* */
//if(SMSTreeView.SelectedNode.Name.Equals("Outbox"))
}
string content = obj.mes;
if (obj.mes.Length > 25)
{
//content = obj.mes.Substring(0, 25) + "...";
}
if (obj.status == (int)TextStatus.SD_NO_GW || obj.status == (int)TextStatus.UNREAD_OUT
|| obj.status == (int)TextStatus.UNREAD_IN || obj.status == (int)TextStatus.UNKNOWN)
{
img = global::Dispatcher.Properties.Resources.closedEnvelope;
stat = 0;
email = "";
}
else
{
if (obj.status == (int)TextStatus.UNREAD_EMAIL || obj.status == (int)TextStatus.READ_EMAIL)
{
img = global::Dispatcher.Properties.Resources.email;
stat = 2;
email = obj.email;
}
else
{
img = global::Dispatcher.Properties.Resources.openEnvelope;
stat = 1;
email = "";
}
}
//ListforGrid.Add(new SMSDataforGRID(obj.idx, img, subNAme, "", content, obj.mes, convDT.GetDTLocalFromSeconds(obj.date).ToString("MMM d,yyyy '-' HH:mm:ss"), stat, email));
try
{
String DataString = "";
DataString = obj.date.GetRegionalFormat(MainForm2.is24hours, MainForm2.DayFirst);
//if (MainForm2.is24hours)
//{
// if (MainForm2.DayFirst)
// DataString = convDT.GetDTLocalFromSeconds(obj.date).ToString("dd/MM/yyyy HH:mm:ss, ddd");
// else
// DataString = convDT.GetDTLocalFromSeconds(obj.date).ToString("MM/dd/yyyy HH:mm:ss, ddd");
//}
//else
//{
// if (MainForm2.DayFirst)
// DataString = convDT.GetDTLocalFromSeconds(obj.date).ToString("dd/MM/yyyy hh:mm:ss tt, ddd");
// else
// DataString = convDT.GetDTLocalFromSeconds(obj.date).ToString("MM/dd/yyyy hh:mm:ss tt, ddd");
//}
// find spaces to add a new line between them
string[] split = DataString.Split(' ');
if (split.Length == 4)
DataString = String.Format("{0}\n{1} {2} {3}", split[0], split[1], split[2], split[3]);
else if (split.Length == 3)
DataString = String.Format("{0}\n{1} {2}", split[0], split[1], split[2]);
else if (split.Length == 2)
DataString = String.Format("{0}\n{1}", split[0], split[1]);
SMSDataforGRID gridItem = new SMSDataforGRID(obj.idx, img, subNAme, "", content, obj.mes, DataString, stat, email, obj.sc_id, 0,
(new DateTime(1970, 1, 1)).AddSeconds(obj.date));
gridItem.Color = obj.color;
ListforGrid.Add(gridItem);
}
catch (Exception ex)
{
SM.Debug("Error on gridview DateFormat:" + ex.ToString());
}
}
}
else
{
arInboxSMSLimit2000 = smdbObj.get_SMS_with_limit(whereCommand, Type_Inbox_for_limit2000, PageforInbox);
Console.WriteLine("Page for Index value:" + PageforInbox);
if (PageforInbox > 0) btn_PrevPage.Visible = true;
else btn_PrevPage.Visible = false;
if (arInboxSMSLimit2000.Count == 2000) btn_NextPage.Visible = true;
else btn_NextPage.Visible = false;
foreach (SMSfromDB obj in arInboxSMSLimit2000)
{
string subNAme = "Unknown unit name4";
Bitmap img = null;
Int32 stat = 0;
String email = "";
if (MainForm2.VehIDHash[obj.sc_id] != null)
{
subNAme = (string)MainForm2.VehIDHash[obj.sc_id];
}
if (obj.sc_id_Dest == obj.sc_id_sour)
subNAme = SMSTreeView.SelectedNode.Name;
string content = obj.mes;
if (obj.mes.Length > 25)
{
//content = obj.mes.Substring(0, 25) + "...";
}
if (obj.status == (int)TextStatus.SD_NO_GW || obj.status == (int)TextStatus.UNREAD_OUT
|| obj.status == (int)TextStatus.UNREAD_IN || obj.status == (int)TextStatus.UNKNOWN)
{
img = global::Dispatcher.Properties.Resources.closedEnvelope;
stat = 0;
email = "";
}
else
{
if (obj.status == (int)TextStatus.UNREAD_EMAIL || obj.status == (int)TextStatus.READ_EMAIL)
{
img = global::Dispatcher.Properties.Resources.email;
stat = 2;
email = obj.email;
}
else
{
img = global::Dispatcher.Properties.Resources.openEnvelope;
stat = 1;
email = "";
}
}
//ListforGrid.Add(new SMSDataforGRID(obj.idx, img, subNAme, "", content, obj.mes, convDT.GetDTLocalFromSeconds(obj.date).ToString("MMM d,yyyy '-' HH:mm:ss"), stat, email));
try
{
String DataString = "";
DataString = obj.date.GetRegionalFormat(MainForm2.is24hours, MainForm2.DayFirst);
//if (MainForm2.is24hours)
//{
// if (MainForm2.DayFirst)
// DataString = convDT.GetDTLocalFromSeconds(obj.date).ToString("dd/MM/yyyy HH:mm:ss, ddd");
// else
// DataString = convDT.GetDTLocalFromSeconds(obj.date).ToString("MM/dd/yyyy HH:mm:ss, ddd");
//}
//else
//{
// if (MainForm2.DayFirst)
// DataString = convDT.GetDTLocalFromSeconds(obj.date).ToString("dd/MM/yyyy hh:mm:ss tt, ddd");
// else
// DataString = convDT.GetDTLocalFromSeconds(obj.date).ToString("MM/dd/yyyy hh:mm:ss tt, ddd");
//}
// find spaces to add a new line between them
string[] split = DataString.Split(' ');
if (split.Length == 4)
DataString = String.Format("{0}\n{1} {2} {3}", split[0], split[1], split[2], split[3]);
else if (split.Length == 3)
DataString = String.Format("{0}\n{1} {2}", split[0], split[1], split[2]);
else if (split.Length == 2)
DataString = String.Format("{0}\n{1}", split[0], split[1]);
SMSDataforGRID gridItem = new SMSDataforGRID(obj.idx, img, subNAme, "", content, obj.mes, DataString, stat, email, obj.sc_id, 0,
(new DateTime(1970, 1, 1)).AddSeconds(obj.date));
gridItem.Color = obj.color;
ListforGrid.Add(gridItem);
}
catch (Exception ex)
{
SM.Debug("Error on gridview DateFormat:" + ex.ToString());
}
}
}
ArrayList positions = new ArrayList();
if (arInboxSMS.Count > 0 )
{
try
{
SMSGridView.DataSource = null;
SMSGridView.DataSource = ListforGrid;
}
catch (Exception ex)
{
SM.Debug("Error on populate grid" + ex.ToString());
}
}
else
{
SMSGridView.Rows.Clear();
SMSGridView.Refresh();
}
SMSGridView.TableElement.ScrollToRow(0);
}
SMSGridView.Refresh();
SMSGridView.TableElement.ScrollToRow(0);
}
catch (Exception ex)
{
Utils.WriteLine(ex.ToString(), ConsoleColor.Red);
}
}
public void updateOnlytree(Int32 _sc_id,String _vehName)
{
try
{
Int32 sc_idd = _sc_id;
String vehName = _vehName;
RadTreeNode selNode = SMSTreeView.SelectedNode;
foreach (RadTreeNode node in SMSTreeView.Nodes)
{
if (node.Name.Contains("Inbox"))
{
foreach (RadTreeNode nodegr in node.Nodes)
{
if (nodegr.Nodes.Count == 0)
{
if (nodegr.Name.CompareTo(vehName) == 0)
{
selNode = nodegr;
break;
}
}
else
{
foreach (RadTreeNode nodein in nodegr.Nodes)
{
if (nodein.Name.CompareTo(vehName) == 0)
{
selNode = nodein;
break;
}
}
}
}
break;
}
}
selNode.Text = vehName;
if (htSUIDwithNewSMS.Contains(sc_idd))
{
int tempI = Convert.ToInt32(htSUIDwithNewSMS[sc_idd]);
tempI++;
htSUIDwithNewSMS[sc_idd] = tempI;
selNode.Text += " [" + htSUIDwithNewSMS[sc_idd].ToString() + "]";
selNode.Font = new Font(
new FontFamily("Segoe UI"),
12,
FontStyle.Bold,
GraphicsUnit.Pixel);
//selNode.Font = new System.Drawing.Font("Tahoma", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
}
else
{
htSUIDwithNewSMS.Add(sc_idd, 1);
selNode.Text += " [" + htSUIDwithNewSMS[sc_idd].ToString() + "]";
selNode.Font = new Font(
new FontFamily("Segoe UI"),
12,
FontStyle.Bold,
GraphicsUnit.Pixel);
selNode.Font = new System.Drawing.Font("Tahoma", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
}
// notify that messages has changed
parent.UpdateUnreadMessagesNumber();
}
catch (Exception ex)
{
SM.Debug("Error on updating the tree:" + ex.ToString());
}
}
public void updateInboxAndOutboxView(Boolean fromDB)
{
SM.Debug("Enter on update Inbox");
arVehSCID.Clear();
if (fromDB) CheckAllInbox();
SMSTreeView.Nodes.Clear();
SMSTreeView.MultiSelect = false;
RadTreeNode inboxNode = new RadTreeNode(wordInbox);
inboxNode.Name = "Inbox";
inboxNode.Font = new Font(
new FontFamily("Segoe UI"),
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
// add image to the dictionary if not exists
Image img = Utils.ScaleImage(global::Dispatcher.Properties.Resources.s_inbox, 37, 37);
if (!MainForm2.imagesDictionary.ContainsKey("s_inbox" + "_37"))
MainForm2.imagesDictionary.Add("s_inbox" + "_37", Utils.ChangeColor((Bitmap)img, MainForm2.ButtonColor));
// set the icon for the unit
inboxNode.Image = MainForm2.imagesDictionary["s_inbox" + "_37"];
inboxNode.BackColor = Color.FromArgb(225, 228, 219);
inboxNode.ItemHeight = 40;
inboxNode.AllowDrop = true;
//add elements in groups
GroupClass g;
ArrayList arrSCidsINGroups = new ArrayList();
foreach (int i in MainForm2.GroupHash.Keys)
{
g = (GroupClass)MainForm2.GroupHash[i];
RadTreeNode nodeGroup = new RadTreeNode(g.name.ToUpper());
nodeGroup.Name = g.name.ToUpper();
nodeGroup.Image = Utils.ChangeColor(global::Dispatcher.Properties.Resources.s_group, MainForm2.ButtonColor);
foreach (int scID in g.arrSc_id)
{
if (MainForm2.VehIDHash.ContainsKey(scID))
{
RadTreeNode node1 = new RadTreeNode((string)MainForm2.VehIDHash[scID]);
node1.Name = (string)MainForm2.VehIDHash[scID];
#region NODE IMAGE
Car crtCar = ((Car)MainForm2.carlist[((Vehicle)MainForm2.vehicleHT[(string)MainForm2.VehIDHash[scID]]).IconID]);
if (crtCar != null)
{
String iconPath = crtCar.listFilePath;
try
{
Bitmap bmp = new Bitmap(iconPath);
Image tmp2 = bmp; //tmp.ToBitmap();
tmp2.Tag = crtCar.listFilePath;
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey(crtCar.listFilePath + "_16"))
MainForm2.imagesDictionary.Add(crtCar.listFilePath + "_16", Utils.ScaleImage(tmp2, 16, 16));
// set the icon for the unit
node1.Image = MainForm2.imagesDictionary[crtCar.listFilePath + "_16"];
}
catch (Exception)
{
SM.Debug("Grid icon could not be found [" + iconPath + "]");
node1.Image = global::Dispatcher.Properties.Resources.subscriber;
}
}
#endregion
arrSCidsINGroups.Add(scID);
node1.ContextMenu = Menu4UnitsSMS;
// set
node1.Tag = scID;
//test if u got new sms
if (htSUIDwithNewSMS.Contains(scID))
{
node1.Text += " [" + htSUIDwithNewSMS[scID].ToString() + "]";
node1.Font = new Font(
new FontFamily("Segoe UI"),
12,
FontStyle.Bold,
GraphicsUnit.Pixel);
//node1.Font = new System.Drawing.Font("Tahoma", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
}
else
{
node1.Font = new Font(
new FontFamily("Segoe UI"),
12,
FontStyle.Regular,
GraphicsUnit.Pixel);
//node1.Font = new System.Drawing.Font("Tahoma", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Regular))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
}
nodeGroup.Nodes.Add(node1);
//nodeGroup.Font = new System.Drawing.Font("Tahoma", 11F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
node1.AllowDrop = false;
}
}
nodeGroup.AllowDrop = true;
// set the group ID as Tag value
nodeGroup.Tag = g.cps_id;
// change font for group node
nodeGroup.Font = new Font(
new FontFamily("Segoe UI"),
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
//add only groups that have 1 ore more elemets
if (nodeGroup.Nodes.Count > 0)
inboxNode.Nodes.Add(nodeGroup);
}
//add groups without elements
foreach (string Gname in htGroupsKeyNAmeValueID.Keys)
{
bool found = false;
foreach (int j in MainForm2.GroupHash.Keys)
{
g = (GroupClass)MainForm2.GroupHash[j];
if (g.name == Gname)
{
found = true;
}
}
if (!found)
{
RadTreeNode nodeGroup = new RadTreeNode(Gname.ToUpper());
nodeGroup.Name = Gname;
nodeGroup.Image = Utils.ChangeColor(global::Dispatcher.Properties.Resources.s_group, MainForm2.ButtonColor);
nodeGroup.AllowDrop = true;
// set the group ID as Tag value
nodeGroup.Tag = htGroupsKeyNAmeValueID[Gname];
nodeGroup.Font = new Font(
new FontFamily("Segoe UI"),
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
//nodeGroup.Font = new System.Drawing.Font("Tahoma", 11F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
inboxNode.Nodes.Add(nodeGroup);
}
}
//add elements NOT in groups
foreach (VehandID obj in MainForm2.arVehSCID)
{
if (!arrSCidsINGroups.Contains(obj.sc_id))
{
RadTreeNode node1 = new RadTreeNode((string)MainForm2.VehIDHash[obj.sc_id]);
node1.Name = (string)MainForm2.VehIDHash[obj.sc_id];
node1.AllowDrop = false;
node1.ContextMenu = Menu4UnitsSMS;
// set the unit ID as Tag value
node1.Tag = obj.sc_id;
#region NODE IMAGE
Car crtCar = ((Car)MainForm2.carlist[((Vehicle)MainForm2.vehicleHT[(string)MainForm2.VehIDHash[obj.sc_id]]).IconID]);
if (crtCar != null)
{
String iconPath = crtCar.listFilePath;
try
{
Bitmap bmp = new Bitmap(iconPath);
Image tmp2 = bmp; //tmp.ToBitmap();
tmp2.Tag = crtCar.listFilePath;
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey(crtCar.listFilePath + "_16"))
MainForm2.imagesDictionary.Add(crtCar.listFilePath + "_16", Utils.ScaleImage(tmp2, 16, 16));
// set the icon for the unit
node1.Image = MainForm2.imagesDictionary[crtCar.listFilePath + "_16"];
}
catch (Exception)
{
SM.Debug("Grid icon could not be found [" + iconPath + "]");
node1.Image = global::Dispatcher.Properties.Resources.subscriber;
}
}
#endregion
if (htSUIDwithNewSMS.Contains(obj.sc_id))
{
node1.Text += " [" + htSUIDwithNewSMS[obj.sc_id].ToString() + "]";
node1.Font = new Font(
new FontFamily("Segoe UI"),
12,
FontStyle.Bold,
GraphicsUnit.Pixel);
//node1.Font = new System.Drawing.Font("Tahoma", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//node1.ForeColor = Color.Red;
}
else
node1.Font = new Font(
new FontFamily("Segoe UI"),
12,
FontStyle.Regular,
GraphicsUnit.Pixel);
inboxNode.Nodes.Add(node1);
}
}
//SMSTreeView.MultiSelect = false;
SMSTreeView.Nodes.Add(inboxNode);
////////////////outBOX
RadTreeNode outboxNode = new RadTreeNode(wordOutbox);
outboxNode.Name = "Outbox";
outboxNode.BackColor = Color.FromArgb(225, 228, 219);
outboxNode.Font = new Font(
new FontFamily("Segoe UI"),
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
//outboxNode.Font = new System.Drawing.Font("Tahoma", 13F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Regular))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
Image img2 = Utils.ScaleImage(global::Dispatcher.Properties.Resources.s_outbox, 37, 37);
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("s_outbox" + "_37"))
MainForm2.imagesDictionary.Add("s_outbox" + "_37", Utils.ChangeColor((Bitmap)img2, MainForm2.ButtonColor));
// set the icon for the unit
outboxNode.Image = MainForm2.imagesDictionary["s_outbox" + "_37"];
outboxNode.ItemHeight = 40;
outboxNode.AllowDrop = true;
arrSCidsINGroups = new ArrayList();
foreach (int i in MainForm2.GroupHash.Keys)
{
g = (GroupClass)MainForm2.GroupHash[i];
RadTreeNode nodeGroup = new RadTreeNode(g.name.ToUpper());
nodeGroup.Name = g.name.ToUpper();
// set the group ID as Tag value
nodeGroup.Tag = g.cps_id;
foreach (int scID in g.arrSc_id)
{
if (MainForm2.VehIDHash.ContainsKey(scID))
{
RadTreeNode node1 = new RadTreeNode((string)MainForm2.VehIDHash[scID]);
node1.Name = (string)MainForm2.VehIDHash[scID];
arrSCidsINGroups.Add(scID);
node1.AllowDrop = false;
node1.ContextMenu = Menu4UnitsSMS;
// set the unit ID as Tag value
node1.Tag = scID;
node1.Font = new Font(
new FontFamily("Segoe UI"),
12,
FontStyle.Regular,
GraphicsUnit.Pixel);
#region NODE IMAGE
Car crtCar = ((Car)MainForm2.carlist[((Vehicle)MainForm2.vehicleHT[(string)MainForm2.VehIDHash[scID]]).IconID]);
if (crtCar != null)
{
String iconPath = crtCar.listFilePath;
try
{
Bitmap bmp = new Bitmap(iconPath);
Image tmp2 = bmp; //tmp.ToBitmap();
tmp2.Tag = crtCar.listFilePath;
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey(crtCar.listFilePath + "_16"))
MainForm2.imagesDictionary.Add(crtCar.listFilePath + "_16", Utils.ScaleImage(tmp2, 16, 16));
// set the icon for the unit
node1.Image = MainForm2.imagesDictionary[crtCar.listFilePath + "_16"];
}
catch (Exception)
{
SM.Debug("Grid icon could not be found [" + iconPath + "]");
node1.Image = global::Dispatcher.Properties.Resources.subscriber;
}
}
#endregion
nodeGroup.Nodes.Add(node1);
}
}
nodeGroup.AllowDrop = true;
// set font for the node group
nodeGroup.Font = new Font(
new FontFamily("Segoe UI"),
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
nodeGroup.Image = Utils.ChangeColor(global::Dispatcher.Properties.Resources.s_group, MainForm2.ButtonColor);
//add only groups that have 1 ore more elemets
if (nodeGroup.Nodes.Count > 0)
outboxNode.Nodes.Add(nodeGroup);
}
//add groups without elements
SM.Debug("GroupHash.Keys Count" + MainForm2.GroupHash.Keys.Count);
foreach (string Gname in htGroupsKeyNAmeValueID.Keys)
{
bool found = false;
foreach (int j in MainForm2.GroupHash.Keys)
{
g = (GroupClass)MainForm2.GroupHash[j];
if (g.name == Gname)
{
found = true;
}
}
if (!found)
{
RadTreeNode nodeGroup = new RadTreeNode(Gname.ToUpper());
nodeGroup.Name = Gname.ToUpper();
nodeGroup.AllowDrop = true;
// set the group ID as Tag value
nodeGroup.Tag = htGroupsKeyNAmeValueID[Gname];
nodeGroup.Font = new Font(
new FontFamily("Segoe UI"),
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
//nodeGroup.Font = new System.Drawing.Font("Tahoma", 11F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
nodeGroup.Image = global::Dispatcher.Properties.Resources.users;
outboxNode.Nodes.Add(nodeGroup);
}
}
//add elements NOT in groups
foreach (VehandID obj in MainForm2.arVehSCID)
{
if (!arrSCidsINGroups.Contains(obj.sc_id))
{
RadTreeNode node1 = new RadTreeNode((string)MainForm2.VehIDHash[obj.sc_id]);
node1.Name = (string)MainForm2.VehIDHash[obj.sc_id];
node1.AllowDrop = false;
node1.ContextMenu = Menu4UnitsSMS;
// set the unit ID as Tag value
node1.Tag = obj.sc_id;
node1.Font = new Font(
new FontFamily("Segoe UI"),
12,
FontStyle.Regular,
GraphicsUnit.Pixel);
#region NODE IMAGE
Car crtCar = ((Car)MainForm2.carlist[((Vehicle)MainForm2.vehicleHT[(string)MainForm2.VehIDHash[obj.sc_id]]).IconID]);
if (crtCar != null)
{
String iconPath = crtCar.listFilePath;
try
{
Bitmap bmp = new Bitmap(iconPath);
Image tmp2 = bmp; //tmp.ToBitmap();
tmp2.Tag = crtCar.listFilePath;
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey(crtCar.listFilePath + "_16"))
MainForm2.imagesDictionary.Add(crtCar.listFilePath + "_16", Utils.ScaleImage(tmp2, 16, 16));
// set the icon for the unit
node1.Image = MainForm2.imagesDictionary[crtCar.listFilePath + "_16"];
}
catch (Exception)
{
SM.Debug("Grid icon could not be found [" + iconPath + "]");
node1.Image = global::Dispatcher.Properties.Resources.subscriber;
}
}
#endregion
outboxNode.Nodes.Add(node1);
}
}
RadTreeNode TrashNode = new RadTreeNode(wordRecyBin);
TrashNode.Name = "Recycle";
TrashNode.Font = new Font(
new FontFamily("Segoe UI"),
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
//TrashNode.Font = new System.Drawing.Font("Tahoma", 13F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Regular))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
TrashNode.BackColor = Color.FromArgb(225, 228, 219);
Image img3 = Utils.ScaleImage(global::Dispatcher.Properties.Resources.trash_activ, 37, 37);
// add image to the dictionary if not exists
if (!MainForm2.imagesDictionary.ContainsKey("trash_activ" + "_37"))
MainForm2.imagesDictionary.Add("trash_activ" + "_37", Utils.ChangeColor((Bitmap)img3, MainForm2.ButtonColor));
// set the icon for the unit
TrashNode.Image = MainForm2.imagesDictionary["trash_activ" + "_37"];
TrashNode.ItemHeight = 40;
SMSTreeView.Nodes.Add(outboxNode);
SMSTreeView.Nodes.Add(TrashNode);
SMSTreeView.ExpandAll();
//reselect the previous tree node
if (selectedTreeNode != null)
{
switch (selectedNodeType)
{
case NodeType.inbox:
SMSTreeView.Nodes[0].Selected = true;
break;
case NodeType.outbox:
SMSTreeView.Nodes[1].Selected = true;
break;
case NodeType.trash:
SMSTreeView.Nodes[2].Selected = true;
break;
case NodeType.grInbox:
SM.Debug("Reselcting inbox group:" + selectedTreeNode.Name);
foreach (RadTreeNode node in SMSTreeView.Nodes[0].Nodes)
{
if (node.Name == selectedTreeNode.Name)
{
node.Selected = true;
}
}
break;
case NodeType.grOutbox:
SM.Debug("Reselcting outbox group:" + selectedTreeNode.Name);
foreach (RadTreeNode node in SMSTreeView.Nodes[1].Nodes)
{
if (node.Name == selectedTreeNode.Name)
{
node.Selected = true;
}
}
break;
case NodeType.subInbox:
SM.Debug("Reselcting inbox subscriber:" + selectedTreeNode.Name);
foreach (RadTreeNode nodeGR in SMSTreeView.Nodes[0].Nodes)
{
foreach (RadTreeNode node in nodeGR.Nodes)
{
if (node.Name == selectedTreeNode.Name)
{
node.Selected = true;
}
}
if (nodeGR.Name == selectedTreeNode.Name)
{
nodeGR.Selected = true;
}
}
break;
case NodeType.subOutbox:
SM.Debug("Reselcting outbox subscriber:" + selectedTreeNode.Text);
foreach (RadTreeNode nodeGR in SMSTreeView.Nodes[1].Nodes)
{
foreach (RadTreeNode node in nodeGR.Nodes)
{
if (node.Name == selectedTreeNode.Name)
{
node.Selected = true;
}
}
if (nodeGR.Name == selectedTreeNode.Name)
{
nodeGR.Selected = true;
}
}
break;
}
}
else
SMSTreeView.SelectedNode = SMSTreeView.Nodes[0];
SMSTreeView_Click(SMSTreeView, null);
}
private String oldSelected = "";
private String oldparent = "";
private void SMSTreeView_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
{
SMSTreeView_Click(SMSTreeView, null);
}
private void SMSTreeView_Click(object sender, EventArgs e)
{
if (SMSTreeView.SelectedNode == null)
return;
// update text for the LOGGED IN USER
labelUser.Text = SMSTreeView.SelectedNode.Text.Split('[')[0].ToUpper();
if (CanSendQuickTextMessage(SMSTreeView.SelectedNode))
{
//rbtSendQuick.Enabled = true;
rtbQuickText.Enabled = true;
rtbQuickText.Text = "";
}
else
{
//rbtSendQuick.Enabled = false;
rtbQuickText.Enabled = false;
rtbQuickText.Text = "";
}
try
{
// refresh tree if desired by sending a new sms
if (((SMSTreeView.SelectedNode != null) && ((oldSelected != SMSTreeView.SelectedNode.Name) || (getParent(SMSTreeView.SelectedNode).Name!=oldparent)))
|| sender != SMSTreeView)
{
oldSelected = SMSTreeView.SelectedNode.Name;
oldparent = getParent(SMSTreeView.SelectedNode).Name;
webBrowser1.DocumentText = "";
selectedTreeNode = SMSTreeView.SelectedNode;
if (MainForm2.vehicleHT.ContainsKey(SMSTreeView.SelectedNode.Name))
{
selectedSC_ID = ((Vehicle)MainForm2.vehicleHT[SMSTreeView.SelectedNode.Name]).sc_id;
}
else
{
selectedSC_ID = 0;
}
SM.Debug("Selected node = " + SMSTreeView.SelectedNode.Name + " with sc_id = " + selectedSC_ID);
if(SMSTreeView.SelectedNode.Nodes.Count > 0)
rtbQuickText.NullText = String.Format(MainForm2.returnLNGString("sendquickgroupsms"), SMSTreeView.SelectedNode.Text.Split('[')[0]);
else
// update null text for quick send textbox
rtbQuickText.NullText = String.Format(MainForm2.returnLNGString("sendquicksms"), SMSTreeView.SelectedNode.Text.Split('[')[0]);
// display maximum number of characters
rtbQuickText.MaxLength = SmsUtils.GetMaxNumberOfCharacters(MainForm2.radioType);
if (MainForm2.vehicleHT.Contains(SMSTreeView.SelectedNode.Name))
{
((Vehicle)MainForm2.vehicleHT[SMSTreeView.SelectedNode.Name]).CheckPositionInSystem();
string GatewayAndRadioID = ((Vehicle)MainForm2.vehicleHT[SMSTreeView.SelectedNode.Name]).GwandRadioID;
int gwType = (int)GatewayType.Unknown;
if (MainForm2.radioGwHT[GatewayAndRadioID] != null)
{
gwType = ((RadioGateway)MainForm2.radioGwHT[GatewayAndRadioID]).Type;
rtbQuickText.MaxLength = SmsUtils.GetMaxNumberOfCharacters(gwType);
}
}
labelCount.Text = String.Format(MainForm2.returnLNGString("charactersLeft"), rtbQuickText.MaxLength);
//txTO.Text = SMSTreeView.SelectedNode.Name;
RadTreeNode inOrOutNode = getParent(SMSTreeView.SelectedNode);
if (inOrOutNode.Name == "Inbox")
{
try
{
SMSGridView.Columns["Date"].HeaderText = MainForm2.returnLNGString("Received");
inboxSelec = true;
SMSGridView.Columns["Source"].HeaderText = wordFrom;
int[] scidArray = getChildSC_ID(SMSTreeView.SelectedNode);
selectedSC_IDlist = scidArray;
if (scidArray.Length > 0)
{
updateDataGrid(scidArray, true, false,false,false);
trashSelec = false;
}
}
catch (Exception ex)
{
SM.Debug("Ex:" + ex.ToString());
}
}
else
{
if (inOrOutNode.Name == "Outbox")
{
// this is a GROUP NODE or an unit with no group :-?
SMSGridView.Columns["Date"].HeaderText = MainForm2.returnLNGString("send2");
try
{
inboxSelec = false;
SMSGridView.Columns["Source"].HeaderText = wordTo;
Boolean ifisGroup = false;
int[] scidArray = getChildSC_ID_GroupID(SMSTreeView.SelectedNode, out ifisGroup);
//if (SMSTreeView.SelectedNode.Nodes.Count > 0)
//{
// ifisGroup = true;
// scidArray = new int[] { Int16.Parse(SMSTreeView.SelectedNode.Tag.ToString()) };
//}
selectedSC_IDlist = scidArray;
if (scidArray.Length > 0)
{
updateDataGrid(scidArray, false, false,false,ifisGroup);
trashSelec = false;
}
}
catch (Exception ex)
{
SM.Debug("Ex:" + ex.ToString());
}
}
else
{
try
{
inboxSelec = false;
//SMSGridView.Columns[2].HeaderText = "To/From";
int[] scidArray = getChildSC_ID(SMSTreeView.SelectedNode);
updateDataGrid(scidArray, false, true,false,false);
trashSelec = true;
inboxSelec = false;
}
catch (Exception ex)
{
SM.Debug("Ex:" + ex.ToString());
}
}
}
// find out what kind of node is it ... inbox/outbox group or subscriber
selectedNodeType = getNodeType(selectedTreeNode);
//set sms label
SetLabelText(selectedTreeNode);
if (SMSGridView.RowCount > 0)
{
//SelectSMSandDisplay(false);
panelNoEvents.Visible = false;
}
else
panelNoEvents.Visible = true;
}
}
catch (Exception ex)
{
SM.Debug("Selected node exception:"+ex.ToString());
}
}
/// <summary>
/// <para>Verific daca activez sau nu butonul de send quick text</para>
/// <para>in functie de nodul selectat</para>
/// </summary>
/// <param name="selectedTreeNode">nodul selectat</param>
/// <returns>true daca pot trimite quick text, false altfel</returns>
private bool CanSendQuickTextMessage(RadTreeNode selectedTreeNode)
{
// enable or disable the quick text option depending on the level
// of the tree view which is selected
if (SMSTreeView.SelectedNode == null)
return false;
else if (SMSTreeView.SelectedNode.Level == 0)
return false;
else if (SMSTreeView.SelectedNode.Nodes.Count > 0)
return true;
else if (SMSTreeView.SelectedNode.GetNodeCount(true) != 0)
{
// Nodul este un grup
// Nu permit quick text message pentru atlas, Simoco, conectPlus, turborepeater, tetra
if (MainForm2.radioType == RADIOTYPE.MOTO || MainForm2.radioType == RADIOTYPE.HYT || MainForm2.radioType == RADIOTYPE.HARRIS)
return true;
else
return false;
}
else
{
return true;
}
}
private void SMSTreeView_DragEnded(object sender, RadTreeViewDragEventArgs e)
{
if (selectedNodeType == NodeType.subInbox || selectedNodeType == NodeType.subOutbox)
{
int[] arryS = getChildSC_ID(e.Node);
if (arryS != null)
{
if (arryS.Length == 1)
{
try
{
if (htGroupsKeyNAmeValueID.ContainsKey(e.TargetNode.Name))
{
SM.Debug("Valid drag and drop ---- moving item with sc_id " + arryS[0] + " TO group with id " + htGroupsKeyNAmeValueID[e.TargetNode.Name]);
smdbObj.AddGroupElement(arryS[0], Convert.ToInt32(htGroupsKeyNAmeValueID[e.TargetNode.Name]));
}
else
{
SM.Debug("Valid drag and drop ---- moving item with sc_id " + arryS[0] + " TO inbox or outbox");
smdbObj.RemoveGroupElement(arryS[0]);
}
MainForm2.GroupHash = smdbObj.Select_groups();
}
catch (Exception ex)
{
SM.Debug("Ex:" + ex.ToString());
}
}
else
{
SM.Debug("Invalid drag and drop... ");
}
}
}
updateInboxAndOutboxView(true);
}
private void SMSGridView_CellClick(object sender, GridViewCellEventArgs e)
{
if (SMSGridView.CurrentCell != null && e.Column.Name.Equals("Color") && !(e.Row is GridViewTableHeaderRowInfo))
SMSGridView.ContextMenuManager.ShowContextMenu(SMSGridView.CurrentCell);
else
{
if (PageforInbox == 0)
SelectSMSandDisplay(false);
else
SelectSMSandDisplay(true);
if (GetTreeLevel() == TreeLevel.OUTBOX && SMSGridView.SelectedRows.Count == 1)
{
foreach (GridViewRowInfo r in SMSGridView.SelectedRows)
{
smdbObj.Update_SMS(
(GetTreeLevel() == TreeLevel.INBOX ? (int)TextStatus.READ_IN : (int)TextStatus.READ_OUT),
Convert.ToInt32(r.Cells["Idx"].Value));
SMSDataforGRID gridItem = r.DataBoundItem as SMSDataforGRID;
if (gridItem != null)
{
gridItem.Icon = global::Dispatcher.Properties.Resources.openEnvelope;
gridItem.Status = 1;
}
r.Cells["Icon"].Value = global::Dispatcher.Properties.Resources.openEnvelope;
r.Cells["Status"].Value = 1;
}
// notify that messages has changed
parent.UpdateUnreadMessagesNumber();
}
}
}
/// <summary>
/// Open the context menu when the Color cell is double clicked
/// </summary>
private void SMSGridView_CellDoubleClick(object sender, GridViewCellEventArgs e)
{
if (SMSGridView.CurrentCell != null && e.Column.Name.Equals("Color") && !(e.Row is GridViewTableHeaderRowInfo))
SMSGridView.ContextMenuManager.ShowContextMenu(SMSGridView.CurrentCell);
}
private void SelectSMSandDisplay(Boolean with_out_refresh)
{
SM.Debug("Selected rows count = " + SMSGridView.SelectedRows.Count);
if (SMSGridView.SelectedRows.Count > 0)
{
slectedSMSidx = new int[SMSGridView.SelectedRows.Count];
for (int i = 0; i < SMSGridView.SelectedRows.Count; i++)
{
slectedSMSidx[i] = Convert.ToInt32(SMSGridView.SelectedRows[i].Cells["Idx"].Value);
}
String s = (String)SMSGridView.SelectedRows[0].Cells["Message"].Value;
string head = "<html><body>";
string end = "</html></body>";
string from = "";
string to = "";
if (inboxSelec)
{
from = (string)SMSGridView.SelectedRows[0].Cells["Source"].Value;
if (Convert.ToInt32(SMSGridView.SelectedRows[0].Cells["Status"].Value) != (int)TextStatus.READ_OUT)
{
to = "Dispatcher";
}
else
{
to = (string)SMSGridView.SelectedRows[0].Cells["email"].Value;
}
}
else
{
if (Convert.ToInt32(SMSGridView.SelectedRows[0].Cells["Status"].Value) != (int)TextStatus.READ_OUT)
{
from = "Dispatcher";
}
else
{
from = (string)SMSGridView.SelectedRows[0].Cells["email"].Value;
}
to = (string)SMSGridView.SelectedRows[0].Cells["Source"].Value;
}
string status = "<div style=\"background: #D0D4DD\">" + "<FONT style=\"FONT-SIZE:10pt\" color=\"#000000\" face=\"Arial\">" +
wordFrom + ": " + from + "<br/>" +
wordTo + ": " + to + "<br/>" +
wordDate + ": " + (String)SMSGridView.SelectedRows[0].Cells["Date"].Value + "<br/>" +
"</FONT></div><br/>";
string text = "<div>" + s + "</div>";
webBrowser1.AllowNavigation = true;
webBrowser1.DocumentText = head + status + text + end;
Application.DoEvents();
webBrowser1.AllowNavigation = false;
if (inboxSelec)
{
if ((!with_out_refresh) && (Convert.ToInt32(SMSGridView.SelectedRows[0].Cells["Status"].Value) != (int)TextStatus.UNREAD_OUT))
{
try
{
Int32 sc_idd = (Int32)SMSGridView.SelectedRows[0].Cells["sc_id_source"].Value;
RadTreeNode selNode = SMSTreeView.SelectedNode;
foreach (RadTreeNode node in SMSTreeView.Nodes)
{
if (node.Name.Contains("Inbox"))
{
foreach (RadTreeNode nodegr in node.Nodes)
{
if (nodegr.Nodes.Count == 0)
{
if (nodegr.Name.CompareTo((string)SMSGridView.SelectedRows[0].Cells["Source"].Value) == 0)
{
selNode = nodegr;
break;
}
}
else
{
foreach (RadTreeNode nodein in nodegr.Nodes)
{
if (nodein.Name.CompareTo((string)SMSGridView.SelectedRows[0].Cells["Source"].Value) == 0)
{
selNode = nodein;
break;
}
}
}
}
break;
}
}
selNode.Text = (string)SMSGridView.SelectedRows[0].Cells["Source"].Value;
if (htSUIDwithNewSMS.Contains(sc_idd))
{
int tempI = Convert.ToInt32(htSUIDwithNewSMS[sc_idd]);
tempI--;
if (tempI == 0) htSUIDwithNewSMS.Remove(sc_idd);
else htSUIDwithNewSMS[sc_idd] = tempI;
if (htSUIDwithNewSMS.Contains(sc_idd))
{
selNode.Text += " [" + htSUIDwithNewSMS[sc_idd].ToString() + "]";
selNode.Font = new System.Drawing.Font("Tahoma", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
}
else
selNode.Font = new System.Drawing.Font("Tahoma", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Regular))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
}
else
selNode.Font = new System.Drawing.Font("Tahoma", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Regular))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
}
catch (Exception ex)
{
SM.Debug("Error on updating the tree:"+ex.ToString());
}
}
if (Convert.ToInt32(SMSGridView.SelectedRows[0].Cells["Status"].Value) != (int)TextStatus.READ_OUT)
{
//mark sms as read (status 4)
try
{
smdbObj.Update_SMS(4, Convert.ToInt32(SMSGridView.SelectedRows[0].Cells["Idx"].Value));
SMSDataforGRID gridItem = SMSGridView.SelectedRows[0].DataBoundItem as SMSDataforGRID;
if (gridItem != null)
{
gridItem.Icon = global::Dispatcher.Properties.Resources.openEnvelope;
gridItem.Status = (int)TextStatus.UNREAD_OUT;
}
SMSGridView.SelectedRows[0].Cells["Icon"].Value = global::Dispatcher.Properties.Resources.openEnvelope;
SMSGridView.SelectedRows[0].Cells["Status"].Value = (int)TextStatus.UNREAD_OUT;
// notify that messages has changed
parent.UpdateUnreadMessagesNumber();
// update the tree node value
// TODO
}
catch (Exception ex)
{
SM.Debug("Error UpdateSMS:" + ex.ToString());
}
//only in read case made refresh
}
}
}
}
private void SMSGridView_CellFormatting(object sender, CellFormattingEventArgs e)
{
GridCellElement cellElement = e.CellElement;
GridViewDataColumn columnInfo = e.CellElement.ColumnInfo as GridViewDataColumn;
if (cellElement == null || columnInfo == null)
return;
// do not draw border
cellElement.DrawBorder = false;
// do not highlight the cell on which was clicked
if (e.CellElement.IsCurrent)
{
e.CellElement.IsCurrent = false;
}
if (e.CellElement.ColumnInfo.Name == "number" && string.IsNullOrEmpty(e.CellElement.Text))
{
e.CellElement.Text = (e.CellElement.RowIndex + 1).ToString();
cellElement.DrawText = true;
Font font3 = new Font(
cellElement.Font.FontFamily,
9,
FontStyle.Regular,
GraphicsUnit.Pixel);
cellElement.ForeColor = Color.FromArgb(0x66, 0x66, 0x66);
cellElement.Font = font3;
cellElement.Padding = new Padding(1, 1, 3, 1);
}
try
{
if (!trashSelec)
{
if (e.Row.DataBoundItem as SMSDataforGRID != null)
{
SMSDataforGRID gridItem = e.Row.DataBoundItem as SMSDataforGRID;
//if ((e.CellElement.RowIndex >= 0) && (SMSGridView.Rows[e.CellElement.RowIndex].Cells["Status"].Value != DBNull.Value))
if (gridItem.Status == 0)
{
//if (Convert.ToInt32(SMSGridView.Rows[e.CellElement.RowIndex].Cells["Status"].Value) == (int)TextStatus.SD_NO_GW)
e.CellElement.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
}
else
{
e.CellElement.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
}
}
if(cellElement is GridImageCellElement && (columnInfo.Name == "Icon"))
{
SMSDataforGRID gridItem = e.Row.DataBoundItem as SMSDataforGRID;
if (gridItem.Status == 0)
{
e.CellElement.Image = global::Dispatcher.Properties.Resources.closedEnvelope;
}
else
{
e.CellElement.Image = global::Dispatcher.Properties.Resources.openEnvelope;
}
}
}
if (cellElement is GridDataCellElement && (columnInfo.Name == "timeAgo" || columnInfo.Name == "Date"))
{
Font font = new Font(
cellElement.Font.FontFamily,
10,
FontStyle.Bold,
GraphicsUnit.Pixel);
cellElement.ForeColor = Color.FromArgb(0x66,0x66,0x66);
cellElement.Font = font;
}
else if (cellElement is GridDataCellElement && columnInfo.Name == "Color")
{
cellElement.DrawText = false;
GridColorCellElement colorCellElement = e.CellElement as GridColorCellElement;
colorCellElement.Text = string.Empty;
int colorBoxWidth = 20;
int leftMargin = (this.SMSGridView.Columns["Color"].Width - colorBoxWidth) / 2;
colorCellElement.ColorBox.Margin = new Padding(leftMargin, 10, 2, 10);
}
}
catch (Exception ex)
{
SM.Debug("Ex:" + ex.ToString());
}
}
/// <summary>
/// Create the context menu which will be displayed when a cell is right clicked
/// This will select the options for each selection
/// </summary>
private void SMSGridView_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e)
{
GridDataCellElement cell = e.ContextMenuProvider as GridDataCellElement;
if (cell == null)
{
return;
}
if (e.ContextMenuProvider is GridDataCellElement)
{
GridViewRowInfo row = ((GridDataCellElement)e.ContextMenuProvider).RowInfo;
// get the database index of the current sms
Int16 idx = 0;
Int16.TryParse(row.Cells["idx"].Value.ToString(), out idx);
// create the drop down menu
RadDropDownMenu menu = new RadDropDownMenu();
if(cell.ColumnIndex == SMSGridView.Columns["Color"].Index)
{
#region COLOR ITEMS
// create context menu button
RadMenuItem itemNone = new RadMenuItem(MainForm2.returnLNGString("categoryNo"));
// add click listener for the context menu button
itemNone.Click += delegate(object s, EventArgs ev)
{
// set the purple color
GridColorCellElement colorCellElement = cell as GridColorCellElement;
colorCellElement.Value = Color.White;
// update color in the DB
if(idx != 0)
smdbObj.ChangeSMSColor(idx, Color.White);
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
};
itemNone.Image = global::Dispatcher.Properties.Resources.s_categ_none;
itemNone.ImageAlignment = ContentAlignment.MiddleLeft;
// add button to context menu
menu.Items.Add(itemNone);
// create context menu button
RadMenuItem itemRed = new RadMenuItem(MainForm2.returnLNGString("categoryRed"));
// add click listener for the context menu button
itemRed.Click += delegate(object s, EventArgs ev)
{
// set the purple color
GridColorCellElement colorCellElement = cell as GridColorCellElement;
colorCellElement.Value = Color.FromArgb(167, 29, 35);
// update color in the DB
if (idx != 0)
smdbObj.ChangeSMSColor(idx, Color.FromArgb(167, 29, 35));
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
};
itemRed.Image = global::Dispatcher.Properties.Resources.s_categ_red;
itemRed.ImageAlignment = ContentAlignment.MiddleLeft;
// add button to context menu
menu.Items.Add(itemRed);
// create context menu button
RadMenuItem itemGreen = new RadMenuItem(MainForm2.returnLNGString("categoryGreen"));
// add click listener for the context menu button
itemGreen.Click += delegate(object s, EventArgs ev)
{
// set the purple color
GridColorCellElement colorCellElement = cell as GridColorCellElement;
colorCellElement.Value = Color.FromArgb(55, 126, 45);
// update color in the DB
if (idx != 0)
smdbObj.ChangeSMSColor(idx, Color.FromArgb(55, 126, 45));
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
};
itemGreen.Image = global::Dispatcher.Properties.Resources.s_categ_green;
itemGreen.ImageAlignment = ContentAlignment.MiddleLeft;
// add button to context menu
menu.Items.Add(itemGreen);
// create context menu button
RadMenuItem itemBlue = new RadMenuItem(MainForm2.returnLNGString("categoryBlue"));
// add click listener for the context menu button
itemBlue.Click += delegate(object s, EventArgs ev)
{
// set the purple color
GridColorCellElement colorCellElement = cell as GridColorCellElement;
colorCellElement.Value = Color.FromArgb(40, 81, 142);
// update color in the DB
if (idx != 0)
smdbObj.ChangeSMSColor(idx, Color.FromArgb(40, 81, 142));
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
};
itemBlue.Image = global::Dispatcher.Properties.Resources.s_categ_blue;
itemBlue.ImageAlignment = ContentAlignment.MiddleLeft;
// add button to context menu
menu.Items.Add(itemBlue);
// create context menu button
RadMenuItem itemYellow = new RadMenuItem(MainForm2.returnLNGString("categoryYellow"));
// add click listener for the context menu button
itemYellow.Click += delegate(object s, EventArgs ev)
{
// set the purple color
GridColorCellElement colorCellElement = cell as GridColorCellElement;
colorCellElement.Value = Color.FromArgb(255, 249, 104);
// update color in the DB
if (idx != 0)
smdbObj.ChangeSMSColor(idx, Color.FromArgb(255, 249, 104));
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
};
itemYellow.Image = global::Dispatcher.Properties.Resources.s_categ_yellow;
itemYellow.ImageAlignment = ContentAlignment.MiddleLeft;
// add button to context menu
menu.Items.Add(itemYellow);
// create context menu button
RadMenuItem itemOrange = new RadMenuItem(MainForm2.returnLNGString("categoryOrange"));
// add click listener for the context menu button
itemOrange.Click += delegate(object s, EventArgs ev)
{
// set the purple color
GridColorCellElement colorCellElement = cell as GridColorCellElement;
colorCellElement.Value = Color.FromArgb(173, 77, 13);
// update color in the DB
if (idx != 0)
smdbObj.ChangeSMSColor(idx, Color.FromArgb(173, 77, 13));
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
};
itemOrange.Image = global::Dispatcher.Properties.Resources.s_categ_orange;
itemOrange.ImageAlignment = ContentAlignment.MiddleLeft;
// add button to context menu
menu.Items.Add(itemOrange);
// create context menu button
RadMenuItem itemPurple = new RadMenuItem(MainForm2.returnLNGString("categoryPurple"));
// add click listener for the context menu button
itemPurple.Click += delegate(object s, EventArgs ev)
{
// set the purple color
GridColorCellElement colorCellElement = cell as GridColorCellElement;
colorCellElement.Value = Color.FromArgb(77, 49, 141);
// update color in the DB
if (idx != 0)
smdbObj.ChangeSMSColor(idx, Color.FromArgb(77, 49, 141));
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
};
itemPurple.Image = global::Dispatcher.Properties.Resources.s_categ_purple;
itemPurple.ImageAlignment = ContentAlignment.MiddleLeft;
// add button to context menu
menu.Items.Add(itemPurple);
#endregion
}
else
{
// detect if many messages are selected or not
bool multiMessagesSelected = SMSGridView.SelectedRows.Count > 1;
#region DELETE MENU ITEM
// create context menu button
RadMenuItem itemDelete = new RadMenuItem(multiMessagesSelected ? MainForm2.returnLNGString("delmsgs") : MainForm2.returnLNGString("delmsg"));
// add click listener for the context menu button
itemDelete.Click += delegate(object s, EventArgs ev)
{
DialogResult dr2 = DialogResult.Yes;
if (rcbDeleteConfirmation.Checked)
{
dr2 = RadMessageBox.Show(MainForm2.returnLNGString("delselected") +" " +
(multiMessagesSelected ? MainForm2.returnLNGString("mss") : MainForm2.returnLNGString("ms")) +"?",
itemDelete.Text, MessageBoxButtons.YesNo, RadMessageIcon.Info);
}
// only if yes was pressed
if (dr2 == DialogResult.Yes)
{
if (slectedSMSidx != null && slectedSMSidx.Length > 0)
{
GridViewSelectedRowsCollection selectedRows = SMSGridView.SelectedRows;
foreach (GridViewDataRowInfo roww in SMSGridView.SelectedRows.ToList())
{
if (!trashSelec)
{
smdbObj.Delete_SMS(Int16.Parse(roww.Cells["Idx"].Value.ToString()));
}
else
{
smdbObj.Delete_SMS_from_trash(new int[] { Int16.Parse(roww.Cells["Idx"].Value.ToString()) });
}
// remove item from the grid
SMSGridView.Rows.Remove(roww);
}
}
}
//update number of message for current node
updateInboxAndOutboxView(true);
// notify that messages has changed
parent.UpdateUnreadMessagesNumber();
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
};
//itemDelete.Image = global::Dispatcher.Properties.Resources.s_categ_none;
itemDelete.ImageAlignment = ContentAlignment.MiddleLeft;
#endregion
#region COPY TEXT MENU ITEM
// create context menu button
RadMenuItem itemCopy = new RadMenuItem(MainForm2.returnLNGString("copyMsg"));
// add click listener for the context menu button
itemCopy.Click += delegate(object s, EventArgs ev)
{
Clipboard.SetText(row.Cells["Message"].Value.ToString());
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
};
//itemCopy.Image = global::Dispatcher.Properties.Resources.s_categ_none;
itemCopy.ImageAlignment = ContentAlignment.MiddleLeft;
#endregion
#region WRITE TEXT MENU ITEM
// create context menu button
RadMenuItem itemWrite = new RadMenuItem(MainForm2.returnLNGString("writeNewMsg"));
// add click listener for the context menu button
itemWrite.Click += delegate(object s, EventArgs ev)
{
// write new sms
//nsf = new NewSmsForm(this, SMSmode.New4Unit, MainForm2.VehIDHash, MainForm2.vehicleHT, row.Cells["Source"].Value.ToString(), "", smdbObj);
nsf = new NewSmsForm(this, SMSmode.New4Unit, MainForm2.VehIDHash, MainForm2.vehicleHT, row.Cells["Source"].Value.ToString(), "", smdbObj);
nsf.FormClosed += new FormClosedEventHandler(nsf_FormClosed);
nsf.Show();
nsf.BringToFront();
if (nsf.WindowState == FormWindowState.Minimized)
nsf.WindowState = FormWindowState.Normal;
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
};
//itemCopy.Image = global::Dispatcher.Properties.Resources.s_categ_none;
itemWrite.ImageAlignment = ContentAlignment.MiddleLeft;
#endregion
#region FORWARD TEXT MENU ITEM
// create context menu button
RadMenuItem itemForward = new RadMenuItem(MainForm2.returnLNGString("FWmsg"));
// add click listener for the context menu button
itemForward.Click += delegate(object s, EventArgs ev)
{
// forward the sms
btn_forwardSMS_Click(s, ev);
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
};
//itemCopy.Image = global::Dispatcher.Properties.Resources.s_categ_none;
itemForward.ImageAlignment = ContentAlignment.MiddleLeft;
#endregion
#region REPLY TEXT MENU ITEM
// create context menu button
RadMenuItem itemReply = new RadMenuItem(MainForm2.returnLNGString("replyMsg"));
// add click listener for the context menu button
itemReply.Click += delegate(object s, EventArgs ev)
{
// reply the sms
nsf = new NewSmsForm(this, SMSmode.Reply, MainForm2.VehIDHash, MainForm2.vehicleHT, row.Cells["Source"].Value.ToString(), "", smdbObj);
nsf.FormClosed += new FormClosedEventHandler(nsf_FormClosed);
nsf.Show();
nsf.BringToFront();
if (nsf.WindowState == FormWindowState.Minimized)
nsf.WindowState = FormWindowState.Normal;
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
};
//itemCopy.Image = global::Dispatcher.Properties.Resources.s_categ_none;
itemReply.ImageAlignment = ContentAlignment.MiddleLeft;
#endregion
#region RESTORE TEXT MENU ITEM
// create context menu button
RadMenuItem itemRestore = new RadMenuItem(MainForm2.returnLNGString("restoreMsg"));
// add click listener for the context menu button
itemRestore.Click += delegate(object s, EventArgs ev)
{
smdbObj.UnDelete_SMS(Convert.ToInt32(row.Cells["Idx"].Value));
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
updateDataGrid(selectedSC_IDlist, inboxSelec, true, false, false);
};
//itemCopy.Image = global::Dispatcher.Properties.Resources.s_categ_none;
itemRestore.ImageAlignment = ContentAlignment.MiddleLeft;
#endregion
#region MARK UNREAD MENU ITEM
bool isReadAtLeastOne = false;
foreach (GridViewRowInfo r in SMSGridView.SelectedRows)
{
if (Convert.ToInt32(r.Cells["Status"].Value.ToString()) == (int)TextStatus.UNREAD_OUT)
isReadAtLeastOne = true;
}
// create context menu button
RadMenuItem itemMarkUnread = new RadMenuItem(multiMessagesSelected ?
MainForm2.returnLNGString("markSelMsgsAsUnread") : MainForm2.returnLNGString("markSelMsgAsUnread"));
// add click listener for the context menu button
itemMarkUnread.Click += delegate(object s, EventArgs ev)
{
foreach (GridViewRowInfo r in SMSGridView.SelectedRows)
{
smdbObj.Update_SMS(
(GetTreeLevel() == TreeLevel.INBOX ? (int)TextStatus.UNREAD_IN : (int)TextStatus.UNREAD_OUT),
Convert.ToInt32(r.Cells["Idx"].Value));
SMSDataforGRID gridItem = r.DataBoundItem as SMSDataforGRID;
if (gridItem != null)
{
gridItem.Icon = global::Dispatcher.Properties.Resources.closedEnvelope;
gridItem.Status = 0;
}
r.Cells["Icon"].Value = global::Dispatcher.Properties.Resources.closedEnvelope;
r.Cells["Status"].Value = 0;
}
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
//update number of message for current node
updateInboxAndOutboxView(true);
// notify that messages has changed
parent.UpdateUnreadMessagesNumber();
};
itemMarkUnread.Image = global::Dispatcher.Properties.Resources.closedEnvelope;
itemMarkUnread.ImageAlignment = ContentAlignment.MiddleLeft;
#endregion
#region MARK ALL UNREAD MENU ITEM
// create context menu button
RadMenuItem itemMarkAllUnread = new RadMenuItem("Mark all as unread");
// add click listener for the context menu button
itemMarkAllUnread.Click += delegate(object s, EventArgs ev)
{
DialogResult dr2 = RadMessageBox.Show("Are you sure you want to mark all messages" +
" as unread?", "Mark all as unread", MessageBoxButtons.YesNo, RadMessageIcon.Info);
// only if yes was pressed
if (dr2 == DialogResult.Yes)
{
foreach (GridViewRowInfo r in SMSGridView.Rows)
{
//mark sms as unread (status 3) for inbox
smdbObj.Update_SMS(3, Convert.ToInt32(r.Cells["Idx"].Value));
SMSDataforGRID gridItem = r.DataBoundItem as SMSDataforGRID;
if (gridItem != null)
{
gridItem.Icon = global::Dispatcher.Properties.Resources.closedEnvelope;
gridItem.Status = 0;
}
r.Cells["Icon"].Value = global::Dispatcher.Properties.Resources.closedEnvelope;
r.Cells["Status"].Value = 0;
}
}
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
//update number of message for current node
updateInboxAndOutboxView(true);
// notify that messages has changed
parent.UpdateUnreadMessagesNumber();
};
itemMarkAllUnread.Image = global::Dispatcher.Properties.Resources.closedEnvelope;
itemMarkAllUnread.ImageAlignment = ContentAlignment.MiddleLeft;
#endregion
#region MARK READ MENU ITEM
bool isUnReadAtLeastOne = false;
foreach (GridViewRowInfo r in SMSGridView.SelectedRows)
{
if (Convert.ToInt32(r.Cells["Status"].Value.ToString()) == (int)TextStatus.SD_NO_GW)
isUnReadAtLeastOne = true;
}
// create context menu button
RadMenuItem itemMarkRead = new RadMenuItem(multiMessagesSelected ?
MainForm2.returnLNGString("markMsgsAsRead") : MainForm2.returnLNGString("markMsgAsRead"));
// add click listener for the context menu button
itemMarkRead.Click += delegate(object s, EventArgs ev)
{
foreach (GridViewRowInfo r in SMSGridView.SelectedRows)
{
smdbObj.Update_SMS(
(GetTreeLevel() == TreeLevel.INBOX ? (int)TextStatus.READ_IN : (int)TextStatus.READ_OUT),
Convert.ToInt32(r.Cells["Idx"].Value));
SMSDataforGRID gridItem = r.DataBoundItem as SMSDataforGRID;
if (gridItem != null)
{
gridItem.Icon = global::Dispatcher.Properties.Resources.openEnvelope;
gridItem.Status = 1;
}
r.Cells["Icon"].Value = global::Dispatcher.Properties.Resources.openEnvelope;
r.Cells["Status"].Value = 1;
}
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
//update number of message for current node
updateInboxAndOutboxView(true);
// notify that messages has changed
parent.UpdateUnreadMessagesNumber();
};
itemMarkRead.Image = global::Dispatcher.Properties.Resources.openEnvelope;
itemMarkRead.ImageAlignment = ContentAlignment.MiddleLeft;
#endregion
#region MARK ALL READ MENU ITEM
// create context menu button
RadMenuItem itemMarkAllRead = new RadMenuItem("Mark all as read");
// add click listener for the context menu button
itemMarkAllRead.Click += delegate(object s, EventArgs ev)
{
DialogResult dr2 = RadMessageBox.Show("Are you sure you want to mark all messages" +
" as read?", "Mark all as read", MessageBoxButtons.YesNo, RadMessageIcon.Info);
// only if yes was pressed
if (dr2 == DialogResult.Yes)
{
foreach (GridViewRowInfo r in SMSGridView.Rows)
{
//mark sms as unread (status 3) for inbox
smdbObj.Update_SMS(1, Convert.ToInt32(r.Cells["Idx"].Value));
SMSDataforGRID gridItem = r.DataBoundItem as SMSDataforGRID;
if (gridItem != null)
{
gridItem.Icon = global::Dispatcher.Properties.Resources.openEnvelope;
gridItem.Status = 1;
}
r.Cells["Icon"].Value = global::Dispatcher.Properties.Resources.openEnvelope;
r.Cells["Status"].Value = 1;
}
}
// close the menu
menu.ClosePopup(RadPopupCloseReason.Mouse);
//update number of message for current node
updateInboxAndOutboxView(true);
// notify that messages has changed
parent.UpdateUnreadMessagesNumber();
};
itemMarkAllRead.Image = global::Dispatcher.Properties.Resources.openEnvelope;
itemMarkAllRead.ImageAlignment = ContentAlignment.MiddleLeft;
#endregion
// display the context menu based on the level of the tree where is selected
switch(GetTreeLevel())
{
case TreeLevel.INBOX:
{
// add mark as unread option if needed
if (isReadAtLeastOne)
menu.Items.Add(itemMarkUnread);
if(isUnReadAtLeastOne)
menu.Items.Add(itemMarkRead);
menu.Items.Add(new RadMenuSeparatorItem());
//menu.Items.Add(itemMarkAllUnread);
//menu.Items.Add(itemMarkAllRead);
//menu.Items.Add(new RadMenuSeparatorItem());
menu.Items.Add(itemWrite);
menu.Items.Add(itemForward);
menu.Items.Add(itemReply);
menu.Items.Add(new RadMenuSeparatorItem());
// add delete button to context menu
menu.Items.Add(itemDelete);
if (!multiMessagesSelected)
menu.Items.Add(itemCopy);
break;
}
case TreeLevel.OUTBOX:
{
// add mark as unread option if needed
if (isReadAtLeastOne)
menu.Items.Add(itemMarkUnread);
if (isUnReadAtLeastOne)
menu.Items.Add(itemMarkRead);
menu.Items.Add(new RadMenuSeparatorItem());
//menu.Items.Add(itemMarkAllUnread);
//menu.Items.Add(itemMarkAllRead);
//menu.Items.Add(new RadMenuSeparatorItem());
menu.Items.Add(itemWrite);
menu.Items.Add(itemForward);
menu.Items.Add(new RadMenuSeparatorItem());
// add delete button to context menu
menu.Items.Add(itemDelete);
if (!multiMessagesSelected)
menu.Items.Add(itemCopy);
break;
}
case TreeLevel.TRASH:
{
menu.Items.Add(itemRestore);
menu.Items.Add(new RadMenuSeparatorItem());
// add delete button to context menu
menu.Items.Add(itemDelete);
break;
}
case TreeLevel.UNKNOWN:
{
break;
}
}
}
// add the menu to the cell context menu
e.ContextMenu = menu;
}
}
private enum TreeLevel { INBOX, OUTBOX, TRASH, UNKNOWN };
/// <summary>
/// Get level at which the SMS Tree View is selected (placed)
/// </summary>
/// <returns>An enum value representing the Tree Level</returns>
private TreeLevel GetTreeLevel()
{
try
{
// detect if inbox, outbox or trash is selected
if (SMSTreeView.SelectedNode.Level == 0)
{
// The Group is selected
if (SMSTreeView.SelectedNode.Name.ToLower().Equals("inbox"))
return TreeLevel.INBOX;
else if (SMSTreeView.SelectedNode.Name.ToLower().Equals("outbox"))
return TreeLevel.OUTBOX;
else
return TreeLevel.TRASH;
}
else if (SMSTreeView.SelectedNode.Level == 1)
{
// a group is selected
if (SMSTreeView.SelectedNode.Parent.Name.ToLower().Equals("inbox"))
return TreeLevel.INBOX;
else if (SMSTreeView.SelectedNode.Parent.Name.ToLower().Equals("outbox"))
return TreeLevel.OUTBOX;
else
return TreeLevel.TRASH;
}
else if (SMSTreeView.SelectedNode.Level == 2)
{
// a unit is selected
if (SMSTreeView.SelectedNode.Parent.Parent.Name.ToLower().Equals("inbox"))
return TreeLevel.INBOX;
else if (SMSTreeView.SelectedNode.Parent.Parent.Name.ToLower().Equals("outbox"))
return TreeLevel.OUTBOX;
else
return TreeLevel.TRASH;
}
}
catch (Exception ex)
{
Utils.WriteLine(ex.ToString(), ConsoleColor.Red);
}
return TreeLevel.UNKNOWN;
}
private int selectedIndex = 0;
private void RefreshALL(Boolean withoutTreeRefresh)
{
// save previous selected row
if (SMSGridView.SelectedRows.Count > 0)
selectedIndex = SMSGridView.SelectedRows[0].Index;
if (!trashSelec)
{
if (selectedSC_IDlist != null)
{
if (selectedSC_IDlist.Length > 0)
{
updateDataGrid(selectedSC_IDlist, inboxSelec, false,false,false);
}
}
else
{
SM.Debug("Error in refresh ...selectedSC_IDlist is NULL");
}
}
else
{
updateDataGrid(selectedSC_IDlist, false, true,false,false);
}
if (!withoutTreeRefresh)
updateInboxAndOutboxView(true);
if(SMSGridView.Rows.Count > selectedIndex)
{
SMSGridView.Rows[selectedIndex].IsSelected = true;
}
}
#endregion
#region SMS buttons events
private NewSmsForm nsf = null;
private void btn_write_Click(object sender, EventArgs e)
{
try
{
//open write sms form
nsf = new NewSmsForm(this,SMSmode.New, MainForm2.VehIDHash, MainForm2.vehicleHT, "", "", smdbObj);
nsf.FormClosed += new FormClosedEventHandler(nsf_FormClosed);
nsf.Show();
nsf.BringToFront();
if (nsf.WindowState == FormWindowState.Minimized)
nsf.WindowState = FormWindowState.Normal;
}
catch (Exception ex)
{
SM.Debug("Cann't show new SMS form" + ex.ToString());
}
}
void nsf_FormClosed(object sender, FormClosedEventArgs e)
{
// skip if the form was closed with X or other way
if (nsf != null && nsf.DialogResult != DialogResult.OK)
return;
System.Threading.Thread.Sleep(200);
// force to take again all the messages
oldSelected = "";
SMSTreeView_Click(rtbQuickText, null);
/*
updateDataGrid(selectedSC_IDlist, inboxSelec, false,false,false);
//webBrowser1.DocumentText = "";
if (SMSGridView.RowCount > 0)
{
SelectSMSandDisplay(false);
}*/
nsf = null;
}
private void btn_forwardSMS_Click(object sender, EventArgs e)
{
try
{
if (SMSGridView.SelectedRows.Count > 0)
{
//opne new form
String text = (String)SMSGridView.SelectedRows[0].Cells["Message"].Value;
nsf = new NewSmsForm(this, SMSmode.Forward, MainForm2.VehIDHash, MainForm2.vehicleHT, "", text, smdbObj);
nsf.FormClosed += new FormClosedEventHandler(nsf_FormClosed);
nsf.Show();
nsf.BringToFront();
if (nsf.WindowState == FormWindowState.Minimized)
nsf.WindowState = FormWindowState.Normal;
}
}
catch (Exception ex)
{
SM.Debug("Cann't show new SMS form" + ex.Message);
}
}
private void btn_deleteSMS_Click_1(object sender, EventArgs e)
{
if (slectedSMSidx != null && slectedSMSidx.Length > 0)
{
for (int i = 0; i < slectedSMSidx.Length; i++)
{
SM.Debug("Deleting SMS with index :" + slectedSMSidx[i]);
try
{
if (!trashSelec)
{
smdbObj.Delete_SMS(slectedSMSidx[i]);
}
else
{
smdbObj.Delete_SMS_from_trash(new int[] {slectedSMSidx[i]});
}
}
catch (Exception ex)
{ SM.Debug("Delete SMS"+ex.ToString()); }
}
if (selectedSC_IDlist != null)
{
if (selectedSC_IDlist.Length > 0)
{
updateDataGrid(selectedSC_IDlist, inboxSelec, false,false,false);
SelectSMSandDisplay(false);
}
}
RefreshALL(true);
}
}
#endregion
#region aux functions
private ArrayList sc_id4SMS;
private ArrayList getAllsc_idFromSelection()
{
ArrayList v_sc_idList = new ArrayList();
foreach (RadTreeNode node in SMSTreeView.SelectedNodes)
{
int[] scidArray = getChildSC_ID(node);
for (int i = 0; i < scidArray.Length; i++)
{
if (!v_sc_idList.Contains(scidArray[i]))
{
v_sc_idList.Add(scidArray[i]);
}
}
}
return v_sc_idList;
}
#endregion
#region send&predefine buttons events
public void SendSMS(string text, int sc_id, int sched_timegmt)
{
parent.SendSmsOnMBus(text, sc_id, sched_timegmt);
}
public void SendSMSGroupMotorola(string text, int cps_id, int sched_timegmt, Int32 sc_id_for_test)
{
try
{
if ((MainForm2.VehIDHash[sc_id_for_test] != null) && (MainForm2.vehicleHT[MainForm2.VehIDHash[sc_id_for_test].ToString()] != null))
{
((Vehicle)MainForm2.vehicleHT[MainForm2.VehIDHash[sc_id_for_test].ToString()]).CheckPositionInSystem();
String Totrans = "#142#" + ((Vehicle)MainForm2.vehicleHT[MainForm2.VehIDHash[sc_id_for_test].ToString()]).GwandRadioID + "." + cps_id + "#" + text + "#" + sched_timegmt + "#";
parent.Send_UDP_cmd(Totrans, 0, 0);
((Vehicle)MainForm2.vehicleHT[MainForm2.VehIDHash[sc_id_for_test].ToString()]).EventLists.Add(new Alarms(rep_type.SMSSEND, DateTime.Now, "", text));
parent.DisplayToast(MainForm2.returnLNGString("txtMsgToGrp") + cps_id, "<html>" + MainForm2.returnLNGString("grpmsj") + " " + "<i>" + text + "</i>" + " " + MainForm2.returnLNGString("wasSentToGW") + "</html>");
}
}
catch (Exception ex)
{
SM.Debug("Send SMS error on hash:" + ex.ToString());
}
}
public void SendSMSGroup(string text, int cps_id, int sched_timegmt)
{
try
{
parent.SendSMSGroup(text, cps_id, sched_timegmt, SMSTreeView.SelectedNode.Text);
}
catch (Exception ex)
{
SM.Debug("Send SMS Group error:" + ex.ToString());
}
}
#endregion
private void radMenuWriteSMS_Click(object sender, EventArgs e)
{
SMSmode mode = SMSmode.Reply;
if (selectedTreeNode != null)
{
if (selectedTreeNode.Name != "")
{
mode = SMSmode.Reply;
}
}
else
{
mode = SMSmode.New4Unit;
}
// skip case when no tree view item is selected
if (SMSTreeView.SelectedNode == null)
return;
// write new sms
nsf = new NewSmsForm(this, mode, MainForm2.VehIDHash, MainForm2.vehicleHT,
SMSTreeView.SelectedNode.Name, "", smdbObj);
nsf.FormClosed += new FormClosedEventHandler(nsf_FormClosed);
nsf.Show();
nsf.BringToFront();
if (nsf.WindowState == FormWindowState.Minimized)
nsf.WindowState = FormWindowState.Normal;
}
private void btn_NextPage_Click(object sender, EventArgs e)
{
PageforInbox++;
int[] tmp = null;
updateDataGrid(tmp, Type_Inbox_for_limit2000, false, true,false);
}
private void btn_PrevPage_Click(object sender, EventArgs e)
{
PageforInbox--;
int[] tmp = null;
updateDataGrid(tmp, Type_Inbox_for_limit2000, false, true,false);
}
private Boolean cusaufara = true;
private void button1_Click(object sender, EventArgs e)
{
//private RadTreeNode selectedTreeNode = null;
RadTreeNode selNode = SMSTreeView.SelectedNode;
selNode.Collapse();
if (cusaufara)
{
selNode.Text += "(" + "20" + ")";
selNode.Font = new System.Drawing.Font("Tahoma", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
cusaufara = false;
}
else
{
selNode.Font = new System.Drawing.Font("Tahoma", 9F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Regular))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
cusaufara = true;
}
selNode.Expand();
}
/// <summary>
/// Filter the text message grid when search text box changes its text
/// </summary>
private FilterDescriptor prevValueFilter = null;
private void tbSearch_TextChanged(object sender, EventArgs e)
{
if (tbSearch.Text.Length == 0)
{
pbSearch.Image = Dispatcher.Properties.Resources.s_search;
pbSearch.Cursor = Cursors.Default;
}
else
{
pbSearch.Image = Dispatcher.Properties.Resources.s_delete;
pbSearch.Cursor = Cursors.Hand;
}
FilterDescriptor valueFilter = new FilterDescriptor("Message", FilterOperator.Contains, tbSearch.Text);
//while (SMSGridView.FilterDescriptors.Count > 0)
// SMSGridView.FilterDescriptors.RemoveAt(0);
// remove previous filter if exists
if (prevValueFilter != null)
SMSGridView.FilterDescriptors.Remove(prevValueFilter);
SMSGridView.FilterDescriptors.Add(valueFilter);
// save filter for the next one
prevValueFilter = valueFilter;
}
/// <summary>
/// Reset the search text box text
/// </summary>
private void pbSearch_Click(object sender, EventArgs e)
{
if(tbSearch.Text.Length > 0)
tbSearch.Text = "";
}
#region PICTURE BOX MAP PIN
/// <summary>
/// Enable or disable the clicks on keys and then changes in grid view
/// </summary>
private void pbKeys_Click(object sender, EventArgs e)
{
PictureBox s = (PictureBox)sender;
if (s.Tag.Equals("selected"))
{
s.Tag = "unselected";
if(s == pbR)
s.Image = MainForm2.imagesDictionary["s_key_r_d"];
else if (s == pbU)
s.Image = MainForm2.imagesDictionary["s_key_u_d"];
else if (s == pbDelete)
s.Image = MainForm2.imagesDictionary["s_key_del_d"];
}
else
{
s.Tag = "selected";
if (s == pbR)
s.Image = MainForm2.imagesDictionary["s_key_r"];
else if (s == pbU)
s.Image = MainForm2.imagesDictionary["s_key_u"];
else if (s == pbDelete)
s.Image = MainForm2.imagesDictionary["s_key_del"];
}
}
/// <summary>
/// Display the Tooltip when the mouse is over the picture box
/// </summary>
private void pbKeys_MouseEnter(object sender, EventArgs e)
{
PictureBox s = (PictureBox)sender;
toolTipHelp.ToolTipTitle = "Current state: " + (((PictureBox)sender).Tag.Equals("selected") ? "Active" : "Inactive");
toolTipHelp.Show(
String.Format("When active, the stroke on "
+ Environment.NewLine
+ (s == pbR ? "R key will mark as read the message" :
(s == pbU ? "U key will mark as unread the message" : "Del key will delete the message")))
,(PictureBox)sender, 50000);
}
/// <summary>
/// Hide the tooltip when the mouse leaves the picture box
/// </summary>
private void pbKeys_MouseLeave(object sender, EventArgs e)
{
toolTipHelp.Hide((PictureBox)sender);
}
#endregion
/// <summary>
/// Quick way to send a text message to a desired unit
/// </summary>
private void rbtSendQuick_Click(object sender, EventArgs e)
{
// skip case when no tree view item is selected
if (SMSTreeView.SelectedNode == null && SMSTreeView.SelectedNode.Tag != null)
return;
Int16 scID = 0;
Int16.TryParse(SMSTreeView.SelectedNode.Tag.ToString(), out scID);
if (scID > 0 && SMSTreeView.SelectedNode.Nodes.Count == 0)
{
SendSMS(rtbQuickText.Text, scID, (int)DateTime.Now.ToUniversalTime().DateTo70Format());
}
else
{
SendSMSGroup(rtbQuickText.Text, scID, (int)DateTime.Now.ToUniversalTime().DateTo70Format());
}
rtbQuickText.ResetText();
//rtbQuickText.Text = "";
rtbQuickText.Focus();
rbtSendQuick.Enabled = false;
SMSTreeView_Click(rbtSendQuick, null);
}
/// <summary>
/// Send text message when enter key was pressed
/// </summary>
private void rtbQuickText_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter && rtbQuickText.Text != "")
rbtSendQuick.PerformClick();
}
/// <summary>
/// Change background color of the button when it becomes enable or disabled
/// </summary>
private void rbtSendQuick_EnabledChanged(object sender, EventArgs e)
{
if (rbtSendQuick.Enabled)
rbtSendQuick.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
else
rbtSendQuick.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColorDisabled;
}
private void SMSuserControl_Load(object sender, EventArgs e)
{
// disable the Send Quick message button
rbtSendQuick.Enabled = false;
isSMSLoaded = true;
VisualSettings.loadUserVisualSettings(this.Name, this.documentWindow2, MainForm2.HashVal);
updateInboxAndOutboxView(true);
Color focusColor = Color.Black;
MainForm2.RestartMEM += 30000000;
}
/// <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>
/// Catches the event when
/// the user inputs/deletes a character in/from the search box,
/// and the vehicles list is refreshed accordingly </summary>
/// </summary>
private void searchTextBox_TextChanged(object sender, EventArgs e)
{
SMSTreeView.Filter = null;
SMSTreeView.Filter = searchTextBox.Text;
}
/// <summary>
/// Change background color for the row according to its state and theme
/// </summary>
private void SMSGridView_RowFormatting(object sender, RowFormattingEventArgs e)
{
e.RowElement.DrawFill = true;
e.RowElement.NumberOfColors = 1;
if (e.RowElement.IsSelected)
e.RowElement.BackColor = MainForm2.GridSelectedRow;
else
e.RowElement.BackColor = (e.RowElement.RowInfo.Index % 2 == 0 ? Color.White : MainForm2.GridAlternateRow);
SMSDataforGRID sms = e.RowElement.Data.DataBoundItem as SMSDataforGRID;
if (sms != null && sms.DateTime.CompareTo(DateTime.UtcNow) > 0 && !e.RowElement.IsSelected)
{
e.RowElement.BackColor = Color.FromArgb(225,255,210);
}
if (sms != null && sms.Status == 0)
{
e.RowElement.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//e.RowElement.VisualCells[2].Image = global::Dispatcher.Properties.Resources.closedEnvelope;
}
else
{
e.RowElement.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
//e.RowElement.VisualCells[2].Image = global::Dispatcher.Properties.Resources.openEnvelope;
}
}
/// <summary>
/// Change background color for the row according to its state and theme
/// </summary>
private void SMSTreeView_NodeFormatting(object sender, TreeNodeFormattingEventArgs e)
{
if (e.NodeElement.IsSelected)
{
e.NodeElement.DrawFill = true;
e.NodeElement.BackColor = MainForm2.GridSelectedRow;
e.NodeElement.NumberOfColors = 1;
}
else
e.NodeElement.DrawFill = false;
}
#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
private void rcbDeleteConfirmation_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
VisualSettings.InsertUpdateHTforVisualItems(this.Name, ((RadCheckBox)sender).Name, ((RadCheckBox)sender).Checked.ToString());
}
private void SMSGridView_CustomSorting(object sender, GridViewCustomSortingEventArgs e)
{
int descriptorIndex = -1;
// search the Date column and get it's descriptor Index
for (int i = 0; i < this.SMSGridView.SortDescriptors.Count; i++)
{
if (SMSGridView.SortDescriptors[i].PropertyName == "Date")
{
descriptorIndex = i;
break;
}
}
// custom sort the ticket column
if (descriptorIndex != -1)
{
// get data bound items for the two rows
SMSDataforGRID sms1 = e.Row1.DataBoundItem as SMSDataforGRID;
SMSDataforGRID sms2 = e.Row2.DataBoundItem as SMSDataforGRID;
// compare based on the sms time
int sortResult = sms1.DateTime.CompareTo(sms2.DateTime);
// invert result if set sort descriptor is descending
if (sortResult != 0)
{
if (this.SMSGridView.SortDescriptors[descriptorIndex].Direction == ListSortDirection.Descending)
sortResult = -sortResult;
}
// set sort result
e.SortResult = sortResult;
}
// do not handle the sorting for other columns
else
e.Handled = false;
}
private void rtbQuickText_TextChanged(object sender, EventArgs e)
{
if (CanSendQuickTextMessage(SMSTreeView.SelectedNode))
rbtSendQuick.Enabled = (rtbQuickText.Text.Length != 0);
// update the number of characters
labelCount.Text = String.Format(MainForm2.returnLNGString("charactersLeft"), rtbQuickText.MaxLength - rtbQuickText.Text.Length);
}
private void rddlFilterMsgStatus_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
// clear status filter
SMSGridView.FilterDescriptors.Remove("Status");
// Create a composite file descriptor with OR logic
FilterDescriptor valueFilter = new FilterDescriptor();
// if display all is selected I can exit
if (rddlFilterMsgStatus.SelectedIndex == 0)
{
return;
}
else if(rddlFilterMsgStatus.SelectedIndex == 1)
{
// read messages needs to be displayed
/*
statusDescriptor.FilterDescriptors.Add(new FilterDescriptor("Icon", FilterOperator.IsEqualTo,
global::Dispatcher.Properties.Resources.openEnvelope));
statusDescriptor.FilterDescriptors.Add(new FilterDescriptor("Status", FilterOperator.IsEqualTo,
1));*/
valueFilter = new FilterDescriptor("Status", FilterOperator.IsLike, "1");
/*
statusDescriptor.FilterDescriptors.Add(new FilterDescriptor("Status", FilterOperator.IsEqualTo,
(int)TextStatus.READ_OUT));*/
}
else
{
//r.Cells["Icon"].Value = global::Dispatcher.Properties.Resources.closedEnvelope;
// read messages needs to be displayed
// for each selected status add a custom filedescroptor
/*
statusDescriptor.FilterDescriptors.Add(new FilterDescriptor("Icon", FilterOperator.IsEqualTo,
global::Dispatcher.Properties.Resources.closedEnvelope));
statusDescriptor.FilterDescriptors.Add(new FilterDescriptor("Status", FilterOperator.IsEqualTo,0));/*
statusDescriptor.FilterDescriptors.Add(new FilterDescriptor("Status", FilterOperator.IsEqualTo,
(int)TextStatus.UNREAD_OUT));*/
valueFilter = new FilterDescriptor("Status", FilterOperator.IsLike, "0");
}
SMSGridView.FilterDescriptors.Add(valueFilter);
}
private void SMSGridView_FilterChanged(object sender, GridViewCollectionChangedEventArgs e)
{
/*
SMSGridView.DataSource = null;
SMSGridView.DataSource = ListforGrid;*/
}
}
}