Skip to content

Commit

Permalink
增加非模态方式打开窗体的辅助方法
Browse files Browse the repository at this point in the history
  • Loading branch information
magicdict committed Nov 4, 2016
1 parent 2b96f08 commit c307b28
Showing 25 changed files with 271 additions and 237 deletions.
22 changes: 21 additions & 1 deletion Common/UI.cs
Original file line number Diff line number Diff line change
@@ -99,7 +99,27 @@ public static void SetUp(Form orgForm, bool showDialog = true)
/// <param name="mfrm"></param>
/// <param name="isDispose">有些时候需要使用被打开窗体产生的数据,所以不能Dispose</param>
/// <param name="isUseAppIcon"></param>
public static void OpenForm(Form mfrm, bool isDispose, bool isUseAppIcon)
public static void OpenForm(Form mfrm, bool isUseAppIcon)
{
mfrm.StartPosition = FormStartPosition.CenterParent;
mfrm.BackColor = Color.White;
mfrm.FormBorderStyle = FormBorderStyle.FixedSingle;
mfrm.MaximizeBox = false;
mfrm.Font = new Font("微软雅黑", 9);
if (isUseAppIcon)
{
mfrm.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);
}
mfrm.Show();
}

/// <summary>
/// 对话框子窗体的统一管理
/// </summary>
/// <param name="mfrm"></param>
/// <param name="isDispose">有些时候需要使用被打开窗体产生的数据,所以不能Dispose</param>
/// <param name="isUseAppIcon"></param>
public static void OpenModalForm(Form mfrm, bool isDispose, bool isUseAppIcon)
{
mfrm.StartPosition = FormStartPosition.CenterParent;
mfrm.BackColor = Color.White;
4 changes: 2 additions & 2 deletions FunctionForm/Aggregation/frmAggregation.cs
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ private void cmdAddCondition_Click(object sender, EventArgs e)
try
{
var frmAddStage = new FrmAddStage();
Utility.OpenForm(frmAddStage, false, true);
Utility.OpenModalForm(frmAddStage, false, true);
if (frmAddStage.DialogResult == DialogResult.OK) {
stages.AddRange(frmAddStage.BsonDocumentList);
FillStagesTreeview();
@@ -151,7 +151,7 @@ private void cmdSaveAggregatePipeline_Click(object sender, EventArgs e)
private void btnAggrBuilder_Click(object sender, EventArgs e)
{
var frmAggregationBuilder = new FrmStageBuilder();
Utility.OpenForm(frmAggregationBuilder, false, true);
Utility.OpenModalForm(frmAggregationBuilder, false, true);
foreach (var item in frmAggregationBuilder.Aggregation)
{
stages.Add(item);
4 changes: 2 additions & 2 deletions FunctionForm/Aggregation/frmMapReduce.cs
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ private void cmdRun_Click(object sender, EventArgs e)
var frm = new frmDataView();
frm.ShowDocument = mMapReduceResult.Response;
frm.Title = "MapReduce Result";
Utility.OpenForm(frm, true, true);
Utility.OpenModalForm(frm, true, true);
}
catch (Exception ex)
{
@@ -84,7 +84,7 @@ private void cmdRun_Click(object sender, EventArgs e)
private void cmdCreateQueryDocument_Click(object sender, EventArgs e)
{
var frmInsertDoc = new frmCreateDocument();
Utility.OpenForm(frmInsertDoc, false, true);
Utility.OpenModalForm(frmInsertDoc, false, true);
QueryDoc = frmInsertDoc.mBsonDocument;
UiHelper.FillDataToTreeView("Query", QueryTreeView, frmInsertDoc.mBsonDocument);
}
4 changes: 2 additions & 2 deletions FunctionForm/Connection/frmConnect.cs
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ private void RefreshConnection()
/// <param name="e"></param>
private void cmdAddCon_Click(object sender, EventArgs e)
{
Utility.OpenForm(new FrmConnectionMgr(), true, true);
Utility.OpenModalForm(new FrmConnectionMgr(), true, true);
RefreshConnection();
}

@@ -118,7 +118,7 @@ private void cmdModifyCon_Click(object sender, EventArgs e)
{
if (lstConnection.CheckedItems.Count != 1) return;
var connectionName = lstConnection.CheckedItems[0].Text;
Utility.OpenForm(new FrmConnectionMgr(connectionName), true, true);
Utility.OpenModalForm(new FrmConnectionMgr(connectionName), true, true);
RefreshConnection();
}

2 changes: 1 addition & 1 deletion FunctionForm/Operation/frmCreateCollection.cs
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ private void cmdPreview_Click(object sender, EventArgs e)
private void btnCollation_Click(object sender, EventArgs e)
{
var frm = new frmCreateCollation();
Utility.OpenForm(frm, false, true);
Utility.OpenModalForm(frm, false, true);
if (frm.mCollation != null)
{
mCollation = frm.mCollation;
4 changes: 2 additions & 2 deletions FunctionForm/Operation/frmCreateView.cs
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ private void btnAggrBuilder_Click(object sender, EventArgs e)
}
RuntimeMongoDbContext.SetCurrentCollection(cmbViewOn.Text);
var frmAggregationBuilder = new FrmStageBuilder();
Utility.OpenForm(frmAggregationBuilder, false, true);
Utility.OpenModalForm(frmAggregationBuilder, false, true);
foreach (var item in frmAggregationBuilder.Aggregation)
{
stages.Add(item);
@@ -113,7 +113,7 @@ private void btnAggrBuilder_Click(object sender, EventArgs e)
private void btnCollation_Click(object sender, EventArgs e)
{
var frm = new frmCreateCollation();
Utility.OpenForm(frm, false, true);
Utility.OpenModalForm(frm, false, true);
if (frm.mCollation != null)
{
mCollation = frm.mCollation;
24 changes: 6 additions & 18 deletions FunctionForm/Status/frmServerMonitor.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 66 additions & 71 deletions FunctionForm/Status/frmServerMonitor.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Globalization;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;
using MongoDB.Bson;
using MongoUtility.Command;
using MongoUtility.Core;
using ResourceLib.Method;
using ResourceLib.Properties;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace FunctionForm.Status
{
@@ -19,89 +21,82 @@ public FrmServerMonitor()
GuiConfig.Translateform(this);
}

private Dictionary<string, string> QueryName = new Dictionary<string, string>();

private void FillQueryName()
{
//opcounters
QueryName.Add("opcounters.Query", "opcounters.query");
QueryName.Add("opcounters.Insert", "opcounters.insert");
QueryName.Add("opcounters.Update", "opcounters.update");
QueryName.Add("opcounters.Delete", "opcounters.delete");

//memory
QueryName.Add("mem.bits", "mem.bits");
QueryName.Add("mem.resident", "mem.resident");
QueryName.Add("mem.virtual", "mem.virtual");
QueryName.Add("mem.mapped", "mem.mapped");
}

/// <summary>
/// 刷新时间间隔
/// </summary>
public static int RefreshInterval { set; get; }

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void frmServerMonitor_Load(object sender, EventArgs e)
{
FillQueryName();
if (!GuiConfig.IsMono) Icon = GetSystemIcon.ConvertImgToIcon(Resources.KeyInfo);
_mTime = new Timer {Interval = RefreshInterval*1000};
_mTime.Tick += M_Tick;

var querySeries = new Series("Query")
{
ChartType = SeriesChartType.Line,
XValueType = ChartValueType.String,
YValueType = ChartValueType.Int32
};
MonitorGrap.Series.Add(querySeries);

var insertSeries = new Series("Insert")
{
ChartType = SeriesChartType.Line,
XValueType = ChartValueType.String,
YValueType = ChartValueType.Int32
};
MonitorGrap.Series.Add(insertSeries);


var updateSeries = new Series("Update")
{
ChartType = SeriesChartType.Line,
XValueType = ChartValueType.String,
YValueType = ChartValueType.Int32
};
MonitorGrap.Series.Add(updateSeries);
_mTime = new Timer { Interval = RefreshInterval * 1000 };
_mTime.Tick += SetValue;
MonitorGrap.Series.Clear();

var deleteSeries = new Series("Delete")
foreach (var item in QueryName.Keys)
{
ChartType = SeriesChartType.Line,
XValueType = ChartValueType.String,
YValueType = ChartValueType.Int32
};
MonitorGrap.Series.Add(deleteSeries);


var querySeries = new Series(item.Split(".".ToCharArray())[1])
{
ChartType = SeriesChartType.Line,
XValueType = ChartValueType.String,
YValueType = ChartValueType.Int32
};
MonitorGrap.Series.Add(querySeries);
}
SetValue(null,null);
FormClosing += (x, y) => _mTime.Stop();
_mTime.Start();
}

private void M_Tick(object sender, EventArgs e)
/// <summary>
/// 将值设定到图表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SetValue(object sender, EventArgs e)
{
var docStatus =
CommandHelper.ExecuteMongoSvrCommand(CommandHelper.ServerStatusCommand,
var docStatus = CommandHelper.ExecuteMongoSvrCommand(CommandHelper.ServerStatusCommand,
RuntimeMongoDbContext.GetCurrentServer()).Response;

var queryPoint = new DataPoint();
queryPoint.SetValueXY(DateTime.Now.ToString(CultureInfo.InvariantCulture),
docStatus.GetElement("opcounters").Value.AsBsonDocument.GetElement("query").Value);
MonitorGrap.Series[0].Points.Add(queryPoint);

var insertPoint = new DataPoint();
insertPoint.SetValueXY(DateTime.Now.ToString(CultureInfo.InvariantCulture),
docStatus.GetElement("opcounters").Value.AsBsonDocument.GetElement("insert").Value);
MonitorGrap.Series[1].Points.Add(insertPoint);


var updatePoint = new DataPoint();
updatePoint.SetValueXY(DateTime.Now.ToString(CultureInfo.InvariantCulture),
docStatus.GetElement("opcounters").Value.AsBsonDocument.GetElement("update").Value);
MonitorGrap.Series[2].Points.Add(updatePoint);

var deletePoint = new DataPoint();
deletePoint.SetValueXY(DateTime.Now.ToString(CultureInfo.InvariantCulture),
docStatus.GetElement("opcounters").Value.AsBsonDocument.GetElement("delete").Value);
MonitorGrap.Series[3].Points.Add(deletePoint);



foreach (var item in QueryName.Keys)
{
var queryPoint = new DataPoint();
queryPoint.SetValueXY(DateTime.Now.ToString(CultureInfo.InvariantCulture), GetValue(docStatus, QueryName[item]));
MonitorGrap.Series[item.Split(".".ToCharArray())[1]].Points.Add(queryPoint);
}
}

private void btnClose_Click(object sender, EventArgs e)
/// <summary>
/// 获得值
/// </summary>
/// <param name="Doc"></param>
/// <param name="Path"></param>
/// <returns></returns>
private BsonValue GetValue(BsonDocument Doc, string Path)
{
_mTime.Stop();
Close();
var PathArray = Path.Split(".".ToCharArray());
return Doc.GetElement(PathArray[0]).Value.AsBsonDocument.GetElement(PathArray[1]).Value;
}

}
}
14 changes: 0 additions & 14 deletions FunctionForm/Status/frmStatus.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c307b28

Please sign in to comment.