private void EditModule() { try { if (dgvMix.SelectedRows.Count > 0) { FormModule form = new FormModule(this, 1, moduleList[dgvMix.SelectedRows[0].Index]); if (form.ShowDialog() == DialogResult.OK) { TModuleLogic.UpdateModule(form.NewModule); //sql.UpdateModule(moduleList[dgvMix.SelectedRows[0].Index].id, form.NewModule); moduleList[dgvMix.SelectedRows[0].Index] = form.NewModule; lblError.Visible = false; dgvMix.InvalidateRow(dgvMix.SelectedRows[0].Index); form.Dispose(); } } else { ShowToolTip("未选中模块", 2000); } } catch { } }
private void FormMain_FormClosing(object sender, FormClosingEventArgs e) { if (processDic.Count != 0) { DialogResult result = MessageBox.Show(this, "是否关闭所有模块", "提示", MessageBoxButtons.YesNoCancel); if (result == DialogResult.Cancel) { e.Cancel = true; } else { if (result == DialogResult.Yes) { StopAllModule(); } } } if (!e.Cancel) { foreach (var m in moduleList) { TModuleLogic.UpdateModule(m.id, new Dos.ORM.Field[] { TModule._.state, TModule._.startindex }, new object[] { -1, m.autostart != 0 ? m.startindex : 0 }); //sql.UpdateModuleState(m.id); } } autoCheckModuleStateFlag = e.Cancel; }
private void AddModule() { try { FormModule formModule = new FormModule(this, 2); DialogResult result = formModule.ShowDialog(); if (result == DialogResult.OK && formModule.NewModule != null) { FormModuleConfig formConfig = new FormModuleConfig(this, formModule.NewModule); DialogResult resultConfig = formConfig.ShowDialog(); var insertResult = TModuleLogic.InsertModule(formModule.NewModule); if (insertResult.IsSuccess) { var qureyResult = TModuleLogic.QureyModule(formModule.NewModule); if (qureyResult.IsSuccess) { formModule.NewModule.id = (qureyResult.Data as List <TModule>)[0].id; } moduleList.Add(formModule.NewModule); if (resultConfig == DialogResult.OK) { ShowToolTip("添加成功,配置成功", 3000); } else if (result == DialogResult.Ignore) { ShowToolTip("添加成功,配置文件不存在或有异常", 3000); } else { ShowToolTip("添加成功,配置已取消 ", 3000); } } else { ShowToolTip("添加失败", 3000); } //sql.InsertModule(formModule.NewModule); //var ds = sql.FromSqlForReader(string.Format("select id from moduleinfo where name='{0}' and path='{1}' and autostart={2} and delay={3} and startindex={4} and arguments='{5}'", // formModule.NewModule.name, formModule.NewModule.path, formModule.NewModule.autostart, // formModule.NewModule.delay, formModule.NewModule.startindex, formModule.NewModule.arguments)); //formModule.NewModule.id = Convert.ToInt32(ds.Tables[0].Rows[0]["id"]); } formModule.Dispose(); } catch (Exception e) { MixLogHelper.Error(ClassName, "添加模块信息异常", e.StackTrace); } }
/// <summary> /// 添加新模块 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnYes_Click(object sender, EventArgs e) { try { btnYes.Enabled = false; if (dgvMix.SelectedRows.Count > 0) { if (!string.IsNullOrWhiteSpace(textBoxLocation.Text) && !string.IsNullOrWhiteSpace(textBoxName.Text)) { int rowIndex = dgvMix.SelectedRows[0].Index; moduleList[rowIndex].path = textBoxLocation.Text.Trim(); moduleList[rowIndex].name = textBoxName.Text.Trim(); moduleList[rowIndex].autostart = checkBoxAutoStart.Checked ? 1 : 0; if (!checkBoxAutoStart.Checked) { moduleList[rowIndex].startindex = 0; } else { moduleList[rowIndex].startindex = moduleList[rowIndex].startindex == 0 ? 1 : moduleList[rowIndex].startindex; } moduleList[rowIndex].delay = string.IsNullOrWhiteSpace(textBoxDelay.Text) ? 0 : int.Parse(textBoxDelay.Text.Trim()); moduleList[rowIndex].arguments = textBoxArguments.Text.Trim() ?? null; //sql.UpdateModule(moduleList[rowIndex].id, moduleList[rowIndex]); TModuleLogic.UpdateModule(moduleList[rowIndex]); dgvMix.InvalidateRow(rowIndex); lblError.Visible = false; ShowToolTip("模块更新成功", 2000); } else { lblError.Text = "模块名称、地址不能为空"; lblError.Visible = true; } } else { ShowToolTip("未选中模块", 2000); } } catch (Exception ex) { MixLogHelper.Error(ClassName, "增加模块异常", ex.StackTrace); } finally { btnYes.Enabled = true; } }
private void DelModule() { try { if (dgvMix.SelectedRows.Count > 0) { TModule module = moduleList[dgvMix.SelectedRows[0].Index]; DialogResult result = MessageBox.Show(this, "确定要删除该模块:" + module.name + "?", "温馨提示", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { var databaseResult = TModuleLogic.DeletModule(module.id); if (databaseResult.IsSuccess) { ShowToolTip("删除成功", 2000); } else { ShowToolTip("删除失败", 2000); } if (processDic.ContainsKey(module.id)) { StopModule(module); } moduleList.RemoveAt(dgvMix.SelectedRows[0].Index); lblError.Visible = false; } } else { ShowToolTip("未选中模块", 2000); //MessageBox.Show("未选中模块"); } } catch (Exception e) { MixLogHelper.Error(ClassName, "删除模块异常", e.StackTrace); } }
private void AutoStartConfig() { try { FormStartIndex formindex = new FormStartIndex(this, moduleList); if (formindex.ShowDialog() == DialogResult.OK) { var index = formindex.GetStartIndex(); for (int i = index.Count - 1; i >= 0; i--) { moduleList.FirstOrDefault(q => q.id == index[i].id).startindex = index.Count - i; //sql.FromSql(string.Format("update moduleinfo set startindex={0} where id={1}", index.Count - i, index[i].id)); TModuleLogic.UpdateModule(index[i].id, new Dos.ORM.Field[] { TModule._.startindex, }, new object[] { index.Count - i, }); } moduleList.Sort(TypeDescriptor.GetProperties(typeof(TModule)).Find("startindex", false), ListSortDirection.Descending); dgvMix.Invalidate(); } formindex.Dispose(); } catch (Exception e) { MixLogHelper.Error(ClassName, "启动顺序配置异常", e.StackTrace); } }
/// <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); } try { if (Convert.ToInt32(ConfigFunc.GetRegeditData_LocalMachine(ConfigFunc.RegeditDirKey, "FirstStart")) == 0) { //开始初始化模块配置和数据库信息 bool success = InitModuleDatabase(); if (success) { ConfigFunc.SetRegeditData_LocalMachine(ConfigFunc.RegeditDirKey, "FirstStart", 1); } } } catch (Exception e) { MixLogHelper.Error(ClassName, "数据库初始化异常", e.StackTrace); } finally { } }
/// <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); } } }