天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

279 lines
9.6 KiB

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using QMAPP.Entity;
using QMAPP.FJC.Entity.Andon;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.Entity.ODS;
using QMAPP.MD.Entity;
using QMAPP.ServicesAgent;
using QMAPP.WinForm.Forms.Andon.Enum;
using QMAPP.WinForm.Forms.ODS;
using QMFrameWork.Common.Serialization;
using QMFrameWork.Data;
namespace QMAPP.WinForm.Forms.Andon
{
/// <summary>
/// 模块编号:M11-3
/// 作 用:视频类型维护
/// 作 者:周晓东
/// 编写日期:2017年11月02日
///</summary>
public partial class CallReasonForm : Form
{
private ServiceAgent _agent;
//呼叫类型
private string _callType = "";
//工厂编码
private string _factoryCode = "";
//工位编码
private string _worklocCode = "";
//工序编码
private string _workcellCode = "";
//工作中心
private string _workcenterCode = "";
//上级主键
private string _pId = "";
//是否新增
private bool isAdd;
/// <summary>
/// 获得工位,工厂,班组等信息
/// </summary>
public void Init()
{
//获得呼叫类型
string callTypeList = System.Configuration.ConfigurationManager.AppSettings["callType"];
string[] arr2 = callTypeList.Split('/');
listBox1.DataSource = arr2;
//根据配置文件获得工位,工序
string locationfile = System.Configuration.ConfigurationManager.AppSettings["loactionfile"];
if (System.IO.File.Exists(locationfile))
{
string machinecode = System.IO.File.ReadAllText(locationfile);
if (!string.IsNullOrEmpty(machinecode.Trim()))
{
//设置ip
MachineInfo machoneInofModel = new MachineInfo { MACHINECODDE = machinecode.Trim() };
var list = _agent.InvokeServiceFunction<List<MachineInfo>>(B9BasicService.MachineInfoBLL_GetAllList.ToString(), machoneInofModel);
if (list.Count > 0)
{
_worklocCode = list[0].WORKLOC_CODE;
_workcellCode = list[0].WORKCELL_CODE;
//根据工序获得工作中心
WorkCell workCellModel = new WorkCell { WORKCELL_CODE = _workcellCode };
var resultWorkCell = _agent.InvokeServiceFunction<DataResult<WorkCell>>("WorkCellBLL_Get", workCellModel);
if (resultWorkCell != null)
{
_workcenterCode = resultWorkCell.Result.WORKCENTER_CODE;
//根据工作中心获得工厂编码
var workCenterModel = new MD.Entity.WorkCenter { WORKCENTER_CODE = _workcenterCode };
var resultWorkCenter = _agent.InvokeServiceFunction<DataResult<MD.Entity.WorkCenter>>("WorkCenterBLL_Get", workCenterModel);
if (resultWorkCenter != null)
{
_factoryCode = resultWorkCenter.Result.FACTORY_CODE;
}
}
}
}
}
}
/// <summary>
/// 获取呼叫原因下拉框数据
/// </summary>
/// <param name="callType"></param>
/// <param name="parentId"></param>
/// <returns></returns>
public List<CallReasonEntity> GetCallReasonList(CallReasonEntity model)
{
//CallReasonEntity model = new CallReasonEntity
//{
// CALL_TYPE = callType,
// PARENTID = parentId
//};
List<CallReasonEntity> callReasonList = _agent.InvokeServiceFunction<List<CallReasonEntity>>("AndonCallBLL_GetCallReasonList", model);
//是否带空项填充返回值
//callReasonList.Insert(0, new CallReasonEntity());
return callReasonList;
}
public void listBoxInit()
{
if (listBox1.SelectedValue != null)
{
//加载下拉列表
_callType = listBox1.SelectedIndex.ToString();
listBox2.DataSource = GetCallReasonList(new CallReasonEntity
{
CALL_TYPE = _callType
});
listBox2.DisplayMember = "CALL_REASION";
listBox2.ValueMember = "PID";
}
}
public CallReasonForm()
{
InitializeComponent();
}
#region 窗体载入
private void Form_Load(object sender, EventArgs e)
{
//隐藏添加修改的panel
panel2.Visible = false;
//初始化
_agent = ClientContext.GetServiceAgent();
//获取变量值
Init();
//获得呼叫类型
string callTypeList = System.Configuration.ConfigurationManager.AppSettings["callType"];
string[] callTypeArr = callTypeList.Split('/');
//加载list
listBox1.DataSource = callTypeArr;
}
#endregion
/// <summary>
/// 删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbDelete_Click(object sender, EventArgs e)
{
string strReason;
string strPid;
if (listBox2.SelectedIndex > 0)
{
//删除
strReason = ((CallReasonEntity)listBox2.SelectedItem).CALL_REASION;
strPid = ((CallReasonEntity)listBox2.SelectedItem).PID;
if (MessageBox.Show("确定删除:" + strReason, Resource1.ConfirmTitle, MessageBoxButtons.OKCancel) != DialogResult.OK)
return;
//直接删除
DataResult<int> result = _agent.InvokeServiceFunction<DataResult<int>>("AndonCallBLL_DeleteCallReason", strPid);
//MessageBox.Show(result.Msg);
if (result.IsSuccess)
{
//加载下拉列表
listBoxInit();
}
}
else
{
MessageBox.Show("请选择要删除的呼叫原因!");
}
}
/// <summary>
/// 新增
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbAdd_Click(object sender, EventArgs e)
{
if (listBox1.SelectedValue == null)
{
MessageBox.Show("请选择呼叫类型.");
}
else
{
//新增
panel2.Visible = true;
isAdd = true;
txtReason.Text = "";
//_pId = ((CallReasonEntity)listBox2.SelectedItem).PID;
}
}
/// <summary>
/// 修改
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsbEdit_Click(object sender, EventArgs e)
{
if (listBox2.SelectedValue == null)
{
MessageBox.Show("请选择呼叫原因.");
}
else
{
//修改
panel2.Visible = true;
isAdd = false;
_pId = ((CallReasonEntity)listBox2.SelectedItem).PID;
txtReason.Text = ((CallReasonEntity)listBox2.SelectedItem).CALL_REASION;
}
}
private void listBox1_SelectedValueChanged(object sender, EventArgs e)
{
listBoxInit();
}
private void listBox2_SelectedValueChanged(object sender, EventArgs e)
{
}
//保存
private void button1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtReason.Text))
{
MessageBox.Show("请输入呼叫原因!");
return;
}
//新增
if (isAdd)
{
DataResult<int> result = _agent.InvokeServiceFunction<DataResult<int>>("AndonCallBLL_InsertCallReason", new CallReasonEntity
{
CALL_TYPE = _callType,
FACTORY_CODE = _factoryCode,
CALL_REASION = txtReason.Text
});
if (result.IsSuccess)
{
//加载下拉列表
listBoxInit();
}
}
//修改
else
{
//获取需要修改的实体
var callReason = _agent.InvokeServiceFunction<CallReasonEntity>("AndonCallBLL_GetCallReason", _pId);
if (callReason != null )
{
callReason.CALL_REASION = txtReason.Text;
DataResult<int> result = _agent.InvokeServiceFunction<DataResult<int>>("AndonCallBLL_UpdateCallReason", callReason);
if (result.IsSuccess)
{
//加载下拉列表
listBoxInit();
}
}
}
panel2.Visible = false;
txtReason.Text = "";
}
//取消
private void button2_Click(object sender, EventArgs e)
{
panel2.Visible = false;
txtReason.Text = "";
}
}
}