一、设计窗体
将电脑时间改为2000年,否则无法打开ORMappingGenerator.exe
使用ORMappingGenerator.exe针对数据表或视图生成代码
生成的4部分代码,分别放到对应的目录。
Common\Entities
DataAccess
BusinessLogic\InterfaceBO
BusinessLogic\DefaultImpl
注意修改命名空间
在GUIClient里的View文件夹里添加类
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Siemens.Simatic.Right.BusinessLogic;
using Siemens.Simatic.PM.Common;
namespace Siemens.Simatic.GUIClient.PM.Unfinished
{
class COPOMUnfinishedView : Siemens.Simatic.Right.BusinessLogic.SSViewDataAdapter<CO_POM_UnFinished>
{
public int RowNumber = 1;
public COPOMUnfinishedView(ListView view, SSResourceManager resourceManager, string resourceKey)
: base(view, resourceManager, resourceKey)
{
}
protected override void OnBuildColumns()
{
ViewDataColumns.Add(new SSViewDataColumn("RowNumber", "行号", 80));
ViewDataColumns.Add(new SSViewDataColumn("SN", "SN码", 160));
ViewDataColumns.Add(new SSViewDataColumn("OrderID", "订单号", 120));
ViewDataColumns.Add(new SSViewDataColumn("SNStatusStr", "SN状态", 120));
ViewDataColumns.Add(new SSViewDataColumn("CreateDate", "操作时间", 120));
ViewDataColumns.Add(new SSViewDataColumn("TypeStr", "尾数机类型", 120));
ViewDataColumns.Add(new SSViewDataColumn("IsLockedStr", "是否锁定", 120));
}
protected override string GetItemBoundValue(string itemID, CO_POM_UnFinished entity)
{
string boundValue = string.Empty;
switch (itemID)
{
case "RowNumber": boundValue = Convert.ToString(RowNumber++); break;
case "SN": boundValue = entity.SN; break;
case "OrderID": boundValue = entity.OrderID; break;
case "SNStatus": boundValue = entity.SNStatus; break;
case "SNStatusStr": boundValue = SNStatusStr(entity.SNStatus); break;
case "CreateDate": boundValue = entity.CreateDate.HasValue ? entity.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss") : ""; break;
case "Type": boundValue = entity.Type; break;
case "TypeStr": boundValue = TypeStr(entity.Type); break;
case "IsLocked": boundValue = entity.IsLocked; break;
case "IsLockedStr": boundValue = IsLockedStr(entity.IsLocked); break;
case "Reason": boundValue = entity.Reason; break;
default: boundValue = string.Empty; break;
}
return boundValue;
}
protected string SNStatusStr(string SNStatus)
{
string str = string.Empty;
switch (SNStatus)
{
case "1": str = "未清机"; break;
default: str = string.Empty; break;
}
return str;
}
protected string TypeStr(string Type)
{
string str = string.Empty;
switch (Type)
{
case "1": str = "工程不良尾数机"; break;
case "2": str = "其他尾数机"; break;
default: str = string.Empty; break;
}
return str;
}
protected string IsLockedStr(string value)
{
string str = string.Empty;
switch (value)
{
case "1": str = "是"; break;
case "0": str = "否"; break;
default: str = string.Empty; break;
}
return str;
}
}
}
在GUIClient里添加UserControl 继承SScanvas
实例
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Siemens.Simatic.Platform.SSControl;
using Siemens.Simatic.Util.Utilities;
using Siemens.Simatic.Right.BusinessLogic;
using Siemens.Simatic.Platform.Core;
using Siemens.Simatic.PM.Common.QueryParams;
using Siemens.Simatic.PM.BusinessLogic;
using Siemens.Simatic.PM.Common;
using Siemens.Simatic.Platform.Common;
using Siemens.Simatic.Util.Common;
namespace Siemens.Simatic.GUIClient.PM.Unfinished
{
public partial class UnfinishedForm : SSCanvas
{
private SSResourceManager _resourceManager = new SSResourceManager(typeof(UnfinishedForm).FullName);
COPOMUnfinishedView _copomunfinishedview;
CO_POM_UnFinished _curUnfinished;
ICO_POM_UnFinishedBO _ico_pom_unfinishedbo = ObjectContainer.BuildUp<ICO_POM_UnFinishedBO>();
public UnfinishedForm()
{
InitializeComponent();
_copomunfinishedview = new COPOMUnfinishedView(this.lvUnfinished, _resourceManager, "_copomunfinishedview");
this.SSFormToolBarController.IsShowBar = true;
this.SSFormToolBarController.QueryToolButtonHandler += new EventHandler(QueryItem_Event);
this.SSFormToolBarController.SaveToolButtonHandler += new EventHandler(SaveItem_Event);
this.SSFormToolBarController.AddButtonsRangeToShow(this.SSFormToolBarController.QueryButton, this.SSFormToolBarController.SaveButton);
this.SSFormToolBarController.QueryButton.Text = "查询";
this.SSFormToolBarController.SaveButton.Text = "保存";
}
//查询
private void QueryItem_Event(Object Sender, EventArgs e)
{
CO_POM_Unfinished_QueryParam qp = new CO_POM_Unfinished_QueryParam
{
SN = this.txtSN.Text.Trim(),
OrderID = this.txtOrderID.Text.Trim(),
SNStatus = this.cbSNStatus.SelectedValue.ToString(),
Type = this.cbType.SelectedValue.ToString(),
IsLocked = this.cbIsLocked.SelectedValue.ToString()
};
IList<CO_POM_UnFinished> list = _ico_pom_unfinishedbo.GetEntities(qp);
_copomunfinishedview.DataBind(list);
}
private void UnfinishedForm_Load(object sender, EventArgs e)
{
#region 状态 下拉框
IList<ComboBoxList> ComboBoxList = new List<ComboBoxList>();
ComboBoxList.Add(new ComboBoxList() { Value = "", Text = "--请选择 --" });
ComboBoxList.Add(new ComboBoxList() { Value = "1", Text = "未清机" });
this.cbSNStatus.DataSource = ComboBoxList.Where(t => t.Text != "").ToList<ComboBoxList>();
this.cbSNStatus.ValueMember = "Value";
this.cbSNStatus.DisplayMember = "Text";
this.cbDetailsSNStatus.DataSource = ComboBoxList.Where(t => 1 == 1).ToList<ComboBoxList>();
this.cbDetailsSNStatus.ValueMember = "Value";
this.cbDetailsSNStatus.DisplayMember = "Text";
#endregion
#region 尾数机类型 下拉框
IList<ComboBoxList> ComboBoxListType = new List<ComboBoxList>();
ComboBoxListType.Add(new ComboBoxList() { Value = "", Text = "--请选择 --" });
ComboBoxListType.Add(new ComboBoxList() { Value = "1", Text = "工程不良尾数机" });
ComboBoxListType.Add(new ComboBoxList() { Value = "2", Text = "其他尾数机" });
this.cbType.DataSource = ComboBoxListType.Where(t => t.Text != "").ToList<ComboBoxList>();
this.cbType.ValueMember = "Value";
this.cbType.DisplayMember = "Text";
this.cbDetailsType.DataSource = ComboBoxListType.Where(t => 1 == 1).ToList<ComboBoxList>();
this.cbDetailsType.ValueMember = "Value";
this.cbDetailsType.DisplayMember = "Text";
this.UpdateToolBarBtnStatuses(FormOperationStatusEnum.Initialized);
#endregion
#region 是否锁定 下拉框
IList<ComboBoxList> ComboBoxListIsLocked = new List<ComboBoxList>();
ComboBoxListIsLocked.Add(new ComboBoxList() { Value = "", Text = "--请选择 --" });
ComboBoxListIsLocked.Add(new ComboBoxList() { Value = "1", Text = "是" });
ComboBoxListIsLocked.Add(new ComboBoxList() { Value = "0", Text = "否" });
this.cbIsLocked.DataSource = ComboBoxListIsLocked.Where(t => t.Text != "").ToList<ComboBoxList>();
this.cbIsLocked.ValueMember = "Value";
this.cbIsLocked.DisplayMember = "Text";
this.cbDetailsIsLocked.DataSource = ComboBoxListIsLocked.Where(t => 1 == 1).ToList<ComboBoxList>();
this.cbDetailsIsLocked.ValueMember = "Value";
this.cbDetailsIsLocked.DisplayMember = "Text";
#endregion
this.UpdateToolBarBtnStatuses(FormOperationStatusEnum.Initialized);
}
//点击数据行
private void lvUnfinished_Click(object sender, EventArgs e)
{
if (_copomunfinishedview.SelectItem == null)
{
return;
}
_curUnfinished = _copomunfinishedview.SelectItem;
this.txtDetailsSN.Text = _curUnfinished.SN;
this.txtDetailsOrderID.Text = _curUnfinished.OrderID;
this.cbDetailsSNStatus.SelectedValue = _curUnfinished.SNStatus;
this.cbDetailsType.SelectedValue = _curUnfinished.Type;
this.txtDetailsReason.Text = _curUnfinished.Reason;
this.cbDetailsIsLocked.SelectedValue = _curUnfinished.IsLocked == null ? string.Empty : _curUnfinished.IsLocked;
this.UpdateToolBarBtnStatuses(FormOperationStatusEnum.BeginEdit);
}
//保存
private void SaveItem_Event(Object sender, EventArgs e)
{
try
{
_curUnfinished.Reason = this.txtDetailsReason.Text;
_curUnfinished.IsLocked = this.cbDetailsIsLocked.SelectedValue.ToString();
_ico_pom_unfinishedbo.Update(_curUnfinished);
SSMessageBox.ShowInfomation("保存成功!");
//TODO刷新查询结果
QueryItem_Event(this,e);
this.UpdateToolBarBtnStatuses(FormOperationStatusEnum.EndEdit);
}
catch (Exception ex)
{
SSMessageBox.ShowError(ex.Message);
}
}
}
}
查询功能
在Common\QueryParam下 新增类CO_POM_Unfinished_QueryParam : CO_POM_UnFinished
在BusinessLogic\InterfaceBO\ICO_POM_UnfinishedBO接口类中增加
IList<CO_POM_UnFinished> GetEntities(CO_POM_Unfinished_QueryParam qp);接口
在BusinessLogic\DefaultImpl\CO_POM_UnFinishedBO实现上面接口。
public IList<CO_POM_UnFinished> GetEntities(Common.QueryParams.CO_POM_Unfinished_QueryParam qp)
{
AndFilter af = new AndFilter();
MatchingFilter mf = new MatchingFilter();
if (!string.IsNullOrEmpty(qp.SN))
{
mf.AddMatching("SN", qp.SN);
}
if (!string.IsNullOrEmpty(qp.OrderID))
{
mf.AddMatching("OrderID", qp.OrderID);
}
if (!string.IsNullOrEmpty(qp.SNStatus))
{
mf.AddMatching("SNStatus", qp.SNStatus);
}
if (!string.IsNullOrEmpty(qp.Type))
{
mf.AddMatching("Type", qp.Type);
}
if (!string.IsNullOrEmpty(qp.IsLocked))
{
mf.AddMatching("IsLocked", qp.IsLocked);
}
af.AddFilter(mf);
Sort sort = new Sort();
sort.OrderBy("ID", Sort.Direction.ASC);
long totalCount;
IList<CO_POM_UnFinished> list = cO_POM_UnFinishedDAO.Find(0, -1, af, sort, out totalCount);
return list;
}
二、配置MESClient显示该窗体
登录Client
系统管理-权限管理-资源管理 在右侧树结构找到对应的模块右键Add Resource
系统
管理-权限管理-资源管理 在右侧树结构找到对应的模块下新建的窗体右键Build Operations 勾选操作
在权限管理-角色管理中找到对应的角色 在操作结构中找到新建的窗体,勾选,保存。