Beispiel #1
0
        private Dictionary <string, string> cartonToDic(Carton carton, List <MandUnionFieldType> mandUnionFieldTypeList)
        {
            PropertyInfo[] propertyInfoARR       = carton.GetType().GetProperties();
            Dictionary <string, string> property = new Dictionary <string, string>();

            foreach (PropertyInfo propertyInfo in propertyInfoARR)
            {
                Object propertyVal = carton.GetType().GetProperty(propertyInfo.Name).GetValue(carton, null);
                if (propertyVal != null)
                {
                    property.Add(propertyInfo.Name.ToUpper(), propertyVal.ToString());
                }
            }

            Dictionary <string, string> cartonDict = new Dictionary <string, string>();

            foreach (MandUnionFieldType mandUnionFieldType in mandUnionFieldTypeList)
            {
                string fieldName = mandUnionFieldType.FieldName.ToUpper();
                if (property.ContainsKey(fieldName))
                {
                    cartonDict.Add(fieldName, property[fieldName]);
                }
                else
                {
                    cartonDict.Add(fieldName, mandUnionFieldType.FieldValue);
                }
            }

            return(cartonDict);
        }
Beispiel #2
0
        private List <Dictionary <string, string> > cartonListToArray(Carton carton, List <MandUnionFieldType> mandUnionFieldTypeList, int printNum)
        {
            List <Dictionary <string, string> > cartonList = new List <Dictionary <string, string> >();

            PropertyInfo[] propertyInfoARR       = carton.GetType().GetProperties();
            Dictionary <string, string> property = new Dictionary <string, string>();

            foreach (PropertyInfo propertyInfo in propertyInfoARR)
            {
                Object propertyVal = carton.GetType().GetProperty(propertyInfo.Name).GetValue(carton, null);
                if (propertyVal != null)
                {
                    property.Add(propertyInfo.Name.ToUpper(), propertyVal.ToString());
                }
            }
            for (int i = 0; i < printNum; i++)
            {
                Dictionary <string, string> cartonDict = new Dictionary <string, string>();
                foreach (MandUnionFieldType mandUnionFieldType in mandUnionFieldTypeList)
                {
                    string fieldName = mandUnionFieldType.FieldName.ToUpper();
                    if (property.ContainsKey(fieldName))
                    {
                        cartonDict.Add(fieldName, property[fieldName]);
                    }
                    else
                    {
                        cartonDict.Add(fieldName, mandUnionFieldType.FieldValue);
                    }
                }
                cartonList.Add(cartonDict);
            }
            return(cartonList);
        }
Beispiel #3
0
        /// <summary>
        /// TODO 打印装箱单
        /// </summary>
        /// <param name="templateFileName"></param>
        /// <param name="carton"></param>
        /// <param name="mandUnionFieldTypeList"></param>
        /// <param name="printerName"></param>
        /// <returns></returns>
        public bool printCatonByModel(string templateFileName, Carton carton, List <MandUnionFieldType> mandUnionFieldTypeList)
        {
            if (lbl == null)
            {
                lbl = new ApplicationClass();
            }
            //未加載模板文件或者模板發生變更時,重新加載新的模板
            if (lbl.Documents.Count == 0 || templateFileName.IndexOf(lbl.ActiveDocument.Name) == -1)
            {
                lbl.Documents.Open(templateFileName, false);// 调用设计好的label文件
            }
            Document doc = lbl.ActiveDocument;

            try
            {
                for (int i = 1; i <= doc.Variables.FormVariables.Count; i++)
                {
                    string variableName = doc.Variables.FormVariables.Item(i).Name.ToString();
                    foreach (MandUnionFieldType mandUnionFieldType in mandUnionFieldTypeList)
                    {
                        if (mandUnionFieldType.FieldName.ToUpper() == variableName.ToUpper())
                        {
                            bool           judge           = false;
                            PropertyInfo[] propertyInfoARR = carton.GetType().GetProperties();
                            foreach (PropertyInfo propertyInfo in propertyInfoARR)
                            {
                                if (propertyInfo.Name.ToUpper() == mandUnionFieldType.FieldName.ToUpper())
                                {
                                    string entityValue = carton.GetType().GetProperty(propertyInfo.Name).GetValue(carton, null).ToString();
                                    doc.Variables.FormVariables.Item(i).Value = entityValue;
                                    judge = true;
                                    break;
                                }
                            }
                            if (!judge)
                            {
                                doc.Variables.FormVariables.Item(i).Value = mandUnionFieldType.FieldValue;
                            }
                        }
                    }
                }

                int Num = 1;                      //打印数量
                doc.Printer.SwitchTo(DefaultPrinter());
                //doc.Printer.SwitchTo(printerName);  //設置打印機
                doc.PrintLabel(1, 1, 1, Num, 1, "");
                doc.FormFeed();
                //doc.PrintDocument(Num);           //打印
            }
            catch (Exception ex)
            {
                return(false);                          //返回,後面代碼不執行
            }
            finally
            {
                //內存釋放和回收
                lbl.Documents.CloseAll();
                lbl.Quit();
                lbl = null;
                doc = null;
                GC.Collect(0);
            }
            return(true);
        }