/// <summary> /// 写入CurrentUser注册表 /// </summary> /// <param name="dirName">数据对应注册表路径</param> /// <param name="keyName">子键名</param> /// <param name="keyValue">写入keyName的键值</param> public static void SetRegeditData(string dirName, string keyName, object keyValue) { using (RegistryKey regKey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true).CreateSubKey(RegeditApplicationKey).CreateSubKey(dirName)) { regKey.SetValue(keyName, keyValue); } MixLogHelper.Info("Program", string.Format("注册表写入: SOFTWARE\\" + RegeditApplicationKey + "\\" + dirName + "({0})", keyValue)); }
private bool InitModuleDatabase() { var appSettings = System.Configuration.ConfigurationManager.AppSettings; if (sqlServer == null) { sqlServer = new SqlServerLogic(string.Format("Server={0};uid={1};pwd={2};", appSettings["DatabaseServerIP"], appSettings["DatabaseUser"], appSettings["DatabasePwd"])); } int createData = sqlServer.FromSql("CREATE DATABASE volador"); MixLogHelper.Info(ClassName, createData != -100 ? "volador数据库创建成功" : "volador数据库创建失败"); bool success = sqlServer.ExecuteCommand(sqlServer.GetSqlFile(Path.Combine(Application.StartupPath, "sqlinit"), "volador")); MixLogHelper.Info(ClassName, success ? "volador表创建成功" : "volador表创建失败"); return(success); }
/// <summary> /// 检查模块配置信息是否存在 /// </summary> private void CheckModuleConfig() { try { if (!TModuleLogic.IsTableExist("moduleinfo")) { MixLogHelper.Info(ClassName, "创建数据表moduleinfo"); DB.Context.FromSql("CREATE TABLE 'moduleinfo' (" + "'id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + "'name' TEXT NOT NULL," + "'path' TEXT NOT NULL," + "'autostart' INTEGER NOT NULL," + "'delay' INTEGER NOT NULL," + "'state' INTEGER NOT NULL," + "'startindex' INTEGER NOT NULL," + "'arguments' TEXT," + "'temtype' INTEGER NOT NULL" + ")").ExecuteNonQuery(); MixLogHelper.Info(ClassName, "moduleinfo创建成功"); } else if (!TModuleLogic.VerifyField().IsSuccess) { DB.Context.FromSql("DROP TABLE moduleinfo").ExecuteNonQuery(); DB.Context.FromSql("CREATE TABLE 'moduleinfo' (" + "'id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + "'name' TEXT NOT NULL," + "'path' TEXT NOT NULL," + "'autostart' INTEGER NOT NULL," + "'delay' INTEGER NOT NULL," + "'state' INTEGER NOT NULL," + "'startindex' INTEGER NOT NULL," + "'arguments' TEXT," + "'temtype' INTEGER NOT NULL" + ")").ExecuteNonQuery(); } } catch (Exception e) { MixLogHelper.Error(ClassName, "创建数据表异常", e.StackTrace); } Label lblOverInfo = new Label(); try { if (flag)//设置模式 { return; } if (Convert.ToInt32(Program.GetRegeditData(Program.RegeditDirKey, "FirstStart")) == 0) { FormDataBaseConfig form = new FormDataBaseConfig(); DialogResult result = form.ShowDialog(); if (result == DialogResult.OK) { lblOverInfo.Text = "初次启动正在初始化数据,请稍候。。。"; lblOverInfo.BringToFront(); Controls.Add(lblOverInfo); //开始初始化模块配置和数据库信息 bool success = InitModuleDatabase(); // if (!success) MessageBox.Show("数据库创建失败", "提示"); 不需要提示 if (success) { Program.SetRegeditData(Program.RegeditDirKey, "FirstStart", 1); } } else { Close(); } } } catch (Exception e) { MixLogHelper.Error(ClassName, "数据库初始化异常", e.StackTrace); MessageBox.Show(this, "数据初始化异常,请联系管理人员", "提示"); } finally { if (Controls.Contains(lblOverInfo)) { Controls.Remove(lblOverInfo); } } }