SafeDispatch/Safedispatch_4_0/NewJobTicketingForm.cs

857 lines
37 KiB
C#
Raw Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using System.Collections;
using Telerik.WinControls.UI;
using SafeMobileLib;
using System.Globalization;
namespace Safedispatch_4_0
{
public partial class NewJobTicketingForm : Telerik.WinControls.UI.RadForm
{
//private ConvertDT convDT;
private SMSmode Smode;
private TicketingUserControl parent;
private bool sched = false;
private DBTicketingManager DBT = new DBTicketingManager(MainForm2.cfg.DB_IP, MainForm2.cfg.DB_schema, MainForm2.cfg.DB_user, MainForm2.cfg.DB_passwd, MainForm2.cfg.DB_port);
private List<PredefineJobTicket> pdf = new List<PredefineJobTicket>();
private PredefineJobTicket CurrentConfiguration = new PredefineJobTicket();
private void setLanguage()
{
this.Text = MainForm2.returnLNGString("newJobTicket");
btnSend.Text = MainForm2.returnLNGString("send");
labelHandleBy.Text = MainForm2.returnLNGString("handledBy");
searchTextBox.NullText = MainForm2.returnLNGString("Typetosearchunit");
radLabel2.Text = MainForm2.returnLNGString("dueDate");
radLabel9.Text = MainForm2.returnLNGString("schedSending");
rcbSavePredefined.Text = MainForm2.returnLNGString("predTicket");
labelPredefined.Text = MainForm2.returnLNGString("prTick");
rddlPredefined.Items[0].Text = MainForm2.returnLNGString("currCfg");
labelSubject.Text = MainForm2.returnLNGString("t_subject");
rtbTicketSubject.NullText = MainForm2.returnLNGString("writeTSubj");
labelMessage.Text = MainForm2.returnLNGString("t_message");
rtbMessage.NullText = MainForm2.returnLNGString("leaveNull");
radLabel3.Text = MainForm2.returnLNGString("priority");
radLabel1.Text = MainForm2.returnLNGString("shareWithDispatchers");
rcbListSharedWith.NullText = MainForm2.returnLNGString("notShared");
rddListPriority.Items.Add(MainForm2.returnLNGString(PriorityType.Low.ToString()));
rddListPriority.Items.Add(MainForm2.returnLNGString(PriorityType.Normal.ToString()));
rddListPriority.Items.Add(MainForm2.returnLNGString(PriorityType.High.ToString()));
rddListPriority.Items.Add(MainForm2.returnLNGString(PriorityType.Critical.ToString()));
//lbPredefineSMS.Text = MainForm2.returnLNGString("AddPred");
//gbAdressBook.Text = MainForm2.returnLNGString("AddrBook");
//lbAdreesBookHelp.Text = MainForm2.returnLNGString("clickTo");
/*
lbGroups.Text = MainForm2.returnLNGString("GrpGroups") + ':';
lbUnits.Text = MainForm2.returnLNGString("GrpUnits") + ':';
lbTO.Text = MainForm2.returnLNGString("Ilabel2") + ':';
cbPredefine.Text = MainForm2.returnLNGString("selpredadd");
*/
}
public NewJobTicketingForm(TicketingUserControl parent, SMSmode _smode, string selectedUnitOrGroupName, string text)
{
this.parent = parent;
Smode = _smode;
InitializeComponent();
//ThemeResolutionService.ApplyThemeToControlTree(this, "ControlDefault");
setLanguage();
// set theme for the Message Box
RadMessageBox.SetThemeName("TelerikMetroBlue");
#region THEMING
btnSend.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
labelHandleBy.ForeColor = labelPredefined.ForeColor
= labelSubject.ForeColor = labelMessage.ForeColor
= MainForm2.LabelColor;
pbDelete.Image = Utils.ChangeColor(global::Dispatcher.Properties.Resources.trash_activ, MainForm2.ButtonColor);
rgbLeft.GroupBoxElement.Header.Border.TopColor = MainForm2.ButtonColor;
rgbLeft.GroupBoxElement.Header.Border.TopShadowColor = MainForm2.ButtonColor;
rgbRight.GroupBoxElement.Header.Border.TopColor = MainForm2.ButtonColor;
rgbRight.GroupBoxElement.Header.Border.TopShadowColor = MainForm2.ButtonColor;
#endregion
btnSend.Enabled = false;
// select first Predefined ticket value
rddlPredefined.SelectedIndex = 0;
getAllDispatcher();
switch (Smode)
{
case SMSmode.New4Unit:
//this.Text = Form1.returnLNGString("writenewSMS");
break;
case SMSmode.Forward:
//this.Text = Form1.returnLNGString("forwSMS");
break;
case SMSmode.Reply:
//this.Text = Form1.returnLNGString("replySMS");
//tbTO.Text += selectedUnitOrGroupName +";";
//tbTO.Text += selectedUnitOrGroupName;
break;
}
//convDT = new ConvertDT();
if(text!="")
{
rtbTicketSubject.Text += text;
}
populateListBoxGroup();
populateListBoxUnits();
rdtpSchedule.CustomFormat = Utils.getDayCustomFormat(MainForm2.is24hours, MainForm2.DayFirst);
//if (MainForm2.is24hours)
//{
// if (MainForm2.DayFirst)
// rdtpSchedule.CustomFormat = rdtpDueDate.CustomFormat = "dd/MM/yyyy HH:mm";
// else
// rdtpSchedule.CustomFormat = rdtpDueDate.CustomFormat = "MM/dd/yyyy HH:mm";
//}
//else
//{
// if (MainForm2.DayFirst)
// rdtpSchedule.CustomFormat = rdtpDueDate.CustomFormat = "dd/MM/yyyy hh:mm tt";
// else
// rdtpSchedule.CustomFormat = rdtpDueDate.CustomFormat = "MM/dd/yyyy hh:mm tt";
//}
rdtpSchedule.Value = DateTime.Now;
rdtpDueDate.Value = DateTime.Now;
rddListPriority.SelectedIndex = 0;
pdf = DBT.get_all_PredefineTickets();
foreach (PredefineJobTicket pd in pdf)
{
rddlPredefined.Items.Add(pd.Name);
}
if ((MainForm2.radioType != RADIOTYPE.MOTO) && (MainForm2.radioType != RADIOTYPE.TETRA) && (MainForm2.radioType != RADIOTYPE.CONECTPLUS) && (MainForm2.radioType != RADIOTYPE.REPEATER_TRBO))
{
try
{
switch (MainForm2.radioType)
{
case RADIOTYPE.HYT:
this.Icon = global::Dispatcher.Properties.Resources.HytSmall24;
this.BackColor = MainForm2.HyteraColor;
this.rtbTicketSubject.MaxLength = 250;
break;
case RADIOTYPE.HARRIS:
this.Icon = global::Dispatcher.Properties.Resources.HarrisSmall;
this.rtbTicketSubject.MaxLength = 250;
//this.lbGroups.ForeColor = MainForm2.HarTextColor;
//this.lbTO.ForeColor = MainForm2.HarTextColor;
//this.lbUnits.ForeColor = MainForm2.HarTextColor;
break;
case RADIOTYPE.ATLAS:
this.Icon = global::Dispatcher.Properties.Resources.ATLICO32;
break;
case RADIOTYPE.SIMOCO:
this.Icon = global::Dispatcher.Properties.Resources.simoco_dispatch_24;
break;
case RADIOTYPE.EXCERA:
this.Icon = global::Dispatcher.Properties.Resources.AXYS_ICON;
break;
}
}
catch (Exception ex)
{
SM.Debug("Error on change color hytera/harris:" + ex.ToString());
}
}
}
private void btnSendTicket_Click(object sender, EventArgs e)
{
string shareWith = "";
if(rcbListSharedWith.CheckedItems.Count > 0)
foreach (RadListDataItem item in rcbListSharedWith.CheckedItems)
{
User user = item.DataBoundItem as User;
if (user != null)
shareWith += user.Id + ";";
}
string specified_end_time = "";
// check ticket subject
if (rtbTicketSubject.Text.Trim().Length < 2)
{
RadMessageBox.Show(this, "Please fill the ticket subject", "", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
rtbTicketSubject.Focus();
return;
}
// check due date
if (rcbDueDate.Checked)
specified_end_time = ((int)rdtpDueDate.Value.ToUniversalTime().DateTo70Format()).ToString();
if (rdtpDueDate.Value < DateTime.Now && rcbDueDate.Checked)
{
RadMessageBox.Show(this, MainForm2.returnLNGString("endtimegrCurrTime"), "", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
rdtpDueDate.Value = DateTime.Now;
return;
}
if (rdtpSchedule.Value < DateTime.Now && rcbSchedule.Checked)
{
RadMessageBox.Show(this, MainForm2.returnLNGString("schtimegrCurrTime"), "", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
rdtpSchedule.Value = DateTime.Now;
return;
}
if (rdtpSchedule.Value > rdtpDueDate.Value && rcbSchedule.Checked && rcbDueDate.Checked)
{
RadMessageBox.Show(this, MainForm2.returnLNGString("endtimegrSchedtime"), "", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
return;
}
PriorityType priority = (PriorityType)rddListPriority.SelectedIndex;
string sms = string.Format("{0}^{1}^{2}^{3}^{4}^{5}", rtbTicketSubject.Text, rtbMessage.Text, rddListPriority.SelectedItem == null ? "" : priority.ToString(), MainForm2.userLog,specified_end_time,shareWith);
sms = sms.Replace("\'", "\'\'");
int ticket = DBT.getMaxTicketID();
sms = "<JTS>" + ticket.ToString() + Environment.NewLine + sms;
if (rtbTicketSubject.Text.Length > 0)
{
List<Int32> assignedUnitsIds = new List<Int32>();
List<String> assignedUnits = new List<string>();
// check all group nodes to see which one is checked
foreach (RadTreeNode groupNode in treeViewUnits.Nodes)
{
// skip groups with no unit checked
if (groupNode.CheckState == Telerik.WinControls.Enumerations.ToggleState.Off)
continue;
// go through each unit and get the checked ones
foreach (RadTreeNode unitNode in groupNode.Nodes)
{
if (unitNode.Checked)
{
assignedUnits.Add(unitNode.Name);
assignedUnitsIds.Add((Int32)unitNode.Tag);
}
}
}
//send predefined message
if (rcbSavePredefined.Checked)
{
RadTreeNodeCollection rtnC = treeViewUnits.Nodes;
PredefineJobTicket PredefineTicketToSave = new PredefineJobTicket();
PredefineTicketToSave.Name = rtbTicketName.Text;
PredefineTicketToSave.Text = rtbTicketSubject.Text;
PredefineTicketToSave.Comment = rtbMessage.Text;
PredefineTicketToSave.Priority = rddListPriority.SelectedItem.Text;
if (rcbDueDate.Checked)
{
TimeSpan ts = Convert.ToDateTime(rdtpDueDate.Value) - DateTime.Now;
PredefineTicketToSave.Enddate = (int)ts.TotalSeconds;
}
if (rcbSchedule.Checked)
{
TimeSpan ts = DateTime.Today.AddHours(rdtpSchedule.Value.Hour).AddMinutes(rdtpSchedule.Value.Minute) - DateTime.Today;
PredefineTicketToSave.Scheduledate = (int)ts.TotalSeconds;
}
else PredefineTicketToSave.Scheduledate = -1;
foreach (int assignedUnitsId in assignedUnitsIds)
PredefineTicketToSave.Handled_by += assignedUnitsId + ";";
PredefineTicketToSave.Share_with = shareWith;
//PredefineTicketToSave.Share_with = rddListPriority.SelectedItem.Text;
TicketResponse b = DBT.InsertUpdate_Define_Ticket(PredefineTicketToSave);
}
// show error message if not unit is checked
if (assignedUnits.Count == 0 )
{
RadMessageBox.Show(this, "You haven't selected any unit", "", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
treeViewUnits.Focus();
return;
}
string[] units = assignedUnits.ToArray();// dest.Split(';');
String mess15 = MainForm2.returnLNGString("info");
String message = MainForm2.returnLNGString("limitSMSto10");
String question = MainForm2.returnLNGString("contorlessunits");
Boolean execute = true;
// show Confirmation dialog if the number of selected units is greater than 10
if ((assignedUnits.Count > 10) && ((MainForm2.radioType == RADIOTYPE.MOTO) || (MainForm2.radioType == RADIOTYPE.ATLAS) || (MainForm2.radioType == RADIOTYPE.TETRA) || (MainForm2.radioType == RADIOTYPE.CONECTPLUS) || (MainForm2.radioType == RADIOTYPE.REPEATER_TRBO)))
{
DialogResult dr2 = RadMessageBox.Show(this, message + "\r\n" + question, mess15, MessageBoxButtons.YesNo, RadMessageIcon.Exclamation);
if (dr2 != DialogResult.Yes)
execute = false;
}
// execute because number of units is grater than 10 or user accepted the risk
// of loosing messages
if (execute)
{
foreach (string unitNameOrGroup in units)
{
try
{
InsertOneSMSinDB4units(unitNameOrGroup, sms);
parent.parent.DisplayToast(MainForm2.returnLNGString("jt2Unit") + (assignedUnits.Count > 1 ? assignedUnits.Count + MainForm2.returnLNGString("units") : assignedUnits[0]),
string.Format(MainForm2.returnLNGString("ticketSubjectHTML"),rtbTicketSubject.Text));
}
catch (Exception ex)
{
SM.Debug("Ex:" + ex.ToString());
}
}
this.Close();
}
}
}
private void btnSendSched_Click(object sender, EventArgs e)
{
sched = true;
if (rdtpSchedule.Value < DateTime.Now)
{
if ((MainForm2.radioType == RADIOTYPE.HARRIS)||(MainForm2.radioType == RADIOTYPE.ATLAS)) ((RadLabel)RadMessageBox.Instance.Controls[1]).LabelElement.ForeColor = MainForm2.HarTextColor;
RadMessageBox.Show(MainForm2.returnLNGString("sched_error") + DateTime.Now.ToString(), MainForm2.returnLNGString("error") + "!", MessageBoxButtons.OK, RadMessageIcon.Exclamation);
}
else
btnSend.PerformClick();
sched = false;
}
private void InsertOneSMSinDB4units(string unitName, string sms)
{
if (unitName != "")
{
if (MainForm2.vehicleHT.ContainsKey(unitName))
{
SM.Debug("Adding SMS to DB for unit:" + unitName);
int sc_id = ((Vehicle)MainForm2.vehicleHT[unitName]).sc_id;
int sched_time = 0;
sched = rcbSchedule.Checked;
if (!sched)
sched_time = 0;
else
sched_time = (int)rdtpSchedule.Value.ToUniversalTime().DateTo70Format();
parent.SendSMS(sms, sc_id, sched_time);
}
else
{
SM.Debug("Error NewJobTicketingForm /InsertOneSMSinDB/ selected item(" + unitName + ") not in hashtable");
}
}
}
private void InsertOneSMSinDB4Groups(ArrayList scIDarray, string sms)
{
if (scIDarray.Count>0)
{
foreach (int scID in scIDarray)
{
SM.Debug("Adding SMS to DB for unit with scid:" + scID);
int sched_time = 0;
if (!sched)
sched_time = 0;
else
sched_time = (int)rdtpSchedule.Value.ToUniversalTime().DateTo70Format();
parent.SendSMS(sms, scID, sched_time);
}
}
}
private void InsertOneSMSinDB4Groups_with_cpsID(Int32 cps_id, string sms)
{
try
{
SM.Debug("Adding SMS to DB for group with cpsid:" + cps_id);
int sched_time = 0;
if (!sched)
sched_time = 0;
else
sched_time = (int)rdtpSchedule.Value.ToUniversalTime().DateTo70Format();
//if (scIDarray.Count>0) parent.SendSMSGroup(sms,cps_id, sched_time,(Int32)scIDarray[0]);
parent.SendSMSGroup(sms, cps_id, sched_time);
}
catch (Exception ex)
{
SM.Debug("Exception on InsertOneSMSinDB4Groups_with_cpsID:"+ex.ToString());
}
}
/// <summary>
/// Add the Groups as Nodes inside the Tree View
/// </summary>
private void populateListBoxGroup()
{
GroupClass g = new GroupClass();
// for each group add a tree node
foreach (int i in MainForm2.GroupHash.Keys)
{
g = (GroupClass)MainForm2.GroupHash[i];
AddTreeGroup(g.name, g.id);
}
}
/// <summary>
/// Add a Group Node to the Tree View
/// </summary>
/// <param name="groupName">Group name which needs to be added to the Tree Node</param>
/// <param name="groupID">Group ID which will be set as a tag for this group node</param>
/// <returns>Returns the inserted Tree Node</returns>
private RadTreeNode AddTreeGroup(string groupName, Int32 groupID)
{
RadTreeNode groupNode = new RadTreeNode(groupName.ToUpper());
groupNode.Font = new Font(
new FontFamily("Segoe UI"),
13,
FontStyle.Bold,
GraphicsUnit.Pixel);
groupNode.Tag = groupID;
groupNode.CheckState = Telerik.WinControls.Enumerations.ToggleState.Off;
groupNode.Expanded = true;
groupNode.Image = Utils.ChangeColor(global::Dispatcher.Properties.Resources.s_group, MainForm2.ButtonColor);
// add the node to the tree view
treeViewUnits.Nodes.Add(groupNode);
return groupNode;
}
private bool DefaultGroupAdded = false;
/// <summary>
/// Add Units to the groups nodes in the Tree View
/// </summary>
private void populateListBoxUnits()
{
// for each Unit defined in the hash table
foreach (DictionaryEntry de in MainForm2.vehicleHT)
{
Vehicle veh = de.Value as Vehicle;
if (veh != null)
{
RadTreeNode unitNode = new RadTreeNode(veh.busName);
unitNode.Tag = veh.sc_id;
Car crtCar = ((Car)MainForm2.carlist[((Vehicle)MainForm2.vehicleHT[veh.busName]).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
unitNode.Image = MainForm2.imagesDictionary[crtCar.listFilePath + "_16"];
}
catch (Exception)
{
SM.Debug("Grid icon could not be found [" + iconPath + "]");
unitNode.Image = global::Dispatcher.Properties.Resources.subscriber;
}
}
// check to see if the unit is assigned to a group
if (veh.group != null && veh.group.Id != 0)
{
// the group already exists
}
else
{
// create Unassigned group if not created until now
if (!DefaultGroupAdded)
{
AddTreeGroup(MainForm2.returnLNGString("otherunit"), 0);
DefaultGroupAdded = true;
}
}
// search the group in which the unit will be added
foreach (RadTreeNode groupNode in treeViewUnits.Nodes)
{
Int32 groupID = (Int32)groupNode.Tag;
if (groupID == veh.group.Id)
groupNode.Nodes.Add(unitNode);
}
}
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void getAllDispatcher()
{
List<User> dispatchers = new List<User>();
// get all dispatchers from the hash table
foreach(KeyValuePair<Int32, User> entry in TicketingUserControl.dispatchersList)
{
if(entry.Value.Lastname != MainForm2.userLog)
dispatchers.Add(entry.Value);
}
//ShareWithGridView.DataSource = usrList;
rcbListSharedWith.DataSource = dispatchers;
rcbListSharedWith.DisplayMember = "UserName";
}
private void NewJobTicketingForm_FormClosed(object sender, FormClosedEventArgs e)
{
parent.StartRefresh();
}
/// <summary>
/// Enable or disable the Schedule DateTime Picker
/// </summary>
private void rcbSchedule_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
rdtpSchedule.Enabled =
(args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On ? true : false);
}
/// <summary>
/// Save the current UI state to a temp Predefinet Ticket and then
/// change the UI to display a predefined ticket values
/// </summary>
private void rddlPredefined_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
// show delete only if not "Current configuration"
pbDelete.Visible = e.Position != 0;
rcbListSharedWith.Text = "";
rcbListSharedWith.CheckedItems.Clear();
rtbTicketName.Text = (rddlPredefined.SelectedIndex == 0) ? MainForm2.returnLNGString("ticketName") : rddlPredefined.SelectedItem.Text;
if (e.Position != 0)
{
foreach (PredefineJobTicket pd in pdf)
{
if (pd.Name == ((RadDropDownList)sender).SelectedItem.ToString())
{
rtbTicketSubject.Text = pd.Text;
rtbMessage.Text = pd.Comment;
rddListPriority.SelectedIndex = rddListPriority.FindString(pd.Priority);
rdtpDueDate.Value = DateTime.Now.AddSeconds(pd.Enddate);
if (pd.Scheduledate > -1)
{
rdtpSchedule.Value = DateTime.Today.AddSeconds(pd.Scheduledate);
rdtpSchedule.Value = (rdtpSchedule.Value < DateTime.Now) ? rdtpSchedule.Value.AddDays(1) : rdtpSchedule.Value;
}
else rdtpSchedule.Value = DateTime.Now;
if (pd.Share_with != null && pd.Share_with.Length > 0)
{
string[] shared = pd.Share_with.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); ;
foreach (string dispatcherID in shared)
{
// get dispatcher name if exists
if (TicketingUserControl.dispatchersList.ContainsKey(Int32.Parse(dispatcherID)))
rcbListSharedWith.Text += TicketingUserControl.dispatchersList[Int32.Parse(dispatcherID)].UserName + ";";
else
rcbListSharedWith.Text += dispatcherID + ";";
}
}
if (pd.Handled_by != null)
{
foreach (RadTreeNode groupNode in treeViewUnits.Nodes)
{
// go through each unit and get the checked ones
2024-06-07 13:20:57 +00:00
string[] splitHandled_by = pd.Handled_by.Split(";".ToCharArray());
2024-02-22 16:43:59 +00:00
foreach (RadTreeNode unitNode in groupNode.Nodes)
{
2024-06-07 13:20:57 +00:00
unitNode.Checked = (Array.IndexOf(splitHandled_by, unitNode.Tag.ToString()) > -1);
2024-02-22 16:43:59 +00:00
}
}
}
}
}
}
else
{
rtbTicketSubject.Text = CurrentConfiguration.Text;
rtbMessage.Text = CurrentConfiguration.Comment;
rddListPriority.SelectedIndex = (CurrentConfiguration.Priority != null) ? rddListPriority.FindString(CurrentConfiguration.Priority) : 0;
rdtpDueDate.Value = DateTime.Now.AddSeconds(CurrentConfiguration.Enddate);
if (CurrentConfiguration.Share_with != null && CurrentConfiguration.Share_with.Length > 0)
{
string[] shared = CurrentConfiguration.Share_with.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); ;
foreach (string dispatcherID in shared)
{
// get dispatcher name if exists
if (TicketingUserControl.dispatchersList.ContainsKey(Int32.Parse(dispatcherID)))
rcbListSharedWith.Text += TicketingUserControl.dispatchersList[Int32.Parse(dispatcherID)].UserName + ";";
else
rcbListSharedWith.Text += dispatcherID + ";";
}
}
if (CurrentConfiguration.Handled_by != null)
{
foreach (RadTreeNode groupNode in treeViewUnits.Nodes)
{
// go through each unit and get the checked ones
2024-06-07 13:20:57 +00:00
string[] splitHandled_by = CurrentConfiguration.Handled_by.Split(";".ToCharArray());
2024-02-22 16:43:59 +00:00
foreach (RadTreeNode unitNode in groupNode.Nodes)
{
unitNode.Checked = (Array.IndexOf(splitHandled_by, unitNode.Tag.ToString()) > -1);
}
}
}
else
{
foreach (RadTreeNode groupNode in treeViewUnits.Nodes)
{
// uncheck all nodes
foreach (RadTreeNode unitNode in groupNode.Nodes)
{
unitNode.Checked = false;
}
}
}
}
}
/// <summary>
/// Save the current ticket configuration to a Predefined one. If the
/// drop down list text is "Current configuration" I should change the
/// message to 'Type Predefined Template name'
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pbSaveTemplate_Click(object sender, EventArgs e)
{
if (rddlPredefined.Text == MainForm2.returnLNGString("currCfg"))
{
rddlPredefined.Text = "Type predefined ticket name";
rddlPredefined.Focus();
rddlPredefined.SelectAllText();
}
}
/// <summary>
/// Hide or show text box for predefined Ticket and focuts the text box
/// </summary>
private void rcbSavePredefined_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
rtbTicketName.Visible = (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On);
rtbTicketName.Text = (rddlPredefined.SelectedIndex == 0) ? MainForm2.returnLNGString("ticketName") : rddlPredefined.SelectedItem.Text;
rtbTicketName.Focus();
rtbTicketName.SelectAll();
}
/// <summary>
/// Enable or disable the date time pickers depending on the state of
/// the checkboxex
/// </summary>
/// <param name="sender">The CheckBox which changed its state</param>
private void CheckBox_StateChanged(object sender, StateChangedEventArgs args)
{
if ((RadCheckBox)sender == rcbDueDate)
rdtpDueDate.Enabled = rcbDueDate.Checked;
else if ((RadCheckBox)sender == rcbSchedule)
rdtpSchedule.Enabled = rcbSchedule.Checked;
}
/// <summary>
/// Delete Predefine Ticket from DB and remove it from
/// rddlPredefined drop down list
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void pbDelete_Click(object sender, EventArgs e)
{
try
{
if (rddlPredefined.SelectedIndex > 0)
{
//remove from DB
DBT.delete_Predefine_Ticket(rddlPredefined.SelectedItem.ToString());
//remove from list
foreach(PredefineJobTicket pd in pdf)
{
if (pd.Name == rddlPredefined.SelectedItem.ToString())
{
pdf.Remove(pd);
rddlPredefined.Items.Remove(rddlPredefined.SelectedItem);
if(rddlPredefined.Items.Count > 1) rddlPredefined.SelectedIndex -= 1;
}
}
}
}
catch (Exception ex)
{
SM.Debug("EX:" + ex.ToString());
}
}
/// <summary>
/// Save current configuration state
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void rddlPredefined_SelectedIndexChanging(object sender, Telerik.WinControls.UI.Data.PositionChangingCancelEventArgs e)
{
//if (rddlPredefined.SelectedIndex == 0) doesn't work
if (((Telerik.WinControls.UI.RadDropDownList)(sender)).SelectedItems.Count > 0)
{
if (((Telerik.WinControls.UI.RadDropDownList)(sender)).SelectedItems[0].RowIndex == 0)
{
//CurrentConfiguration = new PredefineJobTicket();
CurrentConfiguration.Text = rtbTicketSubject.Text;
CurrentConfiguration.Comment = rtbMessage.Text;
CurrentConfiguration.Priority = rddListPriority.SelectedItem.Text;
if (rcbDueDate.Checked)
{
TimeSpan ts = Convert.ToDateTime(rdtpDueDate.Value) - DateTime.Now;
CurrentConfiguration.Enddate = (int)ts.TotalSeconds;
}
CurrentConfiguration.Share_with = "";
CurrentConfiguration.Handled_by = "";
foreach (RadListDataItem item in rcbListSharedWith.CheckedItems)
{
User user = item.DataBoundItem as User;
if (user != null)
CurrentConfiguration.Share_with += user.Id + ";";
}
foreach (RadTreeNode groupNode in treeViewUnits.Nodes)
{
// skip groups with no unit checked
if (groupNode.CheckState == Telerik.WinControls.Enumerations.ToggleState.Off)
continue;
// go through each unit and get the checked ones
foreach (RadTreeNode unitNode in groupNode.Nodes)
{
if (unitNode.Checked)
{
CurrentConfiguration.Handled_by += unitNode.Tag + ";";
}
}
}
}
}
}
private void rtbTicketName_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsLetterOrDigit(e.KeyChar))
{
e.Handled = true;
}
}
private void NewJobTicketingForm_Load(object sender, EventArgs e)
{
// set the checkboxes for due date and schedule to unchecked
rcbSchedule.Checked = false;
rcbDueDate.Checked = false;
}
/// <summary>
/// Change background color for the row according to its state and theme
/// </summary>
private void treeViewUnits_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;
}
/// <summary>
/// Filter the tree node based on the text from the search box
/// </summary>
private void searchTextBox_TextChanged(object sender, EventArgs e)
{
treeViewUnits.Filter = null;
treeViewUnits.Filter = searchTextBox.Text;
}
/// <summary>
/// Validate form when a node is checked or unckhcked. This is done to prevent
/// the case when no unit is selected or text message is not filled
/// </summary>
private void treeViewUnits_NodeCheckedChanged(object sender, TreeNodeCheckedEventArgs e)
{
if (treeViewUnits.CheckedNodes.Count > 0 && rtbTicketSubject.Text.Length > 0)
btnSend.Enabled = true;
else
btnSend.Enabled = false;
}
/// <summary>
/// Enable or disable UI elements depending on the number of characters
/// </summary>
private void rtbTicketSubject_TextChanged(object sender, EventArgs e)
{
if (treeViewUnits.CheckedNodes.Count > 0 && rtbTicketSubject.Text.Length > 0)
btnSend.Enabled = true;
else
btnSend.Enabled = false;
}
/// <summary>
/// Change background color of the button when it becomes enable or disabled
/// </summary>
private void btnSend_EnabledChanged(object sender, EventArgs e)
{
if (btnSend.Enabled)
btnSend.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColor;
else
btnSend.ButtonElement.ButtonFillElement.BackColor = MainForm2.ButtonColorDisabled;
}
}
}