215 lines
7.4 KiB
C#
215 lines
7.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using GZTW.AyaNova.BLL;
|
|
|
|
namespace AyaNovaOL
|
|
{
|
|
public partial class WorkorderSelector : Form
|
|
{
|
|
public WorkorderSelector()
|
|
{
|
|
//MessageBox.Show("@ WorkorderSelector() constructor");
|
|
InitializeComponent();
|
|
//MessageBox.Show("@ WorkorderSelector() constructor - DONE");
|
|
}
|
|
|
|
ClientPickList aClientPickList { get; set; }
|
|
Dictionary<Guid, string> aWorkorderPickList { get; set; }
|
|
Dictionary<Guid, string> aTemplateList { get; set; }
|
|
public Guid SuggestedClient { get; set; }
|
|
public string EmailText { get; set; }
|
|
bool bLoading = true;
|
|
private void WorkorderSelector_Load(object sender, EventArgs e)
|
|
{
|
|
//MessageBox.Show("@ WorkorderSelector_Load TOP");
|
|
aTemplateList = new Dictionary<Guid, string>();
|
|
|
|
aClientPickList = ClientPickList.GetList(true);
|
|
cbClientID.DataSource=aClientPickList;
|
|
cbClientID.DisplayMember="Name";
|
|
cbClientID.ValueMember="ID";
|
|
bLoading = false;
|
|
|
|
|
|
aWorkorderPickList = new Dictionary<Guid, string>();
|
|
aWorkorderPickList.Add(Guid.Empty, "< New workorder >");
|
|
|
|
|
|
cbWO.DataSource = new BindingSource(aWorkorderPickList, "");
|
|
cbWO.ValueMember = "Key";
|
|
cbWO.DisplayMember = "Value";
|
|
|
|
// MessageBox.Show("@ WorkorderSelector_Load MIDDLE");
|
|
|
|
|
|
//This is likely temporary since we should try to autoselect the client before here
|
|
PopulateWorkorderList();
|
|
PopulateTemplateList();
|
|
cbTemplate.Visible = !AyaBizUtils.Lite;
|
|
lblTemplate.Visible = !AyaBizUtils.Lite;
|
|
SelectClient(SuggestedClient);
|
|
//MessageBox.Show("Suggested client: " + SuggestedClient.ToString());
|
|
|
|
//MessageBox.Show("@ WorkorderSelector_Load BOTTOM");
|
|
}
|
|
|
|
/// <summary>
|
|
/// select a client in the client combo
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
private void SelectClient(Guid id)
|
|
{
|
|
if (id != Guid.Empty)
|
|
{
|
|
foreach (ClientPickList.ClientPickListInfo i in cbClientID.Items)
|
|
{
|
|
if (i.ID == id)
|
|
{
|
|
cbClientID.SelectedItem = i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void cbClientID_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
PopulateWorkorderList();
|
|
}
|
|
|
|
private void PopulateWorkorderList()
|
|
{
|
|
if (bLoading) return;
|
|
//MessageBox.Show("cbClientID_SelectedIndexChanged");
|
|
aWorkorderPickList.Clear();
|
|
aWorkorderPickList.Add(Guid.Empty, "< New workorder >");
|
|
//Populate workorder list
|
|
if (cbClientID.SelectedItem != null)
|
|
{
|
|
ClientPickList.ClientPickListInfo infClient = (ClientPickList.ClientPickListInfo)cbClientID.SelectedItem;
|
|
|
|
WorkorderPickList wpl = WorkorderPickList.GetListByClient(infClient.ID);
|
|
foreach (WorkorderPickList.WorkorderPickListInfo i in wpl)
|
|
{
|
|
aWorkorderPickList.Add(i.ID, i.ServiceNumber + " - " + i.ServiceDate.ToString() + " " + i.Summary);
|
|
}
|
|
|
|
//select likely template
|
|
Guid gTemplate=TemplateServiceResolver.ResolveTemplate(infClient.ID, User.CurrentThreadUserID);
|
|
foreach (KeyValuePair<Guid, String> kvp in cbTemplate.Items)
|
|
{
|
|
if (kvp.Key == gTemplate)
|
|
{
|
|
cbTemplate.SelectedItem = kvp;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
cbWO.DataSource = new BindingSource(aWorkorderPickList, "");
|
|
}
|
|
|
|
private void cbWO_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (bLoading) return;
|
|
bool bCanSelectTemplate = cbWO.Text == "< New workorder >";
|
|
cbTemplate.Enabled = bCanSelectTemplate;
|
|
if (!bCanSelectTemplate)
|
|
{
|
|
if(cbTemplate.Items.Count >0)
|
|
cbTemplate.SelectedIndex = 0;
|
|
}
|
|
}
|
|
|
|
private void PopulateTemplateList()
|
|
{
|
|
if (bLoading) return;
|
|
aTemplateList.Clear();
|
|
|
|
if (!AyaBizUtils.Lite)//case 1172
|
|
{
|
|
TemplatePickList UList = TemplatePickList.GetList(WorkorderTypes.Service, true);
|
|
foreach (TemplatePickList.TemplatePickListInfo i in UList)
|
|
{
|
|
aTemplateList.Add(i.ID, i.Description);
|
|
}
|
|
}
|
|
cbTemplate.DataSource = new BindingSource(aTemplateList, "");
|
|
cbTemplate.ValueMember = "Key";
|
|
cbTemplate.DisplayMember = "Value";
|
|
}
|
|
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnOK_Click(object sender, EventArgs e)
|
|
{
|
|
//new workorder or existing
|
|
Workorder w;
|
|
WorkorderItem wi;
|
|
|
|
Guid gTemplateID = Guid.Empty;
|
|
if (!AyaBizUtils.Lite && cbTemplate.SelectedItem != null)
|
|
{
|
|
KeyValuePair<Guid, String> kvpSelectedTemplate = (KeyValuePair<Guid, String>)cbTemplate.SelectedItem;
|
|
gTemplateID = kvpSelectedTemplate.Key;
|
|
}
|
|
Guid gClientID=((ClientPickList.ClientPickListInfo)cbClientID.SelectedItem).ID;
|
|
KeyValuePair<Guid, String> kvpSelectedWorkorder = (KeyValuePair<Guid, String>) cbWO.SelectedItem;
|
|
if (kvpSelectedWorkorder.Key != Guid.Empty)
|
|
{
|
|
w = Workorder.GetItem(kvpSelectedWorkorder.Key);
|
|
wi = w.WorkorderItems.Add(w);
|
|
}
|
|
else
|
|
{
|
|
if (gTemplateID != Guid.Empty)
|
|
w = Workorder.NewItem(gTemplateID, gClientID);
|
|
else
|
|
{
|
|
w = Workorder.NewItem(WorkorderTypes.Service);
|
|
w.ClientID = gClientID;
|
|
}
|
|
wi = w.WorkorderItems[0];
|
|
}
|
|
wi.TechNotes += EmailText;
|
|
MsgToWo msg2wo = new MsgToWo();
|
|
msg2wo.mWorkorder = w;
|
|
msg2wo.mWorkorderItem = wi;
|
|
|
|
msg2wo.ShowDialog();
|
|
msg2wo.Dispose();
|
|
this.DialogResult = DialogResult.OK;
|
|
this.Close();
|
|
}
|
|
|
|
private void btnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
SearchForAyaNovaItem sd = new SearchForAyaNovaItem(EmailText,RootObjectTypes.Client);
|
|
|
|
if (sd.ShowDialog() == DialogResult.OK && sd.SelectedItemID != Guid.Empty)
|
|
{
|
|
|
|
SelectClient(sd.SelectedItemID);
|
|
}
|
|
sd.Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|