795 lines
32 KiB
C#
795 lines
32 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using AyaNova.PlugIn;
|
||
using GZTW.AyaNova.BLL;
|
||
using System.ComponentModel;
|
||
using System.Windows.Forms;
|
||
using System.Reflection;
|
||
using System.Data;
|
||
|
||
using Infragistics.Documents.Excel;
|
||
|
||
namespace AyaNova.Plugin.RepairTekCPC
|
||
{
|
||
class RepairTek : IAyaNovaPlugin
|
||
{
|
||
//Keep all the object types we want to deal with in a collection
|
||
//so that we can quickly check it when asked
|
||
private static List<RootObjectTypes> ObjectsWeCanDealWith = null;
|
||
//Holds the image resources from AyaNova
|
||
//so we can display the correct icons in our plugin
|
||
System.Resources.ResourceManager resman = null;
|
||
|
||
//Holds the current logged in user's localized text
|
||
//lookup object
|
||
LocalizedTextTable LocaleText = null;
|
||
|
||
#region IAyaNovaPlugin Members
|
||
|
||
#region interface properties
|
||
public string PluginName
|
||
{
|
||
get { return "RepairTek - Create Service Orders"; }
|
||
}
|
||
|
||
public string PluginVersion
|
||
{
|
||
get { return "7.2"; }
|
||
}
|
||
|
||
public string About
|
||
{
|
||
get
|
||
{
|
||
return "AyaNova RepairTek - Create Service Orders plugin\r\n" +
|
||
"Copyright 2009-2014 Ground Zero Tech-Works Inc.";
|
||
}
|
||
}
|
||
|
||
public Guid PluginID
|
||
{
|
||
get { return new Guid("{1A8DE4EF-A6B6-4B50-B2D3-44BBB43B289E}"); }
|
||
}
|
||
|
||
public System.Drawing.Image PluginSmallIcon
|
||
{
|
||
get { return null; }
|
||
}
|
||
|
||
public System.Drawing.Image PluginLargeIcon
|
||
{
|
||
get { return null; }
|
||
}
|
||
|
||
public System.Resources.ResourceManager AyaNovaResourceManager
|
||
{
|
||
set { resman = value; }
|
||
get { return resman; }
|
||
}
|
||
#endregion interface properties
|
||
|
||
#region Initialization and Close
|
||
public bool Initialize(Version AyaNovaVersion, LocalizedTextTable localizedText)
|
||
{
|
||
LocaleText = localizedText;
|
||
ObjectsWeCanDealWith = new List<RootObjectTypes>();
|
||
ObjectsWeCanDealWith.Add(RootObjectTypes.Nothing);
|
||
return true;
|
||
}
|
||
|
||
public void Close()
|
||
{
|
||
;
|
||
}
|
||
#endregion Initialization and close
|
||
|
||
#region ShowMenu?
|
||
public bool SingleObjectMenuShow(RootObjectTypes objectType)
|
||
{
|
||
return (ObjectsWeCanDealWith.Contains(objectType));
|
||
}
|
||
|
||
public bool MultipleObjectsMenuShow(RootObjectTypes objectType)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
#endregion show menu?
|
||
|
||
#region Menu options
|
||
public List<AyaNovaPluginMenuItem> SingleObjectMenuOptions(RootObjectTypes objectType, object ayaNovaObject)
|
||
{
|
||
|
||
|
||
if (!ObjectsWeCanDealWith.Contains(objectType)) return null;
|
||
List<AyaNovaPluginMenuItem> list = new List<AyaNovaPluginMenuItem>();
|
||
list.Add(new AyaNovaPluginMenuItem("REPAIRTEK3", "RepairTek - Create Service Orders", null, null));
|
||
return list;
|
||
}
|
||
|
||
public List<AyaNovaPluginMenuItem> MultipleObjectsMenuOptions(RootObjectTypes objectType)
|
||
{
|
||
|
||
return null;
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region Menu Commands
|
||
|
||
#region LIST OBJECT COMMAND
|
||
/// <summary>
|
||
/// LIST OBJECT
|
||
/// </summary>
|
||
/// <param name="commandKey"></param>
|
||
/// <param name="objectType"></param>
|
||
/// <param name="objectIDList"></param>
|
||
/// <param name="listObject"></param>
|
||
/// <returns></returns>
|
||
public bool CommandSelectedForList(string commandKey, RootObjectTypes objectType, List<Guid> objectIDList, object listObject)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
#endregion list object command
|
||
|
||
#region SINGLE OBJECT COMMAND
|
||
/// <summary>
|
||
/// SINGLE OBJECT
|
||
/// </summary>
|
||
/// <param name="commandKey"></param>
|
||
/// <param name="objectType"></param>
|
||
/// <param name="ayaNovaObject"></param>
|
||
public void CommandSelectedForSingleObject(string commandKey, RootObjectTypes objectType, object ayaNovaObject)
|
||
{
|
||
|
||
switch (commandKey)
|
||
{
|
||
|
||
case "REPAIRTEK3":
|
||
{
|
||
Update();
|
||
}
|
||
break;
|
||
}
|
||
|
||
}
|
||
#endregion single object command
|
||
|
||
#endregion menu commands
|
||
|
||
#endregion
|
||
|
||
/*
|
||
THIS IS THE "REPAIRTEK 3" PLUGIN - Create Service Orders
|
||
|
||
*/
|
||
|
||
#region REPAIRTEK3 Create workorders from spreadsheet
|
||
#region specifications
|
||
/*
|
||
*
|
||
* Specifics of plugin needed:
|
||
|
||
First row of the xlxs file being imported will always just be headers. Include code to not import first row.
|
||
|
||
|
||
Plugin specifications:
|
||
|
||
provide ability for the user to select any xlxs file
|
||
i.e. browse feature so he can select file from any folder, etc
|
||
xlxs file will have a header row, and then any number of rows
|
||
as per example xlxs file Sample_OpenWO_onerow.xlxs
|
||
a new workorder is to be created for each row
|
||
the new workorder to have in it selected the Workorder Status with specific text and case of OPEN ORDERS
|
||
and the following imported:
|
||
as per example xlxs file which identifies which specific AyaNova field corresponds to which column that will be imported Sample_OpenWO_columnsidentified.xlxs (this sample has an extra header row identifying in default what the field corresponds to as well as additional row under with more info - NOT to be used as example xlxs file imported.
|
||
A column: workorder # / WO#
|
||
This column will be ignored.
|
||
B column: Client / CLIENT
|
||
This column equates to an existing client record already in AyaNova.
|
||
If client is not yet entered in AyaNova, skip creating workorder - and indicate so in the text dialogue that displays.
|
||
Expectation that will always be the same client, but just in case...
|
||
C and D column:
|
||
will be ignored
|
||
E column: Unit / UNIT
|
||
If existing unit with that exact serial number and case owned by the client above is already entered into AyaNova, this unit will be selected for this new workorder.
|
||
If there is not an existing unit with that exact serial number and case owned by the client above, the unit record to be created ( with serial number and client who owns is all that is needed).
|
||
F column: Client Ref # / PULSE INCIDENT
|
||
Workorder.Label.CustomerReferenceNumber
|
||
Import the text from this column into the Client Ref # field
|
||
G column: Contact / Comments o RMA#
|
||
Workorder.Label.CustomerContactName
|
||
Import the text from this column into the Contact field
|
||
H column: Project / Problem Description
|
||
O.Project
|
||
Select existing Project record with exact same spelling and case
|
||
If there is not an existing Project record with exact same spelling and case as that in the xlxs file, skip importing BUT identify in the text dialogue box missing project record
|
||
I column: Summary / WC#
|
||
Workorder.Label.Summary
|
||
Import the text from this column into the Summary field
|
||
J column: Item Summary / INCOMING WAYBILL
|
||
WorkorderItem.Label.Summary
|
||
Import the text from this column into the Item Summary field
|
||
K column: Priority / DATA
|
||
WorkorderItem.Label.PriorityID
|
||
Select existing Priority record with exact same spelling and case
|
||
If there is not an existing Priority record with exact same spelling and case as that in the xlxs file, skip creating workorder and indicate so in the text dialogue
|
||
L column: Travel Details/ CONTACT
|
||
WorkorderItemTravel.Label.TravelDetails
|
||
Import the text from this column into a new travel record's Travel Details field
|
||
M column: Workorder Item Type / SITE ADDRESS
|
||
WorkorderItem.Label.TypeID
|
||
Select existing Workorder Item Type record with exact same spelling and case
|
||
If there is not an existing Workorder Item Type record with exact same spelling and case as that in the xlxs file, leave blank and indicate had to do so in the text dialogue window
|
||
|
||
|
||
*
|
||
*
|
||
* UPDATE: November 17th, apparently not correct in how missing data is handled, this is an addendum:
|
||
*
|
||
* B column: Client / CLIENT
|
||
If there is not an existing Client record with exact same spelling and case as that in the xlxs file,
|
||
create the client record, and then continue with creating the workorder and importing the fields.
|
||
|
||
|
||
H column: Project / Problem Description
|
||
If there is not an existing Project record with exact same spelling and case as that in the xlxs file
|
||
-leave field blank in the service workorder, indicate had to do so in the text dialogue window and continue to create this workorder..
|
||
|
||
|
||
K column: Priority / DATA
|
||
If there is not an existing Priority record with exact same spelling and case as that in the xlxs file,
|
||
-leave field blank in the service workorder, indicate had to do so in the text dialogue window and continue to create this workorder.
|
||
|
||
|
||
M column: Workorder Item Type / SITE ADDRESS
|
||
If there is not an existing Workorder Item Type record with exact same spelling and case as that in the xlxs file,
|
||
leave field blank in the service workorder and indicate had to do so in the text dialogue window and continue to create this workorder.
|
||
|
||
|
||
*
|
||
* UPDATE: 11/18/2014 blank fields should be also reported as warning in unmatchable warning for columns H K and M
|
||
|
||
*
|
||
*
|
||
*
|
||
*
|
||
*
|
||
*
|
||
* UPDATE: 11/26/2014
|
||
*
|
||
Hi Joyce, I added some answers below and attached sample with missing fields. Columns A and G will always be blank so no error indication is required for these.
|
||
|
||
The same error message can be used as per current plugin that you just created. Sorry I don’t have anything to create currently and I can’t remember the message that it would display. If you cannot retrieve, message can be ‘skipped missing field(s)’.
|
||
|
||
Thanks.Regards, Frank Sanzo
|
||
|
||
From: AyaNova Sales & Support [mailto:support@ayanova.com]
|
||
Sent: Wednesday, November 26, 2014 11:32 AM
|
||
To: Frank Sanzo
|
||
Subject: Re: FW: Creating new Service Order using selected xlxs
|
||
|
||
Hello Frank
|
||
|
||
I have received response back from development. Please provide the following:
|
||
|
||
In reference to "that if any field is blank," are you referring to if a field in the row in a XLXS file that is blank? - YES
|
||
Please identify which specific field(s) (field in which columns) or if all fields – all fields
|
||
Provide a copy of an existing xlxs file that shows examples of blank in each field (i.e. one row has one specific field blank, a second row has a different specific field blank, a third row has two specific fields blank and so on )
|
||
Provide examples of the indication in the dialogue box you would want to show for these that would occur in #3 above
|
||
|
||
Thank you!
|
||
|
||
- Joyce
|
||
www.ayanova.com
|
||
|
||
On 11/25/2014 4:51 PM, Frank Sanzo wrote:
|
||
|
||
Hi Joyce, this plugin does work properly as per the emails but I may have left out an action
|
||
that if any field is blank, not just the pulldowns,
|
||
that we can also get an indication in dialogue box that it has to do so.
|
||
And continue to create the workorder. Please let me know the charge to make this change. Thank you.
|
||
|
||
*
|
||
*
|
||
* DEVELOPMENT RESPONSE:
|
||
* Changes made to plugin column handling code:
|
||
|
||
Column A - No change, is ignored, always blank, as per instructions won't report
|
||
Column B - No change, client name if empty already reports as Error in log and won't import that row.
|
||
Column C - No change, not used by plugin, will not report empty values in this column
|
||
Column D - No change, not used by plugin, will not report empty values in this column
|
||
Column E - No change, Serial column. Plugin uses this field to detect empty rows and so this is a required column to import the row, if this column is empty it will just skip that row assuming it's an empty row. Have left it unchanged without reporting if this field is empty because the import spreadsheets have many empty rows at the bottom and if this were to report every empty row it would be a lot of redundant information.
|
||
if Frank expects there could be actual rows that have data in other fields but are missing the serial number then we should change how it detects empty rows to check more columns, however the way it works now is simple and reliable for detecting empppty rows if there will always be a serial number.
|
||
Column F - Now reports if column is empty in import file.
|
||
Column G - No change, is ignored, always blank, as per instructions won't report
|
||
Column H - Now reports if column is empty in import file. (Unchanged: If it is not empty but can't be matched to an existing value (project) reports as before exact value and fact it couldn't be matched.)
|
||
COLUMN I - Now reports if column is empty in import file.
|
||
COLUMN J - Now reports if column is empty in import file.
|
||
COLUMN K - Now reports if column is empty in import file. (Unchanged: If it is not empty but can't be matched to an existing value (Priority) reports as before exact value and fact it couldn't be matched.)
|
||
Column L - Now reports if column is empty in import file.
|
||
Column M - Now reports if column is empty in import file. (Unchanged: If it is not empty but can't be matched to an existing value (TypeID) reports as before exact value and fact it couldn't be matched.)
|
||
|
||
*
|
||
*
|
||
*
|
||
* Update December 10 2014
|
||
* New column N
|
||
*
|
||
|
||
The existing Create Service Order plugin is to be further modified so that if there is text in column N for that row:
|
||
|
||
a Misc Expense record is created for the created workorder
|
||
the text in column N is copied to the Description field of the Misc Expense record
|
||
all other fields of the Misc record are left blank or unselected
|
||
|
||
|
||
If there is no text in column N for that row:
|
||
|
||
a warning to display to the report at the end
|
||
|
||
|
||
* */
|
||
#endregion specifications
|
||
|
||
/// <summary>
|
||
/// Update workorders
|
||
/// </summary>
|
||
private void Update()
|
||
{
|
||
//track ops to report upon completion
|
||
System.Text.StringBuilder sb = new StringBuilder();
|
||
sb.AppendLine("Import results:");
|
||
|
||
#region Open the xls file
|
||
OpenFileDialog ofd = new OpenFileDialog();
|
||
ofd.Multiselect = false;
|
||
ofd.Title = "";
|
||
ofd.DefaultExt = "xlsx";
|
||
ofd.FileName = "*.xlsx";
|
||
if (ofd.ShowDialog() != DialogResult.OK) return;
|
||
Workbook workbook;
|
||
try
|
||
{
|
||
workbook = Workbook.Load(ofd.FileName);
|
||
sb.AppendLine("File " + ofd.FileName + " opened for processing...");
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
MessageBox.Show("Error opening file:\r\n" + ex.ToString());
|
||
return;
|
||
}
|
||
|
||
ofd.Dispose();
|
||
#endregion open the xls
|
||
|
||
//Projects list
|
||
ProjectList projects = ProjectList.GetList("");
|
||
|
||
//fetch priority list
|
||
PriorityPickList priorities = PriorityPickList.GetList();
|
||
|
||
//fetch workorder item type list
|
||
WorkorderItemTypePickList typesList = WorkorderItemTypePickList.GetList();
|
||
|
||
//default status
|
||
WorkorderStatusPickList wspl = WorkorderStatusPickList.GetList();
|
||
Guid openOrderStatus = GetMatchingStatus(wspl, "OPEN ORDERS");
|
||
if (openOrderStatus == Guid.Empty)
|
||
{
|
||
MessageBox.Show("Error: Workorder status of \"OPEN ORDERS\" not found in AyaNova database and is required to proceed.");
|
||
return;
|
||
}
|
||
|
||
//default unit model:
|
||
//CN50AQU1LP20
|
||
UnitModelPickList umpl = UnitModelPickList.GetList();
|
||
Guid defaultUnitModelId = GetMatchingUnitModel(umpl, "CN50AQU1LP20");
|
||
if (defaultUnitModelId == Guid.Empty)
|
||
{
|
||
MessageBox.Show("Error: Unit model \"CN50AQU1LP20\" not found in AyaNova database and is required to proceed.");
|
||
return;
|
||
}
|
||
|
||
|
||
//client list
|
||
// ClientPickList cpl = ClientPickList.GetList();
|
||
|
||
//Iterate the workorders
|
||
Cursor.Current = Cursors.WaitCursor;
|
||
|
||
int nRow = 0;
|
||
foreach (WorksheetRow r in workbook.Worksheets[0].Rows)
|
||
{
|
||
nRow++;
|
||
|
||
//wo number not used in this plugin except to skip over empty / title row
|
||
string sWorkorderNumber = SafeGetCellValue(r, 0);
|
||
//skip over empty or title rows
|
||
if (string.IsNullOrEmpty(sWorkorderNumber))
|
||
sWorkorderNumber = "UNKNOWN";
|
||
|
||
if (sWorkorderNumber.StartsWith("W"))
|
||
continue;
|
||
//empty row check, if no sn then it's empty
|
||
string sSerial = SafeGetCellValue(r, 4);
|
||
if (string.IsNullOrWhiteSpace(sSerial))
|
||
{
|
||
//can't do this because there are so many emppty rows it would fill up the dialog box
|
||
//If more stringent empty row checking is required then we need to check all columns or some key ones in combination
|
||
//if(nRow > 1)
|
||
// sb.AppendLine("WARNING:\t[Row " + nRow.ToString() + "]\tSerial field (column E) value is blank, assuming empty row and skipping.");
|
||
continue;
|
||
}
|
||
|
||
|
||
Workorder w = Workorder.NewItem(WorkorderTypes.Service);
|
||
w.WorkorderService.WorkorderStatusID = openOrderStatus;
|
||
//Need a workorder item
|
||
if (w.WorkorderItems.Count < 1)
|
||
w.WorkorderItems.Add(w);
|
||
|
||
#region Set values from spreadsheet row
|
||
|
||
//B 2nd column Client name
|
||
string sClient = SafeGetCellValue(r, 1);
|
||
if (string.IsNullOrWhiteSpace(sClient))
|
||
{
|
||
sb.AppendLine("INFO:\t[Row " + nRow.ToString() + "]\tCLIENT field value is blank in import file can't match or create without a client name - NOT IMPORTED!");
|
||
continue;
|
||
}
|
||
Guid clientId = GetSertClient(sClient);
|
||
w.ClientID = clientId;
|
||
|
||
//E 5th column UNIT
|
||
//Moved this up in order to check for empty rows
|
||
//string sSerial = SafeGetCellValue(r, 4);
|
||
Guid unitId = GetSertUnit(sSerial, clientId, defaultUnitModelId);
|
||
w.WorkorderItems[0].UnitID = unitId;
|
||
|
||
//F 6th column PULSE INCIDENT (Workorder.Label.CustomerReferenceNumber)
|
||
string sPulse = SafeGetCellValue254(r, 5);
|
||
if (string.IsNullOrWhiteSpace(sPulse))
|
||
{
|
||
sb.AppendLine("INFO:\t[Row " + nRow.ToString() + "]\tPULSE INCIDENT (column F) is blank in import file.");
|
||
}
|
||
w.CustomerReferenceNumber = sPulse;
|
||
|
||
//G 7th column Comments / RMA field (Workorder.Label.CustomerContactName)
|
||
string sRMA = SafeGetCellValue254(r, 6);
|
||
w.CustomerContactName = sRMA;
|
||
|
||
//H 8th column PROBLEM DESCRIPTI (O.Project matchup to insert in Workorder.ProjectID)
|
||
string sProblem = SafeGetCellValue(r, 7);
|
||
if (string.IsNullOrWhiteSpace(sProblem))
|
||
{
|
||
sb.AppendLine("INFO:\t[Row " + nRow.ToString() + "]\tPROBLEM DESCRIPTION (column H) is blank in import file.");
|
||
}
|
||
else
|
||
{
|
||
|
||
Guid projectId = GetMatchingProject(projects, sProblem);
|
||
if (projectId != Guid.Empty)
|
||
{
|
||
w.ProjectID = projectId;
|
||
}
|
||
else
|
||
{
|
||
//no match, this is not an error just log as warning
|
||
sb.AppendLine("WARNING:\t[Row " + nRow.ToString() + "]\tPROBLEM DESCRIPTION field value: \"" + sProblem + "\" no match, left blank.");
|
||
}
|
||
}
|
||
|
||
//I 9th column Summary / WC field (Workorder.Label.Summary)
|
||
string sSummary = SafeGetCellValue254(r, 8);
|
||
if (string.IsNullOrWhiteSpace(sSummary))
|
||
{
|
||
sb.AppendLine("INFO:\t[Row " + nRow.ToString() + "]\tSummary / WC (column I) is blank in import file.");
|
||
}
|
||
//always overwrite unless empty
|
||
if (!string.IsNullOrWhiteSpace(sSummary))
|
||
w.Summary = sSummary;
|
||
|
||
//J 10th column INCOMING WAYBILL field (WorkorderItem.Label.Summary)
|
||
string sIncomingWayBill = SafeGetCellValue254(r, 9);
|
||
if (string.IsNullOrWhiteSpace(sIncomingWayBill))
|
||
{
|
||
sb.AppendLine("INFO:\t[Row " + nRow.ToString() + "]\tINCOMING WAYBILL (column J) is blank in import file.");
|
||
}
|
||
w.WorkorderItems[0].Summary = sIncomingWayBill;
|
||
|
||
//K 11th column Priority / DATA field (WorkorderItem.Label.PriorityID matchup from list)
|
||
string sData = SafeGetCellValue(r, 10);
|
||
if (string.IsNullOrWhiteSpace(sData))
|
||
{
|
||
sb.AppendLine("INFO:\t[Row " + nRow.ToString() + "]\tPriority / DATA (column K) is blank in import file.");
|
||
}
|
||
else
|
||
{
|
||
Guid priorityId = GetMatchingPriority(priorities, sData);
|
||
if (priorityId != Guid.Empty)
|
||
{
|
||
w.WorkorderItems[0].PriorityID = priorityId;
|
||
}
|
||
else
|
||
{
|
||
//no match - log warning
|
||
sb.AppendLine("WARNING:\t[Row " + nRow.ToString() + "]\tPriority / DATA field value: \"" + sData + "\" no match, left blank.");
|
||
}
|
||
}
|
||
|
||
//L 12th column CONTACT field (WorkorderItemTravel.Label.TravelDetails)
|
||
string sContact = SafeGetCellValue(r, 11);
|
||
if (string.IsNullOrWhiteSpace(sContact))
|
||
{
|
||
sb.AppendLine("INFO:\t[Row " + nRow.ToString() + "]\tCONTACT (column L) is blank in import file.");
|
||
}
|
||
if (!string.IsNullOrWhiteSpace(sContact))
|
||
{
|
||
if (!w.WorkorderItems[0].HasTravel)
|
||
w.WorkorderItems[0].Travels.Add(w.WorkorderItems[0]);
|
||
w.WorkorderItems[0].Travels[0].TravelDetails = sContact;
|
||
}
|
||
|
||
//M 13th column Workorder Item Type / SITE ADDRESS field (WorkorderItem.Label.TypeID matchup from list)
|
||
string sSiteAddress = SafeGetCellValue(r, 12);
|
||
if (string.IsNullOrWhiteSpace(sSiteAddress))
|
||
{
|
||
sb.AppendLine("INFO:\t[Row " + nRow.ToString() + "]\tSITE ADDRESS (column M) is blank in import file.");
|
||
}
|
||
else
|
||
{
|
||
Guid typeId = GetMatchingType(typesList, sSiteAddress);
|
||
if (typeId != Guid.Empty)
|
||
{
|
||
w.WorkorderItems[0].TypeID = typeId;
|
||
}
|
||
else
|
||
{
|
||
//no match - log warning
|
||
sb.AppendLine("WARNING:\t[Row " + nRow.ToString() + "]\tWorkorder Item Type / SITE ADDRESS field value: \"" + sSiteAddress + "\" no match, left blank.");
|
||
}
|
||
}
|
||
|
||
//N 14th column POSTAL CODE / goes into a new misc expense record's description field
|
||
string sPostalCode = SafeGetCellValue254(r, 13);
|
||
if (string.IsNullOrWhiteSpace(sPostalCode))
|
||
{
|
||
sb.AppendLine("INFO:\t[Row " + nRow.ToString() + "]\tPOSTAL CODE (column N) is blank in import file.");
|
||
}
|
||
else
|
||
{
|
||
w.WorkorderItems[0].Expenses.Add(w.WorkorderItems[0]);
|
||
w.WorkorderItems[0].Expenses[0].Description = sPostalCode;
|
||
}
|
||
|
||
#endregion set values from spreadsheet row
|
||
|
||
if (w.IsSavable)
|
||
{
|
||
w = (Workorder)w.Save();
|
||
sb.AppendLine("INFO:\t[Row " + nRow.ToString() + "]\tworkorder \"" + w.WorkorderService.ServiceNumber + "\" created in AyaNova");
|
||
}
|
||
else
|
||
{
|
||
sb.AppendLine("ERROR:\t[Row " + nRow.ToString() + "]\tcouldn't be saved due to broken rules, error was:\r\n----------------------------------\r\n" + w.BrokenRulesText + "\r\n----------------------------------");
|
||
}
|
||
|
||
}
|
||
Cursor.Current = Cursors.Default;
|
||
sb.AppendLine("All rows in spreadsheet processed!");
|
||
//Report results
|
||
ReportResults(sb);
|
||
}
|
||
|
||
|
||
|
||
private void ReportResults(StringBuilder sb)
|
||
{
|
||
CopyableMessageBox dlgCMB = new CopyableMessageBox(sb.ToString());
|
||
dlgCMB.ShowDialog();
|
||
|
||
}
|
||
|
||
//safe get cell value
|
||
private string SafeGetCellValue(WorksheetRow r, int nColumn)
|
||
{
|
||
object o = r.Cells[nColumn].Value;
|
||
if (o == null) return "";
|
||
else
|
||
return o.ToString();
|
||
}
|
||
|
||
//safe get cell value no longer than 254 characters
|
||
private string SafeGetCellValue254(WorksheetRow r, int nColumn)
|
||
{
|
||
object o = r.Cells[nColumn].Value;
|
||
if (o == null) return "";
|
||
else
|
||
{
|
||
string ret = o.ToString();
|
||
return ret.Length <= 254 ? ret : ret.Substring(0, 254);
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// Attempt to match status from text in spreadsheet
|
||
/// if no match return guid empty
|
||
/// </summary>
|
||
/// <param name="ppl"></param>
|
||
/// <param name="sToMatch"></param>
|
||
/// <returns></returns>
|
||
Guid GetMatchingStatus(WorkorderStatusPickList ppl, string sToMatch)
|
||
{
|
||
foreach (WorkorderStatusPickList.WorkorderStatusPickListInfo i in ppl)
|
||
{
|
||
if (i.Name.Equals(sToMatch, StringComparison.InvariantCultureIgnoreCase))
|
||
{
|
||
return i.ID;
|
||
}
|
||
}
|
||
|
||
return Guid.Empty;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Attempt to match priority from text in spreadsheet
|
||
/// if no match return guid empty
|
||
/// </summary>
|
||
/// <param name="ppl"></param>
|
||
/// <param name="sToMatch"></param>
|
||
/// <returns></returns>
|
||
Guid GetMatchingPriority(PriorityPickList ppl, string sToMatch)
|
||
{
|
||
foreach (PriorityPickList.PriorityPickListInfo i in ppl)
|
||
{
|
||
if (i.Name.Equals(sToMatch, StringComparison.InvariantCultureIgnoreCase))
|
||
{
|
||
return i.ID;
|
||
}
|
||
}
|
||
|
||
return Guid.Empty;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Attempt to match Workorder item type from text in spreadsheet
|
||
/// if no match return guid empty
|
||
/// </summary>
|
||
/// <param name="ppl"></param>
|
||
/// <param name="sToMatch"></param>
|
||
/// <returns></returns>
|
||
Guid GetMatchingType(WorkorderItemTypePickList l, string sToMatch)
|
||
{
|
||
foreach (WorkorderItemTypePickList.WorkorderItemTypePickListInfo i in l)
|
||
{
|
||
if (i.Name.Equals(sToMatch, StringComparison.InvariantCultureIgnoreCase))
|
||
{
|
||
return i.ID;
|
||
}
|
||
}
|
||
|
||
return Guid.Empty;
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// Attempt to match Project from text in spreadsheet
|
||
/// if no match return guid empty
|
||
/// </summary>
|
||
/// <param name="l"></param>
|
||
/// <param name="sToMatch"></param>
|
||
/// <returns></returns>
|
||
Guid GetMatchingProject(ProjectList l, string sToMatch)
|
||
{
|
||
foreach (ProjectList.ProjectListInfo i in l)
|
||
{
|
||
if (i.LT_O_Project.Display.Equals(sToMatch, StringComparison.InvariantCultureIgnoreCase))
|
||
{
|
||
return i.LT_O_Project.Value;
|
||
}
|
||
}
|
||
|
||
return Guid.Empty;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// Attempt to match Client from text in spreadsheet
|
||
/// if no match return guid empty
|
||
/// </summary>
|
||
/// <param name="l"></param>
|
||
/// <param name="sToMatch"></param>
|
||
/// <returns></returns>
|
||
Guid GetMatchingClient(ClientPickList l, string sToMatch)
|
||
{
|
||
foreach (ClientPickList.ClientPickListInfo i in l)
|
||
{
|
||
if (i.Name.Equals(sToMatch, StringComparison.InvariantCultureIgnoreCase))
|
||
{
|
||
return i.ID;
|
||
}
|
||
}
|
||
|
||
return Guid.Empty;
|
||
}
|
||
|
||
/// <summary>
|
||
/// Attempt to match unit model from text in spreadsheet
|
||
/// if no match return guid empty
|
||
/// </summary>
|
||
/// <param name="ppl"></param>
|
||
/// <param name="sToMatch"></param>
|
||
/// <returns></returns>
|
||
Guid GetMatchingUnitModel(UnitModelPickList ppl, string sToMatch)
|
||
{
|
||
foreach (UnitModelPickList.UnitModelPickListInfo i in ppl)
|
||
{
|
||
//Note: name is combined number and name fields here so
|
||
//can't directly match
|
||
if (i.Name.Contains(sToMatch))
|
||
{
|
||
return i.ID;
|
||
}
|
||
}
|
||
|
||
return Guid.Empty;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// gets matching unit ID or, if it's not there, inserts one and returns that Id
|
||
/// </summary>
|
||
/// <param name="serialNumber"></param>
|
||
/// <param name="ClientId"></param>
|
||
/// <returns></returns>
|
||
Guid GetSertUnit(string serialNumber, Guid ClientId, Guid UnitModelId)
|
||
{
|
||
|
||
UnitPickList upl = UnitPickList.GetListByClient(ClientId);
|
||
foreach (UnitPickList.UnitPickListInfo i in upl)
|
||
{
|
||
if (i.Serial == serialNumber)
|
||
return i.ID;
|
||
}
|
||
|
||
//here due to no match, so make one now
|
||
Unit u = Unit.NewItem();
|
||
u.ClientID = ClientId;
|
||
u.Serial = serialNumber;
|
||
u.UnitModelID = UnitModelId;
|
||
u = (Unit)u.Save();
|
||
return u.ID;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// gets matching client ID or, if it's not there, inserts one and returns that Id
|
||
/// </summary>
|
||
/// <param name="serialNumber"></param>
|
||
/// <param name="ClientId"></param>
|
||
/// <returns></returns>
|
||
Guid GetSertClient(string sClientName)
|
||
{
|
||
Guid ret = Client.IDFromName(sClientName);
|
||
if (ret != Guid.Empty)
|
||
return ret;
|
||
|
||
Client c = Client.NewItem();
|
||
c.Name = sClientName;
|
||
|
||
c = (Client)c.Save();
|
||
return c.ID;
|
||
}
|
||
|
||
#endregion update
|
||
}
|
||
}
|