西門子Siemens.Simatic.Framework框架學習
一、設計窗體
將電腦時間改為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 勾選操作
在許可權管理-角色管理中找到對應的角色 在操作結構中找到新建的窗體,勾選,儲存。