1 Star 0 Fork 0

momoxxx/cq.Plugins

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
PRD_MO_editPlugins.cs 9.43 KB
一键复制 编辑 原始数据 按行查看 历史
momoxxx 提交于 2024-01-09 14:40 . 添加项目文件。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.ComponentModel;
using Kingdee.BOS;
using Kingdee.BOS.Contracts;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.List;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Metadata.ControlElement;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Business.Bill;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Core.Bill.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Core.Interaction;
using Kingdee.BOS.App;
using Kingdee.BOS.App.Core;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Orm.Metadata.DataEntity;
/// <summary>
/// 宇祥 2018.04.12
/// </summary>
namespace DomuStar.Plugins
{
[Description("生产工单")]
public class PRD_MO_editPlugins : AbstractBillPlugIn
{
public override void BeforeSave(BeforeSaveEventArgs e)
{
base.BeforeSave(e);
OperationResult pushResult = new OperationResult();
OperateResult oOperateResult = new OperateResult();
string sWorkShopName1 = "", sWorkShopName2 = "";
string sFWorkShopID = "", sFPlanFinishDate = "", sMaterialid = "";
double dQty = 0;
int iWorkShopId = 0, iErrCnt = 0;
string ls_sql = "";
System.Data.IDataReader data3;
//二开生产订单:保存时计算此车间的所有产能情况,根据生产订单的完工日期判断如果超过部门总产能
//,就自动跳到第二生产部门,依次类推,直到第三部门,再不满足就提示
for (int i = 0; i < View.Model.GetEntryRowCount("FTreeEntity"); i++)
{
if (View.Model.GetValue("FMaterialId", i) != null)
sMaterialid = (this.View.Model.GetValue("FMaterialId", i) as DynamicObject)["id"].ToString();//物料编码
if (View.Model.GetValue("FWorkShopID", i) != null)
sFWorkShopID = (this.View.Model.GetValue("FWorkShopID", i) as DynamicObject)["id"].ToString();//生产部门
if (View.Model.GetValue("FPlanFinishDate", i) != null)
sFPlanFinishDate = this.View.Model.GetValue("FPlanFinishDate", i).ToString();//计划完工时间
if (View.Model.GetValue("FQty", i) != null)
dQty = Convert.ToDouble(this.View.Model.GetValue("FQty", i).ToString());//数量
ls_sql = " EXEC sp_ODE_chgMOWORKSHOPID '" + sFWorkShopID + "'," + sMaterialid + "," + dQty + ",'" + sFPlanFinishDate + "'";
data3 = Kingdee.BOS.App.Data.DBUtils.ExecuteReader(this.Context, ls_sql);
while (data3.Read())
{
iWorkShopId = Convert.ToInt32(data3["WorkShopId"].ToString());
if (iWorkShopId == 0)
{
oOperateResult = new OperateResult()
{
Message = "车间产能不满足",
Name = "车间产能不满足",
MessageType = MessageType.FatalError,
SuccessStatus = false
};
pushResult.OperateResult.Add(oOperateResult);
iErrCnt++;
}
else
{
this.View.Model.SetItemValueByID("FWorkShopID", iWorkShopId, i);//生产部门
sWorkShopName1 = GetFirstColResult<string>(getWorkShopName(sFWorkShopID));
sWorkShopName2 = GetFirstColResult<string>(getWorkShopName(iWorkShopId.ToString()));
oOperateResult = new OperateResult()
{
Message = "行【" + (i + 1) + "】车间由【" + sWorkShopName1 + "】转换为车间【" + sWorkShopName2 + "】",
Name = "车间转换",
MessageType = MessageType.Normal,
SuccessStatus = true
};
pushResult.OperateResult.Add(oOperateResult);
}
}
data3.Close();
data3.Dispose();
}
if (iErrCnt > 0)
{
pushResult.MergeValidateErrors();
this.View.ShowOperateResult(pushResult.OperateResult);
e.Cancel = true;
}
else if (pushResult.OperateResult.Count > 0)
{
pushResult.MergeValidateErrors();
this.View.ShowOperateResult(pushResult.OperateResult);
}
}
//public override void AfterSave(AfterSaveEventArgs e)
//{
// base.AfterSave(e);
// if (e.DataEntitys.Length > 0)
// {
// for (int i = 0; i < e.DataEntitys.Length; i++)
// {
// string billno = e.DataEntitys[i]["BillNO"].ToString();
// //e.DataEntitys[i].Clone();
// IViewService ivs = Kingdee.BOS.App.ServiceHelper.GetService<IViewService>();
// MetaDataService metaService = new MetaDataService();
// FormMetadata formmeta = metaService.Load(this.Context, "YL_T_TMS_ForwardInfo") as FormMetadata;
// DynamicObjectType dt = formmeta.BusinessInfo.GetDynamicObjectType();
// DynamicObject[] dyos = ivs.Load(this.Context, new object[] { e.DataEntitys[i]["Id"] }, dt);
// if (dyos.Length > 0)
// {
// DynamicObject[] dyosclon = dyos.Clone() as DynamicObject[];
// if (dyosclon != null)
// {
// IEnumerable<long> infopk =
// ServiceHelper.GetService<IDBService>()
// .GetSequenceInt64(this.Context, "YL_T_TMS_ForwardInfo", 1);
// dyosclon[0]["Id"] = infopk.ElementAt<long>(0);
// dyosclon[0]["BillNo"] = dyosclon[0]["BillNo"] + "QC";
// //dyosclon[0][""]
// DynamicObjectCollection forwardInfoForw =
// dyosclon[0]["YL_T_TMS_ForwardInfoForw"] as DynamicObjectCollection;
// if (forwardInfoForw.Count > 0)
// {
// //int[] forwpk = ServiceHelper.GetService<IDBService>().GetSequenceInt32(this.Context, "YL_T_TMS_ForwardInfoForw", forwardInfoForw.Count);
// //for (int j = 0; j < forwardInfoForw.Count; j++)
// //{
// // forwardInfoForw[j]["Id"] = forwpk[j];
// //}
// forwardInfoForw.Clear();
// }
// DynamicObjectCollection dyocmat = dyosclon[0]["YL_T_TMS_ForwardInfoMAT"] as DynamicObjectCollection;
// if (dyocmat.Count > 0)
// {
// //int[] matpk = ServiceHelper.GetService<IDBService>().GetSequenceInt32(this.Context, "YL_T_TMS_ForwardInfoMAT", dyocmat.Count);
// for (int j = 0; j < dyocmat.Count; j++)
// {
// dyocmat[j]["Id"] = infopk.ElementAt<long>(0);
// }
// }
// ISaveService ise = Kingdee.BOS.App.ServiceHelper.GetService<ISaveService>();
// ise.Save(this.Context, formmeta.BusinessInfo, dyosclon);
// }
// }
// }
// }
//}
public string getWorkShopName(string sWorkShopId)
{
string sSql = "select FNAME from T_BD_DEPARTMENT_L where FDEPTID=" + sWorkShopId;
return sSql;
}
/// <summary>
/// 获取第一行第一列的值
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="sql"></param>
/// <returns></returns>
private T GetFirstColResult<T>(string sql)
{
//string sql = string.Format("/*dialect*/select sum(f_piqe_needqty) from PIQE_t_SCM_PreProentry where fid={0} and F_PIQE_MATERIALID={1}", pkId, mid);
if (sql.IsNullOrEmptyOrWhiteSpace())
return default(T);
var exp = from p
in DBUtils.ExecuteEnumerable(this.Context, sql)
select new
{
value = p.GetValue<T>(0)
};
T result = default(T);
var data = exp.FirstOrDefault();
if (data != null)
{
result = data.value;
}
return result;
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/momoxxx/cq.-plugins.git
git@gitee.com:momoxxx/cq.-plugins.git
momoxxx
cq.-plugins
cq.Plugins
master

搜索帮助