Esempio n. 1
0
        private void addXmlFileData(string strFileName)
        {
            //主要添加两个方向,一个是往选择框里添加,一个是往xmlapp文件中添加。
            clsKeyValue keyvalue = new clsKeyValue(Path.GetFileNameWithoutExtension(strFileName), strFileName);
            comboBoxBarcodeModel.Items.Add(keyvalue);
            comboBoxBarcodeModel.SelectedItem = keyvalue;

            /**如下的也注释掉了。改为序列化。

            //保存早xmlapp文件中。
            //因为会有文件异常,所以

            XmlDocument xmlDocApp = new XmlDocument();
            xmlDocApp.Load(Application.StartupPath + "\\xmlAPP.xml");
            XmlNode myxmlNode = xmlDocApp.SelectNodes("root").Item(0);

            XmlElement xmlEleFileName = xmlDocApp.CreateElement("xmlBarcodeModel");
            XmlAttribute xmlAttributeFileName = xmlDocApp.CreateAttribute("Path");
            xmlAttributeFileName.Value = strFileName;

            xmlEleFileName.Attributes.Append(xmlAttributeFileName);
            myxmlNode.AppendChild(xmlEleFileName);
            xmlDocApp.Save(Application.StartupPath + "\\xmlAPP.xml");
             * */

            if (myClsXmlApp == null)
                myClsXmlApp = new ClsXmlApp();

            myClsXmlApp.addBarcodeModel(strFileName);

            saveXmlApp();

            //同时更新画布。
            dataGridViewChangedCell();
        }
Esempio n. 2
0
        private void btnSelectPrinter_Click(object sender, EventArgs e)
        {
            //这个是选择打印机
            //我自制力一个对话框来选择打印机,并且自动取得分辨率.

            FrmSelectPrinter f = new FrmSelectPrinter();
            if (f.ShowDialog() == DialogResult.OK)
            {
                if (myClsXmlApp == null)
                    myClsXmlApp = new ClsXmlApp();

                //这里要保存的
                myClsXmlApp.strPrintingName = f.strPrinterName;

                lblPrinterName.Text = f.strPrinterName;

                //设置到
                ClsBarcodePrint.strPrinterName = f.strPrinterName;

                saveXmlApp();//保存

            }
        }
Esempio n. 3
0
        //
        /// <summary>
        /// 加载程序配置,包括打印机名字,是否倒着打印,以及模板的路径
        /// </summary>
        private void loadXmlAPP()
        {
            #region 如下的我打算用序列化来实现
            /**
            if (!File.Exists(Application.StartupPath + "\\xmlAPP.xml"))
            {
                createXmlApp();

            }
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(Application.StartupPath + "\\xmlAPP.xml");
            XmlElement xmlEle = xmlDoc.DocumentElement;
            foreach (XmlElement myxmlNode in xmlEle.ChildNodes)
            {
                string strNodeName = myxmlNode.Name;
                switch (strNodeName)
                {
                    case "printer":

                        //clsBarcodePrint.fltDPIX = clsBarcodePrint.strAttributeValueToFloat(myxmlNode, "DPIX");
                        //clsBarcodePrint.fltDPIY = clsBarcodePrint.strAttributeValueToFloat(myxmlNode, "DPIY");
                        //读取打印机的时候,得判断是否为空,如果为空就设置为默认打印机
                        string strPrintName_ = myxmlNode.GetAttribute("PrinterName");

                        if (strPrintName_ == "")
                        {
                            PrintDocument printDoc = new PrintDocument();
                            ClsBarcodePrint.strPrinterName = printDoc.PrinterSettings.PrinterName;
                        }
                        else
                        {
                            ClsBarcodePrint.strPrinterName = strPrintName_;

                        }
                        lblPrinterName.Text = ClsBarcodePrint.strPrinterName;

                        break;

                    case "xmlBarcodeModel"://条形码模板

                        string strPath = myxmlNode.Attributes["Path"].InnerText;//路径

                        //还得判断这个路径是否是相对路径

                        if (strPath.IndexOf(":") < 0)
                        strPath = Application.StartupPath + "\\" + strPath;

                        //去掉了没有的
                        if (File.Exists(strPath))
                        {
                            clsKeyValue lt = new clsKeyValue(Path.GetFileNameWithoutExtension(strPath), strPath);
                            comboBoxBarcodeModel.Items.Add(lt);
                        }
                        break;
                }
            }

             * */
            #endregion

            //如下是用序列化实现的,如果存在文件就反序列化
            if (File.Exists(Application.StartupPath + "\\xmlAPP.xml"))
            {
                try
                {
                    using (Stream stream = new FileStream(Application.StartupPath + "\\xmlAPP.xml", FileMode.Open, FileAccess.Read, FileShare.Read))
                    {

                        XmlSerializer formatter = new XmlSerializer(typeof(ClsXmlApp));

                        myClsXmlApp = formatter.Deserialize(stream) as ClsXmlApp;

                    }

                }
                catch (Exception exception)
                {
                    ClsErrorFile.WriteLine("加载不成功,原因是" , exception);
                    //MessageBox.Show("加载不成功,原因是" + exception.Message);
                }
                finally
                {

                }
            }

            //如下就是添加了。

            if (myClsXmlApp != null)
            {
                PrintDocument printdoc = new PrintDocument();

                //如果没有设置打印机就设置使用默认的打印机
                if (myClsXmlApp.strPrintingName == null)
                {
                    myClsXmlApp.strPrintingName = printdoc.PrinterSettings.PrinterName;

                }

                //显示选择的打印机,通常是用户选择要使用的,
                lblPrinterName.Text = myClsXmlApp.strPrintingName;

                //这个类也使用这个打印机配置
                //如果没有设置打印机,就设置默认的打印机

                ClsBarcodePrint.strPrinterName = myClsXmlApp.strPrintingName;

                foreach (string  strPath in myClsXmlApp.arrlistBarcodeModel)
                {
                    //去掉了没有的
                    if (File.Exists(strPath))
                    {
                        clsKeyValue lt = new clsKeyValue(Path.GetFileNameWithoutExtension(strPath), strPath);
                        comboBoxBarcodeModel.Items.Add(lt);
                    }

                }

                //如果有模板,就设置第一个
                if (comboBoxBarcodeModel.Items.Count > 0)
                {
                    comboBoxBarcodeModel.Text = comboBoxBarcodeModel.Items[0].ToString();
                    //MessageBox.Show(comboBoxBarcodeModel.Items[0].ToString());
                }
            }
        }