예제 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            getSet(tcDemo);
            int index = 0;

            int.TryParse(WRSetting.Set().getSettings("ActivePage", "0"), out index);
            tcDemo.SelectTab(index);
        }
예제 #2
0
 protected LogLocal()
 {
     logPath = WRSetting.Set().getSettings("LogPath");
     if ("".Equals(logPath))
     {
         logPath = SystemUtil.CurrentDirectory() + @"Log";  //默认文件夹
     }
     if (!Directory.Exists(logPath))
     {
         Directory.CreateDirectory(logPath); //不存在则创建文件夹
     }
 }
예제 #3
0
 private void setSet(Control control)
 {
     foreach (Control ctl in control.Controls)
     {
         if (ctl is TextBox)
         {
             WRSetting.Set().setSettings(ctl.Name, (ctl as TextBox).Text);
         }
         if (ctl is RadioButton)
         {
             WRSetting.Set().setSettings(ctl.Name, (ctl as RadioButton).Checked ? "true" : "false");
         }
         if (ctl is CheckBox)
         {
             WRSetting.Set().setSettings(ctl.Name, (ctl as CheckBox).Checked ? "true" : "false");
         }
         setSet(ctl);
     }
 }
예제 #4
0
 private void getSet(Control control)
 {
     foreach (Control ctl in control.Controls)
     {
         if (ctl is TextBox)
         {
             (ctl as TextBox).Text = WRSetting.Set().getSettings(ctl.Name);
         }
         if (ctl is RadioButton)
         {
             (ctl as RadioButton).Checked = WRSetting.Set().getSettings(ctl.Name).Equals("true");
         }
         if (ctl is CheckBox)
         {
             (ctl as CheckBox).Checked = WRSetting.Set().getSettings(ctl.Name).Equals("true");
         }
         getSet(ctl);
     }
 }
예제 #5
0
        private DataCfg(string suffix)
        {
            string linkType = WRSetting.Set().getSettings(Const.LinkType + suffix);

            if ("1".Equals(linkType))
            {
                dlt = DataLinkType.dltODBC;
            }
            else if ("2".Equals(linkType))
            {
                dlt = DataLinkType.dltSocket;
            }
            else if ("3".Equals(linkType))
            {
                dlt = DataLinkType.dltWeb;
            }
            else
            {
                dlt = DataLinkType.dltNone;
            }

            switch (dlt)
            {
            case DataLinkType.dltODBC:
                string dbtype   = WRSetting.Set().getSettings(Const.ODBC + suffix + "/" + Const.DBType).ToLower();
                string ip       = WRSetting.Set().getSettings(Const.ODBC + suffix + "/" + Const.DBIP);
                string port     = WRSetting.Set().getSettings(Const.ODBC + suffix + "/" + Const.DBPort);
                string dbase    = WRSetting.Set().getSettings(Const.ODBC + suffix + "/" + Const.DBase);
                string user     = WRSetting.Set().getSettings(Const.ODBC + suffix + "/" + Const.DBUserName);
                string password = WRSetting.Set().getSettings(Const.ODBC + suffix + "/" + Const.DBUserPass);
                string ver      = WRSetting.Set().getSettings(Const.ODBC + suffix + "/" + Const.DBVer);
                string dbfile   = WRSetting.Set().getSettings(Const.ODBC + suffix + "/" + Const.DBFile).ToLower();
                password = CryptUtil.DecryptDES(password);       //密码采用DES加密算法存储在配置文件中,所以此处应该解密
                if (Const.oracle.Equals(dbtype))
                {
                    dbt = DataBaseType.dbtOracle;
                }
                else if (Const.mssql.Equals(dbtype))
                {
                    dbt = DataBaseType.dbtMSSQL;
                }
                else if (Const.mysql.Equals(dbtype))
                {
                    dbt = DataBaseType.dbtMySQL;
                }
                else if (Const.access.Equals(dbtype))
                {
                    dbt = DataBaseType.dbtAccess;
                }
                else if (Const.sqlite.Equals(dbtype))
                {
                    dbt = DataBaseType.dbtSQLite;
                }
                else if (Const.dbase.Equals(dbtype))
                {
                    dbt = DataBaseType.dbtDBase;
                }
                else
                {
                    dbt = DataBaseType.dbtNone;
                }

                dbService = new DataODBCService();

                switch (dbt)
                {
                case DataBaseType.dbtOracle:
                    (dbService as DataODBCService).db = new Oracle(ip, port, dbase, user, password, ver);
                    break;

                case DataBaseType.dbtMSSQL:
                    (dbService as DataODBCService).db = new SqlServer(ip, port, dbase, user, password, ver);
                    break;

                case DataBaseType.dbtMySQL:
                    (dbService as DataODBCService).db = new MySql(ip, port, dbase, user, password, ver);
                    break;

                case DataBaseType.dbtAccess:
                    (dbService as DataODBCService).db = new Access(dbfile, password);
                    break;

                case DataBaseType.dbtSQLite:
                    (dbService as DataODBCService).db = new SQLite(dbfile, password);
                    break;

                case DataBaseType.dbtDBase:
                    (dbService as DataODBCService).db = new DBase(dbfile, password);
                    break;

                default:
                    throw new Exception("没有设置数据库类型!");
                }
                break;

            case DataLinkType.dltSocket:
                string socketIP     = WRSetting.Set().getSettings(Const.Socket + suffix + "/" + Const.SocketIP).ToLower();
                string socketPort   = WRSetting.Set().getSettings(Const.Socket + suffix + "/" + Const.SocketPort).ToLower();
                string socketServer = WRSetting.Set().getSettings(Const.Socket + suffix + "/" + Const.SocketServer).ToLower();
                break;

            case DataLinkType.dltWeb:
                string url = WRSetting.Set().getSettings(Const.WebService + suffix + "/" + Const.WSURL).ToLower();
                break;

            default:
                throw new Exception("没有设置连接数据库方式!");
            }
        }
