예제 #1
0
        public bool Print(string fileName, Dictionary <string, string> fldValues)
        {
            FileInfo fileInfo;

            try
            {
                fileInfo = fileBuffer[fileName];
            }
            catch (KeyNotFoundException)
            {
                fileInfo = BuildFileInfo(fileName);
                if (fileInfo == null)
                {
                    return(false);
                }
                else
                {
                    fileBuffer.Add(fileName, fileInfo);
                }
            }

            string s = string.Copy(fileInfo.contents);

            foreach (string sym in fileInfo.symbols)
            {
                try {
                    var val = fldValues[sym].ToString();
                    s = s.Replace(sym, val);
                }
                catch (KeyNotFoundException)
                {
                    MessageLogger.Add("Unknown symbol in label file: " + sym, MessageLogger.MsgLevel.warning);
                    s = s.Replace(sym, "??");
                }
            }
            return(RawPrinterHelper.SendStringToPrinter(settings.printerName, s));
        }
예제 #2
0
        public static bool Add(string msg)
        {
            DBOperations.OpenDBConnection();
            DBOperations.BeginTransaction();

            try
            {
                var cmd = DBOperations.myConn.CreateCommand();
                cmd.CommandText = "INSERT INTO pck.log (msg) VALUES (@msg)";

                cmd.Parameters.AddWithValue("@msg", msg);

                cmd.ExecuteNonQuery();
                DBOperations.CommitTransaction();
            }
            catch (MySqlException ex)
            {
                DBOperations.RollbackTransaction();
                MessageLogger.Add("Error inserting record into PCK.LOG - see log for details", MessageLogger.MsgLevel.error);
                MessageLogger.Add(ex.ToString(), MessageLogger.MsgLevel.additional);
                return(false);
            }
            return(true);
        }
예제 #3
0
        static public object ReadConfig(Type type)
        {
            // Just some boiler plate deserialisation code...
            var settings = Activator.CreateInstance(type);

            System.IO.FileStream fs = null;

            try
            {
                // Create an instance of the XmlSerializer class; specify the type of object to be deserialized.
                XmlSerializer serializer = new XmlSerializer(type);

                /* If the XML document has been altered with unknown nodes or attributes, handle them with the
                 * UnknownNode and UnknownAttribute events.*/
                serializer.UnknownNode      += new XmlNodeEventHandler(serializer_UnknownNode);
                serializer.UnknownAttribute += new XmlAttributeEventHandler(serializer_UnknownAttribute);

                // A FileStream is needed to read the XML document.
                fs = new System.IO.FileStream(type.Name + ".xml", System.IO.FileMode.Open);

                /* Use the Deserialize method to restore the object's state withdata from the XML document. */
                settings = serializer.Deserialize(fs);
            }
            catch (Exception exp)
            {
                if (fs != null)
                {
                    fs.Close();
                }
                MessageLogger.Add(exp.ToString(), MessageLogger.MsgLevel.error);
                return(null);
            }
            fs.Close();

            return(settings);
        }
예제 #4
0
 static private void serializer_UnknownAttribute
     (object sender, System.Xml.Serialization.XmlAttributeEventArgs e)
 {
     System.Xml.XmlAttribute attr = e.Attr;
     MessageLogger.Add("Error in xml settings file - unknown attribute " + attr.Name + "='" + attr.Value + "'", MessageLogger.MsgLevel.error);
 }
예제 #5
0
 static private void serializer_UnknownNode
     (object sender, System.Xml.Serialization.XmlNodeEventArgs e)
 {
     MessageLogger.Add(string.Format("Error in xml settings file - unknown Node: {0} \t {1}", e.Name, e.Text), MessageLogger.MsgLevel.error);
 }