Пример #1
0
 /// <summary>
 /// Debug method for Milton to test where printing to UID4 is failing.20180502:GD
 /// Remove at some point.
 /// </summary>
 /// <param name="label"></param>
 /// <param name="quantity"></param>
 private static void ForkPrintToMTSB(CSLabel label, Int32 quantity)
 {
     (new Thread(() =>
     {
         PrintLabel("MTSB", label, quantity);
     })).Start();
 }
Пример #2
0
        public static CSLabel GetLabel(string labelName, string labelPath)
        {
            CSLabel standardLabel = new CSLabel();

            standardLabel.Name = labelName;
            standardLabel.Path = labelPath;
            return(standardLabel);
        }
Пример #3
0
 public void Dispose()
 {
     if (_CurrentDocument != null)
     {
         try
         {
             //_CurrentDocument.Close(false);
             _CurrentDocument = null;
             //log4net.LogManager.GetLogger("DEBUG").Error(new Exception("Document Dispose. Session ID:" + ID));
         }
         catch (Exception err)
         {
             log4net.LogManager.GetLogger("DEBUG").Error(err);
         }
     }
     if (_CurrentLabel != null)
     {
         _CurrentLabel.CSVariables.Clear();
         _CurrentLabel = null;
     }
 }
Пример #4
0
 /// <summary>
 /// Sets an immutable reference to the current CSLabel
 /// </summary>
 /// <param name="label"></param>
 public void SetLabel(CSLabel label)
 {
     if (label == null)
     {
         Dispose();
     }
     else
     {
         //prevent mutation
         CSLabel obj = CSLabelManager.GetLabel(label.Name, label.Path);
         obj.AddVariables(label.CSVariables);
         this._CurrentLabel = obj;
         //if (this._CurrentDocument != null)
         //this._CurrentDocument.Close(false);
         CSDocument Doc = SessionManager.Documents.Where(p => p.LabelPath == label.Path).FirstOrDefault();
         this._CurrentDocument = Doc;
         if (Doc == null)
         {
             Doc = CSNetApp.Instance.OpenDocument(obj.Path);
             this._CurrentDocument = Doc;
             SessionManager.Documents.Add(Doc);
         }
     }
 }
Пример #5
0
        /// <summary>
        /// The Print app is a web based label printing program that allows a user to print from a large list of labels.
        /// The map used is a large poly zone so it should accept most variable inputs.
        /// Input Folder: \\netapp\labels\Sentinel\Print_app\INPUT
        /// Output Folder:  \\netapp\labels\Sentinel\Print_app\OUTPUT
        /// Label files will be retained for 7 days.
        /// File format:  The data files MUST start with “PA”.  (PA*.*).  It is strongly recommended that you make each file name unique.  i.e. add date and time to the filename.  This will prevent the files from being overwritten in the output folder and will help with troubleshooting.
        /// </summary>
        /// <param name="printer"></param>
        /// <param name="label"></param>
        public static void PrintLabel(string printer, CSLabel label, Int32 quantity)
        {
            bool   hasSerialNumberRange = label.CSVariables.Exists(p => p.Value.Contains(Constants.Delimiter_SequencedNumberRange));
            string sentinelPath         = @"\\netapp\labels\Sentinel\Print_app\INPUT";
            string sentinelPrefix       = "PA";
            string prnstring            = "";

            if (quantity > 1 || hasSerialNumberRange)
            {
                //for (int i = 0; i < quantity; i++)
                //{
                if (hasSerialNumberRange)
                {
                    CodeSoftDTO.Variable rangeVariable = label.CSVariables.Where(p => p.Value.Contains(Constants.Delimiter_SequencedNumberRange)).First();
                    string originalValue   = rangeVariable.Value;
                    int    delimiterIndex  = rangeVariable.Value.IndexOf(Constants.Delimiter_SequencedNumberRange);
                    int    delimiterLength = Constants.Delimiter_SequencedNumberRange.Length;
                    string startString     = rangeVariable.Value.Substring(0, delimiterIndex);
                    string endString       = rangeVariable.Value.Substring(delimiterIndex + delimiterLength);

                    //The sequence will be some specific place within the variable string.
                    //Let's look for a commong prefix and suffix if it exists.
                    //The remaining charcters will be the start and end range integers.
                    string commonPrefix = commonString(startString, endString);
                    string commonSuffix = commonReverseString(startString, endString);
                    if (!String.IsNullOrEmpty(commonPrefix))
                    {
                        startString = startString.Replace(commonPrefix, "");
                        endString   = endString.Replace(commonPrefix, "");
                    }
                    if (!String.IsNullOrEmpty(commonSuffix))
                    {
                        startString = startString.Replace(commonSuffix, "");
                        endString   = endString.Replace(commonSuffix, "");
                    }

                    //try to get the start and end integers.
                    int startValue = 0;
                    int endValue   = 0;
                    if (!String.IsNullOrEmpty(startString))
                    {
                        int value;
                        if (Int32.TryParse(startString, out value))
                        {
                            startValue = value;
                        }
                        else
                        {
                            throw new UserError("The start range is not a number");
                        }
                    }
                    if (!String.IsNullOrEmpty(endString))
                    {
                        int value;
                        if (Int32.TryParse(endString, out value))
                        {
                            endValue = value;
                        }
                        else
                        {
                            throw new UserError("The end range is not a number");
                        }
                    }
                    if (startValue > endValue)
                    {
                        throw new UserError("The begin range is greater than the end");
                    }
                    if (startValue == endValue)
                    {
                        throw new UserError("The begin and end range are the same");
                    }

                    for (int j = startValue; j <= endValue; j++)
                    {
                        rangeVariable.Value = commonPrefix + j.ToString() + commonSuffix;
                        prnstring          += GetPrintVariables(printer, label.Path, label.CSVariables, (quantity < 1));
                        if (quantity > 0)
                        {
                            prnstring += "@LABEL_QUANTITY=" + quantity.ToString() + System.Environment.NewLine;
                            prnstring += "END" + System.Environment.NewLine;
                        }
                    }
                    rangeVariable.Value = originalValue;
                }
                else
                {
                    prnstring += GetPrintVariables(printer, label.Path, label.CSVariables, (quantity < 1));
                    if (quantity > 0)
                    {
                        prnstring += "@LABEL_QUANTITY=" + quantity.ToString() + System.Environment.NewLine;
                        prnstring += "END" + System.Environment.NewLine;
                    }
                }
                //}
            }
            else
            {
                prnstring = GetPrintVariables(printer, label.Path, label.CSVariables, false);
            }

            string     file = sentinelPath + @"\" + sentinelPrefix + "_" + label.Name.Replace(".lab", "").Replace(".LAB", "") + "_" + DateTime.Now.ToString("MMddyyfff") + ".txt";
            FileStream fs   = new FileStream(file, FileMode.CreateNew, FileAccess.Write);

            byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(prnstring);
            fs.Write(byteArray, 0, byteArray.Length);
            fs.Close();

            //Test method. Remove when Milton is done with it. 20180502:GD
            if (printer.ToLower() == "uid4")
            {
                ForkPrintToMTSB(label, quantity);
            }
        }