예제 #6
0
        protected override bool DoSaveLog(LogEntity logEntity)
        {
            try
            {
                //读取配置文件固定位置的日志级别
                string logLevel = WRSetting.Set().getSettings("LogLevel");
                if (logLevel.Equals(""))
                {
                    logLevel = LogLevel.ERROR;
                }

                foreach (string level in logEntity.Levels)
                {
                    if (!LogLevel.needLog(level, logLevel))
                    {
                        continue;
                    }

                    string logfile = string.Format(@"{0}\{1}", logPath, level);
                    if (!Directory.Exists(logfile))
                    {
                        Directory.CreateDirectory(logfile); //不存在则创建文件夹
                    }

                    logfile = string.Format(@"{0}\{1}.log", logfile, DateTime.Now.ToString("yyyyMMdd"));

                    FileStream fs;
                    if (File.Exists(logfile))
                    {
                        fs = new FileStream(logfile, FileMode.Append, FileAccess.Write, FileShare.ReadWrite, 8, FileOptions.Asynchronous);
                    }
                    else
                    {
                        fs = new FileStream(logfile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite, 8, FileOptions.Asynchronous);
                    }

                    Byte[] dataArray = Encoding.Default.GetBytes(logEntity.Content.Message + Environment.NewLine);
                    bool   flag      = true;
                    long   slen      = dataArray.Length;
                    long   len       = 0;
                    while (flag)
                    {
                        try
                        {
                            if (len >= fs.Length)
                            {
                                fs.Lock(len, slen);
                                lockDic[len] = slen;
                                flag         = false;
                            }
                            else
                            {
                                len = fs.Length;
                            }
                        }
                        catch
                        {
                            while (!lockDic.ContainsKey(len))
                            {
                                len += lockDic[len];
                            }
                        }
                    }
                    fs.Seek(len, SeekOrigin.Begin);
                    fs.Write(dataArray, 0, dataArray.Length);
                    fs.Close();
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
예제 #7
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     setSet(tcDemo);
     WRSetting.Set().setSettings("ActivePage", tcDemo.SelectedIndex.ToString());
 }