SafeDispatch/SubscriberAndUserManager/controlTicketing.cs

117 lines
4.1 KiB
C#
Raw Permalink Normal View History

2024-02-22 16:43:59 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SafeMobileLib;
using SafeMobileLib.DBmanagers;
using Telerik.WinControls.UI;
using System.Globalization;
namespace SubscriberAndUserManager
{
public partial class controlTicketing : UserControl
{
DBTicketingManager dbTicketStatus;
private List<TicketingStatus> ticketStatuses;
public TicketingStatus selectedTicketStatus;
private void setLanguage()
{
gvJobTicketing.Columns[0].HeaderText = MainForm.returnLNGString("id");
gvJobTicketing.Columns["status"].HeaderText = MainForm.returnLNGString("tsname");
gvJobTicketing.Columns["IsFirstState"].HeaderText = MainForm.returnLNGString("tsdefautstat");
gvJobTicketing.Columns["IsLastState"].HeaderText = MainForm.returnLNGString("tscompstat");
gvJobTicketing.Columns["SoundFile"].HeaderText = MainForm.returnLNGString("tssound");
gvJobTicketing.Columns["color"].HeaderText = MainForm.returnLNGString("tscolor");
}
public controlTicketing(DBTicketingManager DBreg)
{
InitializeComponent();
dbTicketStatus = DBreg;
ShowTicketStatuses();
setLanguage();
// set the row height
gvJobTicketing.TableElement.RowHeight = 43;
this.gvJobTicketing.EnableAlternatingRowColor = true;
this.gvJobTicketing.TableElement.GridViewElement.TableElement.AlternatingRowColor = Color.LightYellow;
// remove border for grid
this.gvJobTicketing.GridViewElement.DrawBorder = false;
this.gvJobTicketing.GridViewElement.GroupPanelElement.DrawBorder = false;
}
private void ShowTicketStatuses()
{
try
{
ticketStatuses = dbTicketStatus.getAllTicketStatuses();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
CustomMessageBox.Show(CustomMessageBoxType.exclamation, MainForm.returnLNGString("dberr"), MainForm.returnLNGString("err"));
return;
}
gvJobTicketing.DataSource = ticketStatuses;
if (ticketStatuses.Count > 0)
{
selectedTicketStatus = ticketStatuses[0];
}
}
private void gvJobTicketing_CellClick(object sender, GridViewCellEventArgs e)
{
if (e.RowIndex > -1)
{
selectedTicketStatus = (TicketingStatus)ticketStatuses[e.RowIndex];
}
}
private void gvJobTicketing_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;
}
int argb = -1;
if (e.CellElement.ColumnInfo.HeaderText == "Color")
{
argb = Int32.Parse(e.CellElement.Value.ToString(), NumberStyles.HexNumber);
e.CellElement.ForeColor = Color.FromArgb(argb);
}
}
/// <summary>
/// Change background color for the row according to its state and theme
/// </summary>
private void gvJobTicketing_RowFormatting(object sender, RowFormattingEventArgs e)
{
e.RowElement.DrawFill = true;
e.RowElement.NumberOfColors = 1;
if (e.RowElement.IsSelected)
e.RowElement.BackColor = MainForm.GridSelectedRow;
else
e.RowElement.BackColor = (e.RowElement.RowInfo.Index % 2 == 0 ? Color.White : MainForm.GridAlternateRow);
}
}
}