[How To]如何使用Wildfish进行ISeries开发---多操作篇
ORDEREntity entity = orderDataSet1.ORDERTable.CreateEntity();
entity.CUSTOMERNAME = this.txtCustomerName.Text;
entity.ORDERDATE = DateTime.Now;
entity.PROCESSDATE = DateTime.Now; //Here I think it will be a nullable date type,but the framework now do not support this feature.
entity.PROCESSUSER = "";
orderDataSet1.ORDERTable.SetEntity(entity);
ORDERSystem mgrSystem = new ORDERSystem();
if (!mgrSystem.InsertOrder(orderDataSet1))
{
MessageBox.Show("Error occured at inserting order!Please check the log for the problem!");
}
else
{
MessageBox.Show("Success to insert an order!You may using STRSQL or using navigator to see what inserted!");
}
1。新建一个Winform 名字是TestMultiTableentity.CUSTOMERNAME = this.txtCustomerName.Text;
entity.ORDERDATE = DateTime.Now;
entity.PROCESSDATE = DateTime.Now; //Here I think it will be a nullable date type,but the framework now do not support this feature.
entity.PROCESSUSER = "";
orderDataSet1.ORDERTable.SetEntity(entity);
ORDERSystem mgrSystem = new ORDERSystem();
if (!mgrSystem.InsertOrder(orderDataSet1))
{
MessageBox.Show("Error occured at inserting order!Please check the log for the problem!");
}
else
{
MessageBox.Show("Success to insert an order!You may using STRSQL or using navigator to see what inserted!");
}
2. 添加using
using Wildfish.Data.ISeries;
using Wildfish.BusinessFacade.ISeries;
3。画屏幕
4。编写Code
插入OrderItem
//thus is just a sample,so i do not add lot of validation
int maxItemIndex = 0;
for (int i = 0; i < orderDataSet1.ORDERITEMTable.Rows.Count; i++)
{
if (maxItemIndex < orderDataSet1.ORDERITEMTable.GetEntity(i).ITEMID)
{
maxItemIndex = orderDataSet1.ORDERITEMTable.GetEntity(i).ITEMID;
}
}
maxItemIndex++; //It will be a new Item
ORDERITEMEntity entity = orderDataSet1.ORDERITEMTable.CreateEntity();
entity.ITEMID = maxItemIndex;
entity.PRICE = Convert.ToDecimal(this.txtPrice.Text);
entity.PRODUCTNAME = this.txtProductName.Text;
entity.QUANTITY = Convert.ToInt32(this.txtQuantity.Text);
orderDataSet1.ORDERITEMTable.SetEntity(entity);
int maxItemIndex = 0;
for (int i = 0; i < orderDataSet1.ORDERITEMTable.Rows.Count; i++)
{
if (maxItemIndex < orderDataSet1.ORDERITEMTable.GetEntity(i).ITEMID)
{
maxItemIndex = orderDataSet1.ORDERITEMTable.GetEntity(i).ITEMID;
}
}
maxItemIndex++; //It will be a new Item
ORDERITEMEntity entity = orderDataSet1.ORDERITEMTable.CreateEntity();
entity.ITEMID = maxItemIndex;
entity.PRICE = Convert.ToDecimal(this.txtPrice.Text);
entity.PRODUCTNAME = this.txtProductName.Text;
entity.QUANTITY = Convert.ToInt32(this.txtQuantity.Text);
orderDataSet1.ORDERITEMTable.SetEntity(entity);
OrderSystem的InsertOrder逻辑
KEYSEQNUpdateObject updObj = new KEYSEQNUpdateObject();
updObj.Where[KEYSEQNUpdateObject.TYPE_Field].FieldValue = "SEQN";
updObj.Where[KEYSEQNUpdateObject.CODE_Field].FieldValue = "ORDER";
updObj.Result[KEYSEQNUpdateObject.DETAIL6_Field].Expression = "DETAIL6+1";
try
{
baseDataAccess.BeginTransaction();
if (!mgrRule.UpdateData(baseDataAccess, updObj))
{
baseDataAccess.Rollback();
return false;
}
string orderID = "Order" + updObj.Result[KEYSEQNUpdateObject.DETAIL6_Field].FieldValue;
ORDEREntity orderEntity = orderDataSet.ORDERTable.GetEntity(0);
orderEntity.ORDERID = orderID;
for (int i = 0; i < orderEntity.ORDERITEMEntities.Count; i++)
{
orderEntity.ORDERITEMEntities[i].ORDERID = orderID;
}
orderDataSet.SetEntity(orderEntity);
if (!baseDataAccess.InsertObjectData(orderDataSet))
{
baseDataAccess.Rollback();
return false;
}
baseDataAccess.Commit();
return true;
}
catch
{
baseDataAccess.Rollback();
return false;
}
updObj.Where[KEYSEQNUpdateObject.TYPE_Field].FieldValue = "SEQN";
updObj.Where[KEYSEQNUpdateObject.CODE_Field].FieldValue = "ORDER";
updObj.Result[KEYSEQNUpdateObject.DETAIL6_Field].Expression = "DETAIL6+1";
try
{
baseDataAccess.BeginTransaction();
if (!mgrRule.UpdateData(baseDataAccess, updObj))
{
baseDataAccess.Rollback();
return false;
}
string orderID = "Order" + updObj.Result[KEYSEQNUpdateObject.DETAIL6_Field].FieldValue;
ORDEREntity orderEntity = orderDataSet.ORDERTable.GetEntity(0);
orderEntity.ORDERID = orderID;
for (int i = 0; i < orderEntity.ORDERITEMEntities.Count; i++)
{
orderEntity.ORDERITEMEntities[i].ORDERID = orderID;
}
orderDataSet.SetEntity(orderEntity);
if (!baseDataAccess.InsertObjectData(orderDataSet))
{
baseDataAccess.Rollback();
return false;
}
baseDataAccess.Commit();
return true;
}
catch
{
baseDataAccess.Rollback();
return false;
}
代码很简单,我就不细说了,
其实就是,用一个UpdateObject对象生成Key,然后给Order对象的OrderID赋值,然后Insert到数据库。