Ejemplo n.º 1
0
 /// <summary>
 /// Method add variable
 /// </summary>
 /// <param name="csVar"></param>
 public virtual void AddVariable(CodeSoftDTO.Variable csVar)
 {
     if (!this.CSVariables.Exists(v => v.Name == csVar.Name) &&
         !csVar.Name.ToLower().Contains("d_"))
     {
         this.CSVariables.Add(csVar);
     }
 }
Ejemplo n.º 2
0
        public static void CheckNumberRange(List <CodeSoftDTO.Variable> variables)
        {
            bool hasSerialNumberRange = variables.Exists(p => p.Value.Contains(Constants.Delimiter_SequencedNumberRange));

            if (hasSerialNumberRange)
            {
                int count = variables.Where(p => p.Value.Contains(Constants.Delimiter_SequencedNumberRange)).Count();
                if (count > 1)
                {
                    throw new UserError("More than 1 variables are using a range of values. Ranges can only be used once per label!");
                }
                CodeSoftDTO.Variable rangeVariable = variables.Where(p => p.Value.Contains(Constants.Delimiter_SequencedNumberRange)).First();
                int    delimiterIndex  = rangeVariable.Value.IndexOf(Constants.Delimiter_SequencedNumberRange);
                int    delimiterLength = Constants.Delimiter_SequencedNumberRange.Length;
                string start           = rangeVariable.Value.Substring(0, delimiterIndex);
                string end             = rangeVariable.Value.Substring(delimiterIndex + delimiterLength);

                decimal decCheck;
                var     startNumberCheck = decimal.TryParse(start, out decCheck);
                var     endNumberCheck   = decimal.TryParse(end, out decCheck);
                if (!startNumberCheck)
                {
                    //throw new UserError("Variable \"" + rangeVariable.Name + "\" has a range where the beginning is not a number!");
                }
                else if (!endNumberCheck)
                {
                    //throw new UserError("Variable \"" + rangeVariable.Name + "\" has a range where the end is not a number!");
                }

                int  startValue;
                int  endValue;
                bool startIntCheck = int.TryParse(start, out startValue);
                bool endIntCheck   = int.TryParse(end, out endValue);
                if (!startIntCheck)
                {
                    //throw new UserError("Variable \"" + rangeVariable.Name + "\"  has a begin number that is too large!");
                }
                else if (!endIntCheck)
                {
                    //throw new UserError("Variable \"" + rangeVariable.Name + "\"  has an end number that is too large!");
                }

                if (startValue > endValue)
                {
                    //throw new UserError("Variable \"" + rangeVariable.Name + "\" has a beginning that is greater than the end!");
                }
                else if ((endValue - startValue) > Constants.MaxRangeSpan)
                {
                    //throw new UserError("Variable \"" + rangeVariable.Name + "\" has a range which spans greater than " + Constants.MaxRangeSpan.ToString() + ".");
                }
            }
        }
Ejemplo n.º 3
0
        private static string GetPrintVariables(string printer, string label, List <CodeSoftDTO.Variable> variables, CodeSoftDTO.Variable permutationVar, bool appendEnd)
        {
            string prnstring = @"LABELNAME = " + label + System.Environment.NewLine;

            prnstring = prnstring + "PRINTER = " + printer + System.Environment.NewLine;
            foreach (CodeSoftDTO.Variable variable in variables)
            {
                prnstring = prnstring + variable.Name + " = " + variable.Value + System.Environment.NewLine;
                if (variable.Name.ToLower() == permutationVar.Value.ToLower())
                {
                    prnstring = prnstring + variable.Name + " = " + permutationVar.Value + System.Environment.NewLine;
                }
            }
            if (appendEnd)
            {
                prnstring = prnstring + "END" + System.Environment.NewLine + System.Environment.NewLine;
            }
            return(prnstring);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method to permutate collections of variables.
        /// </summary>
        /// <param name="printer"></param>
        /// <param name="label"></param>
        /// <param name="variables"></param>
        /// <param name="permutationVar"></param>
        private static void PrintVariables(string printer, string label, List <CodeSoftDTO.Variable> variables, CodeSoftDTO.Variable permutationVar)
        {
            string sentinelPath   = @"\\netapp\labels\Sentinel\Print_app\INPUT";
            string sentinelPrefix = "PA";
            string prnstring      = @"LABELNAME = " + label + System.Environment.NewLine;

            prnstring = prnstring + "PRINTER = " + printer + System.Environment.NewLine;
            foreach (CodeSoftDTO.Variable variable in variables)
            {
                prnstring = prnstring + variable.Name + " = " + variable.Value + System.Environment.NewLine;
                if (variable.Name.ToLower() == permutationVar.Value.ToLower())
                {
                    prnstring = prnstring + variable.Name + " = " + permutationVar.Value + System.Environment.NewLine;
                }
            }
            string     file = sentinelPath + @"\" + sentinelPrefix + "_" + label.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();
        }
Ejemplo n.º 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);
            }
        }