288 lines
11 KiB
C#
288 lines
11 KiB
C#
namespace LaaProductionVFM
|
|
{
|
|
using System;
|
|
using System.Collections.Specialized;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Web.UI;
|
|
|
|
public partial class API : Page
|
|
{
|
|
protected void Page_Load(Object sender, EventArgs e)
|
|
{
|
|
var actionString = this.Request.QueryString.Get("action");
|
|
|
|
if (!String.IsNullOrWhiteSpace(actionString))
|
|
{
|
|
var action = this.GetType()
|
|
.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)
|
|
.Where(method => method.Name.Equals(actionString, StringComparison.OrdinalIgnoreCase))
|
|
.FirstOrDefault();
|
|
|
|
if (action != null)
|
|
{
|
|
this.Response.Clear();
|
|
this.Response.ContentType = "application/json";
|
|
|
|
action.Invoke(this, null);
|
|
|
|
this.Response.Flush();
|
|
}
|
|
}
|
|
}
|
|
|
|
/*****************************************************************************************
|
|
*
|
|
* A new control variable @IMAGE_MODE allows you to dynamically change the configuration
|
|
* of the sentinel for the next print job.
|
|
* If set to 0, the sentinel prints a label. -
|
|
* If set to 1, the sentinel generates a preview image of the label but does not print it.
|
|
* If set to 2, the sentinel prints the label and generates a preview image of the label.
|
|
*
|
|
*****************************************************************************************/
|
|
protected void PrintTestLabel()
|
|
{
|
|
try
|
|
{
|
|
var form = this.FormData<TestLabel>();
|
|
var builder = new StringBuilder();
|
|
|
|
builder.AppendLine(String.Format("@JOB_NAME = \"testlabel_{0}\"", form.PcbId));
|
|
builder.AppendLine(String.Format("@PRINTER_NAME = \"{0}\"", Appsettings.TestLabelPrinter));
|
|
builder.AppendLine(String.Format("@LABEL_NAME = \"{0}\"", Appsettings.TestLabel));
|
|
builder.AppendLine(String.Format("@IMAGE_MODE = \"{0}\"", 0));
|
|
builder.AppendLine(String.Format("ORDERNO = \"{0}\"", form.Orderno));
|
|
builder.AppendLine(String.Format("POSNO = \"{0}\"", form.Posno));
|
|
builder.AppendLine(String.Format("TESTDATE = \"{0}\"", form.TestDate));
|
|
builder.AppendLine(String.Format("PARTNO = \"{0}\"", form.Partno));
|
|
builder.AppendLine(String.Format("DESCL1 = \"{0}\"", form.DescriptionL1));
|
|
builder.AppendLine(String.Format("DESCL2 = \"{0}\"", form.DescriptionL2));
|
|
builder.AppendLine(String.Format("CUSTSN = \"{0}\"", form.CustId));
|
|
builder.AppendLine(String.Format("REGSN = \"{0}\"", form.FactId));
|
|
builder.AppendLine(String.Format("QMAXGPM = \"{0}\"", form.QmaxGPM));
|
|
builder.AppendLine(String.Format("QMIDGPM = \"{0}\"", form.QmidGPM));
|
|
builder.AppendLine(String.Format("QMINGPM = \"{0}\"", form.QminGPM));
|
|
builder.AppendLine(String.Format("QMAXACC = \"{0}\"", form.QmaxACC));
|
|
builder.AppendLine(String.Format("QMIDACC = \"{0}\"", form.QmidACC));
|
|
builder.AppendLine(String.Format("QMINACC = \"{0}\"", form.QminACC));
|
|
|
|
if (!String.IsNullOrWhiteSpace(Appsettings.TestLabelTxt))
|
|
{
|
|
var testDataTxt = String.Format(Appsettings.TestLabelTxt, form.PcbId);
|
|
var testLabelContent = builder.ToString();
|
|
|
|
File.WriteAllText(testDataTxt, testLabelContent);
|
|
|
|
this.Response.StatusCode = (Int32)HttpStatusCode.OK;
|
|
}
|
|
else
|
|
{
|
|
this.Response.StatusCode = (Int32)HttpStatusCode.BadRequest;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
this.Response.StatusCode = (Int32)HttpStatusCode.InternalServerError;
|
|
this.Response.Write(e.ToString());
|
|
}
|
|
}
|
|
|
|
/*****************************************************************************************
|
|
*
|
|
* A new control variable @IMAGE_MODE allows you to dynamically change the configuration
|
|
* of the sentinel for the next print job.
|
|
* If set to 0, the sentinel prints a label. -
|
|
* If set to 1, the sentinel generates a preview image of the label but does not print it.
|
|
* If set to 2, the sentinel prints the label and generates a preview image of the label.
|
|
*
|
|
*****************************************************************************************/
|
|
protected void PrintBoxLabel()
|
|
{
|
|
try
|
|
{
|
|
var form = this.FormData<BoxLabel>();
|
|
var builder = new StringBuilder();
|
|
|
|
builder.AppendLine(String.Format("@JOB_NAME = \"boxlabel_{0}\"", form.CustId));
|
|
builder.AppendLine(String.Format("@PRINTER_NAME = \"{0}\"", Appsettings.BoxLabelPrinter));
|
|
builder.AppendLine(String.Format("@LABEL_NAME = \"{0}\"", Appsettings.BoxLabel));
|
|
builder.AppendLine(String.Format("@IMAGE_MODE = \"{0}\"", 0));
|
|
builder.AppendLine(String.Format("TITLE = \"{0}\"", form.Title));
|
|
builder.AppendLine(String.Format("DESCL1 = \"{0}\"", form.DescriptionL1));
|
|
builder.AppendLine(String.Format("DESCL2 = \"{0}\"", form.DescriptionL2));
|
|
builder.AppendLine(String.Format("PARTNO = \"{0}\"", form.Partno));
|
|
builder.AppendLine(String.Format("ORDERNO = \"{0}\"", form.Orderno));
|
|
builder.AppendLine(String.Format("CUSTSN = \"{0}\"", form.CustId));
|
|
builder.AppendLine(String.Format("BOXDATE = \"{0}\"", form.BoxDate));
|
|
builder.AppendLine(String.Format("BOXNO = \"{0}\"", form.Boxno));
|
|
builder.AppendLine(String.Format("QUANTITY = \"{0}\"", form.Quantity));
|
|
|
|
if (!String.IsNullOrWhiteSpace(Appsettings.BoxLabelTxt))
|
|
{
|
|
var boxDataTxt = String.Format(Appsettings.BoxLabelTxt, form.CustId);
|
|
var boxLabelContent = builder.ToString();
|
|
|
|
File.WriteAllText(boxDataTxt, boxLabelContent);
|
|
|
|
this.Response.StatusCode = (Int32)HttpStatusCode.OK;
|
|
}
|
|
else
|
|
{
|
|
this.Response.StatusCode = (Int32)HttpStatusCode.BadRequest;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
this.Response.StatusCode = (Int32)HttpStatusCode.InternalServerError;
|
|
this.Response.Write(e.ToString());
|
|
}
|
|
}
|
|
|
|
private T FormData<T>() where T : new()
|
|
{
|
|
var expectedResult = new T();
|
|
var properties = expectedResult
|
|
.GetType()
|
|
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
|
.ToDictionary(x => x.Name.ToLower(), x => (Action<Object, Object>)x.SetValue);
|
|
|
|
var buffer = new Byte[this.Request.InputStream.Length];
|
|
var dataLength = this.Request.InputStream.Read(buffer, 0, buffer.Length);
|
|
var data = new Byte[dataLength];
|
|
|
|
Array.Copy(buffer, 0, data, 0, dataLength);
|
|
|
|
var content = Encoding.UTF8.GetString(data);
|
|
|
|
if (String.IsNullOrWhiteSpace(content))
|
|
{
|
|
return expectedResult;
|
|
}
|
|
|
|
content = content.Trim('"');
|
|
|
|
var parts = content.Split(new[] { ';', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
foreach (var part in parts)
|
|
{
|
|
if (String.IsNullOrWhiteSpace(part))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var tokens = part.Split(new[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
if (tokens.Length != 2)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var key = tokens[0];
|
|
var value = tokens[1];
|
|
|
|
if (String.IsNullOrWhiteSpace(key) || String.IsNullOrWhiteSpace(value))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
key = key.ToLower().Trim();
|
|
value = value.Trim();
|
|
|
|
if (properties.ContainsKey(key))
|
|
{
|
|
properties[key](expectedResult, value);
|
|
}
|
|
}
|
|
|
|
return expectedResult;
|
|
}
|
|
|
|
public class TestLabel
|
|
{
|
|
public String PcbId { get; set; }
|
|
|
|
public String Orderno { get; set; }
|
|
|
|
public String Posno { get; set; }
|
|
|
|
public String TestDate { get; set; }
|
|
|
|
public String Partno { get; set; }
|
|
|
|
public String DescriptionL1 { get; set; }
|
|
|
|
public String DescriptionL2 { get; set; }
|
|
|
|
public String CustId { get; set; }
|
|
|
|
public String FactId { get; set; }
|
|
|
|
public String QmaxGPM { get; set; }
|
|
|
|
public String QmidGPM { get; set; }
|
|
|
|
public String QminGPM { get; set; }
|
|
|
|
public String QmaxACC { get; set; }
|
|
|
|
public String QmidACC { get; set; }
|
|
|
|
public String QminACC { get; set; }
|
|
}
|
|
|
|
public class BoxLabel
|
|
{
|
|
public String CustId { get; set; }
|
|
|
|
public String Title { get; set; }
|
|
|
|
public String DescriptionL1 { get; set; }
|
|
|
|
public String DescriptionL2 { get; set; }
|
|
|
|
public String Partno { get; set; }
|
|
|
|
public String Orderno { get; set; }
|
|
|
|
public String BoxDate { get; set; }
|
|
|
|
public String Boxno { get; set; }
|
|
|
|
public String Quantity { get; set; }
|
|
}
|
|
|
|
public class Appsettings
|
|
{
|
|
public const String ERROR_MSG = "ERROR_MSG";
|
|
|
|
private static readonly NameValueCollection appsettings
|
|
= ConfigurationManager.AppSettings;
|
|
|
|
public static readonly String SQLServer = ConfigurationManager
|
|
.ConnectionStrings["DefaultConnection"]
|
|
.ConnectionString;
|
|
|
|
public static readonly String BoxLabel = appsettings["BoxLabel"];
|
|
|
|
public static readonly String BoxLabelPrinter = appsettings["BoxLabelPrinter"];
|
|
|
|
public static readonly String BoxLabelTxt = appsettings["BoxLabelTxt"];
|
|
|
|
public static readonly String BoxLabelJpg = appsettings["BoxLabelJpg"];
|
|
|
|
public static readonly String TestLabel = appsettings["TestLabel"];
|
|
|
|
public static readonly String TestLabelPrinter = appsettings["TestLabelPrinter"];
|
|
|
|
public static readonly String TestLabelTxt = appsettings["TestLabelTxt"];
|
|
|
|
public static readonly String TestLabelJpg = appsettings["TestLabelJpg"];
|
|
|
|
public static readonly String CurrentDirectory = appsettings["CurrentDirectory"];
|
|
}
|
|
}
|
|
} |