示例#1
0
        public static List <PrinterAndBoxSingleIndex> GetCustomersSelectedPrinterAndBox()
        {
            List <PrinterAndBoxSingleIndex> list = new List <PrinterAndBoxSingleIndex>();
            var AppSettings = System.Configuration.ConfigurationManager.AppSettings;

            for (int i = 0; i < AppSettings.Count; i++)
            {
                if (AppSettings.AllKeys[i].Contains("PrinterName"))
                {
                    PrinterAndBoxSingleIndex index = new PrinterAndBoxSingleIndex();
                    index.CustomerName = AppSettings.AllKeys[i].Replace("PrinterName", "");
                    var value = AppSettings.GetValues(i)[0];
                    if (Regex.IsMatch(value, "\\S+\\[[\\s\\S]*\\]"))
                    {
                        index.PrinterName = value.Substring(0, value.LastIndexOf('['));

                        index.BoxName = value.Substring(value.LastIndexOf('[') + 1, value.LastIndexOf(']') - value.LastIndexOf('[') - 1);
                    }
                    else
                    {
                        index.PrinterName = value;
                        index.BoxName     = null;
                    }
                    list.Add(index);
                }
            }
            return(list);
        }
示例#2
0
        /// <summary>
        /// 修改打印机设置
        /// </summary>
        /// <param name="wcfPrinterSettings"></param>
        /// <returns></returns>
        public string EditPrinterSettingInfo(WcfPrinterSettings wcfPrinterSettings)
        {
            var AppSettings = System.Configuration.ConfigurationManager.AppSettings;

            for (int i = 0; i < AppSettings.Count; i++)
            {
                if (AppSettings.AllKeys[i].Contains("PrinterName"))
                {
                    PrinterAndBoxSingleIndex index = new PrinterAndBoxSingleIndex();
                    index.CustomerName = AppSettings.AllKeys[i].Replace("PrinterName", "");
                    for (int j = 0; j < wcfPrinterSettings.CustomersSelectedPrinterAndBox.Count; j++)
                    {
                        if (wcfPrinterSettings.CustomersSelectedPrinterAndBox[j].CustomerName == index.CustomerName)
                        {
                            string value = wcfPrinterSettings.CustomersSelectedPrinterAndBox[j].PrinterName + "[" + wcfPrinterSettings.CustomersSelectedPrinterAndBox[j].BoxName + "]";

                            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                            if (config.AppSettings.Settings[AppSettings.AllKeys[i]] != null)
                            {
                                config.AppSettings.Settings[AppSettings.AllKeys[i]].Value = value;
                            }
                            else
                            {
                                config.AppSettings.Settings.Add(AppSettings.AllKeys[i], value);
                            }
                            config.Save(ConfigurationSaveMode.Modified);
                            ConfigurationManager.RefreshSection("appSettings");
                        }
                    }
                }
            }
            return("OK");
        }