130 lines
4.8 KiB
C#
130 lines
4.8 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Data.SqlClient;
|
|||
|
|
|
|||
|
|
namespace DatabaseImport
|
|||
|
|
{
|
|||
|
|
public class TemplateRegion
|
|||
|
|
{
|
|||
|
|
public string TemplateName { get; }
|
|||
|
|
|
|||
|
|
public string TemplateZone { get; }
|
|||
|
|
|
|||
|
|
public int RegionNumber { get; set; }
|
|||
|
|
|
|||
|
|
public string RegionName { get; set; }
|
|||
|
|
|
|||
|
|
public string RegionDescription { get; set; }
|
|||
|
|
|
|||
|
|
public string TestObject { get; set; }
|
|||
|
|
|
|||
|
|
public string Position { get; set; }
|
|||
|
|
|
|||
|
|
public string MainLocation { get; set; }
|
|||
|
|
|
|||
|
|
public string FineLocation1 { get; set; }
|
|||
|
|
|
|||
|
|
public string FineLocation2 { get; set; }
|
|||
|
|
|
|||
|
|
public string FineLocation3 { get; set; }
|
|||
|
|
|
|||
|
|
public string PhysicalDimension { get; set; }
|
|||
|
|
|
|||
|
|
public string Direction { get; set; }
|
|||
|
|
|
|||
|
|
public string FilterClass { get; set; }
|
|||
|
|
|
|||
|
|
public bool LocalOnly { get; } = false;
|
|||
|
|
|
|||
|
|
private int _upperLeftX = 0;
|
|||
|
|
private int _upperLeftY = 0;
|
|||
|
|
private int _lowerRightX = 0;
|
|||
|
|
private int _lowerRightY = 0;
|
|||
|
|
|
|||
|
|
public System.Drawing.Point UpperLeft
|
|||
|
|
{
|
|||
|
|
get => new System.Drawing.Point(_upperLeftX, _upperLeftY);
|
|||
|
|
set { _upperLeftX = value.X; _upperLeftY = value.Y; }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public System.Drawing.Point LowerRight
|
|||
|
|
{
|
|||
|
|
get => new System.Drawing.Point(_lowerRightX, _lowerRightY);
|
|||
|
|
set { _lowerRightX = value.X; _lowerRightY = value.Y; }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public TemplateRegion(string templateName, string zoneName, bool bLocalOnly)
|
|||
|
|
{
|
|||
|
|
TemplateName = templateName;
|
|||
|
|
TemplateZone = zoneName;
|
|||
|
|
LocalOnly = bLocalOnly;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public TemplateRegion(DataRow dr)
|
|||
|
|
{
|
|||
|
|
TemplateName = (string)dr["TemplateName"];
|
|||
|
|
RegionNumber = Convert.ToInt32(dr["RegionNumber"]);
|
|||
|
|
RegionName = (string)dr["RegionName"];
|
|||
|
|
RegionDescription = (string)dr["RegionDescription"];
|
|||
|
|
TestObject = (string)dr["TestObject"];
|
|||
|
|
Position = (string)dr["Position"];
|
|||
|
|
MainLocation = (string)dr["MainLocation"];
|
|||
|
|
FineLocation1 = (string)dr["FineLocation1"];
|
|||
|
|
FineLocation2 = (string)dr["FineLocation2"];
|
|||
|
|
FineLocation3 = (string)dr["FineLocation3"];
|
|||
|
|
PhysicalDimension = (string)dr["PhysicalDimension"];
|
|||
|
|
Direction = (string)dr["Direction"];
|
|||
|
|
FilterClass = (string)dr["FilterClass"];
|
|||
|
|
LocalOnly = Convert.ToBoolean(dr["LocalOnly"]);
|
|||
|
|
_upperLeftX = Convert.ToInt32(dr["UpperLeftX"]);
|
|||
|
|
_upperLeftY = Convert.ToInt32(dr["UpperLeftY"]);
|
|||
|
|
_lowerRightX = Convert.ToInt32(dr["LowerRightX"]);
|
|||
|
|
_lowerRightY = Convert.ToInt32(dr["LowerRightY"]);
|
|||
|
|
TemplateZone = (string)dr["ZoneName"];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
internal static TemplateRegion[] GetAllRegions(string templateName, string zoneName)
|
|||
|
|
{
|
|||
|
|
var regions = new List<TemplateRegion>();
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
using (var cmd = DbOperations.GetSQLCommand(true))
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
cmd.CommandType = CommandType.StoredProcedure;
|
|||
|
|
cmd.CommandText = DbOperationsEnum.StoredProcedure.sp_TemplateRegionsGet.ToString();
|
|||
|
|
cmd.Parameters.Add(
|
|||
|
|
new SqlParameter("@TemplateName", SqlDbType.NVarChar, 255) { Value = templateName });
|
|||
|
|
cmd.Parameters.Add(new SqlParameter("@ZoneName", SqlDbType.NVarChar, 50) { Value = zoneName });
|
|||
|
|
using (var ds = DbOperations.Connection.QueryDataSet(cmd))
|
|||
|
|
{
|
|||
|
|
if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
|
|||
|
|
{
|
|||
|
|
foreach (DataRow dr in ds.Tables[0].Rows)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
regions.Add(new TemplateRegion(dr));
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
//APILogger.Log("Failed to retrieve a region", templateName, ex);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
finally
|
|||
|
|
{
|
|||
|
|
cmd.Connection.Dispose();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception) {/* APILogger.Log("Failed to retrieve regions", templateName, ex);*/ }
|
|||
|
|
return regions.ToArray();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|