using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CoreFS.CA03;
using CoreFS.CA04;
using CoreFS.CA06;
using System.Collections;
using Infragistics.Win.UltraWinGrid;
using Core.Mes.Client.Comm.Server;
using Core.Mes.Client.Comm.Control;
using Core.Mes.Client.Comm.Tool;
namespace Core.StlMes.Client.SaleOrder
{
public partial class frmOrderModel : FrmBase
{
public frmOrderModel()
{
InitializeComponent();
}
public frmOrderModel(OpeBase ob)
{
InitializeComponent();
this.ob = ob;
}
private string use_unit;
public string Use_unit
{
get { return use_unit; }
set { use_unit = value; }
}
///
/// 范本描述模糊查询
///
///
///
private void ultraCheckEditor2_CheckedChanged(object sender, EventArgs e)
{
if (ultraCheckEditor2.Checked)
{
txtNMTitle.Enabled = true;
}
else
{
txtNMTitle.Text = "";
txtNMTitle.Enabled = false;
}
}
///
/// 适用单位模糊查询
///
///
///
private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
{
if (uceUnit.Checked)
{
cmbSyTitle.Enabled = true;
}
else
{
//cmbSyTitle.Value = "";
cmbSyTitle.Enabled = false;
}
}
private void frmOrderModel_Load(object sender, EventArgs e)
{
string saleRegion = doGetSaleOrg();
//适用单位数据源绑定
BindCmbSy(saleRegion);
if (!"".Equals(Use_unit))
{
uceUnit.Checked = true;
cmbSy.Enabled = false;
cmbSy.Value = Use_unit;
cmbSyTitle.Text = Use_unit;
}
doQuery();
}
///
/// 重写基类load事件,屏蔽平台过滤功能。
///
///
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
ultraGrid2.DisplayLayout.Bands[0].Override.HeaderClickAction = HeaderClickAction.Select;
}
///
/// 手动添加toolbar
///
///
///
private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
{
if ("doQuery".Equals(e.Tool.Key))
{
doQueryNew();
}
else if ("doAdd".Equals(e.Tool.Key))
{
doAdd();
}
else if ("doUpdate".Equals(e.Tool.Key))
{
doUpdate();
}
else if ("doDelete".Equals(e.Tool.Key))
{
doDeleteOrRecovery(true);
}
else if ("doRecovery".Equals(e.Tool.Key))
{
doDeleteOrRecovery(false);
}
else if ("doLase".Equals(e.Tool.Key))
{
//上移功能。
doLase();
}
else if ("doNext".Equals(e.Tool.Key))
{
//下移功能
doNext();
}
else if ("doOk".Equals(e.Tool.Key))
{
//确认功能
doOk();
}
else
{
this.Close();
}
}
///
/// 委托方法
///
///
public delegate void GetOrderModelHander(DataRow row,DataTable dt);
public event GetOrderModelHander GetOrderModel;
///
/// 确认功能
///
private void doOk()
{
if (ultraGrid1.ActiveRow == null)
{
MessageBox.Show("请选择一条商务条款范本!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string orderModelNo = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
//子表Table记录也要返回。
BindOrderModelItem(orderModelNo);
foreach (DataRow row in this.dataTable1.Rows)
{
if (orderModelNo.Equals(row["ORDER_MODEL_NO"].ToString()))
{
if (Convert.ToBoolean(row["CUSTOMER_MODEL_FL"]))
{
row["CUSTOMER_MODEL_FL"] = "1";
}
else
{
row["CUSTOMER_MODEL_FL"] = "0";
}
GetOrderModel(row, dataTable2);
this.Close();
return;
}
}
}
///
/// 下移功能
///
private void doNext()
{
if (ultraGrid2.ActiveRow == null)
{
MessageBox.Show("请先选择需要范本条目!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
//获取当前顺序号
string modelIndex = ultraGrid2.ActiveRow.Cells["MODEL_INDEX"].Value.ToString();
string orderModelNo = ultraGrid2.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
string modelSeqNo = ultraGrid2.ActiveRow.Cells["MODEL_SEQ_NO"].Value.ToString();
//获取最大顺序号。
string IndexMax = (GetIndex(orderModelNo) - 1).ToString();
if (IndexMax.Equals(modelIndex))
{
//最大顺序号,无法下移。
return;
}
ServerHelper.SetData("com.steering.pss.sale.order.CoreOrderModel.doNext", new Object[] { modelIndex, orderModelNo, modelSeqNo }, this.ob);
BindOrderModelItem(orderModelNo);
//聚焦当前操作行
Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
for (int i = 0; i < ultraGrid2.Rows.Count; i++)
{
rowD = ultraGrid2.Rows[i];
if (rowD.Cells["ORDER_MODEL_NO"].Value.ToString().Equals(orderModelNo) && rowD.Cells["MODEL_SEQ_NO"].Value.ToString().Equals(modelSeqNo))
{
rowD.Activate();
break;
}
}
}
///
/// 上移功能
///
private void doLase()
{
if (ultraGrid2.ActiveRow == null)
{
MessageBox.Show("请先选择需要范本条目!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
//获取当前选中项的顺序号和相关主键。
//ORDER_MODEL_NO,
// MODEL_SEQ_NO,
// MODEL_SEQ,
// MODEL_INDEX,
string modelIndex = ultraGrid2.ActiveRow.Cells["MODEL_INDEX"].Value.ToString();
string orderModelNo = ultraGrid2.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
string modelSeqNo = ultraGrid2.ActiveRow.Cells["MODEL_SEQ_NO"].Value.ToString();
//如果modelIndex=1,则不执行任何操作。
if ("1".Equals(modelIndex))
{
return;
}
//UPDATE 顺序号=Y WHERE 顺序号=Y-1
//UPDATE 顺序号=Y-1 where 顺序号=当前顺序号所对应的主键id。
//将当前顺序号与相关主键id作为参数,传递到后台执行事物操作。
ServerHelper.SetData("com.steering.pss.sale.order.CoreOrderModel.doLase", new Object[] { modelIndex, orderModelNo, modelSeqNo }, this.ob);
BindOrderModelItem(orderModelNo);
//聚焦当前操作行
Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
for (int i = 0; i < ultraGrid2.Rows.Count; i++)
{
rowD = ultraGrid2.Rows[i];
if (rowD.Cells["ORDER_MODEL_NO"].Value.ToString().Equals(orderModelNo) && rowD.Cells["MODEL_SEQ_NO"].Value.ToString().Equals(modelSeqNo))
{
rowD.Activate();
break;
}
}
}
///
/// 废除或恢复
///
/// true废除 false恢复
private void doDeleteOrRecovery(bool isDelete)
{
//判断是主表还是从表
if ("1".Equals(ultraTabControl1.SelectedTab.Key))
{
if (ultraGrid1.ActiveRow == null)
{
MessageBox.Show("请选择需要" + (isDelete ? "废除" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
Boolean validflagStr = Convert.ToBoolean(ultraGrid1.ActiveRow.Cells["VALIDFLAG"].Value);
if (isDelete)
{
//无效数据不允许删除。
if (!validflagStr)
{
MessageBox.Show("无效数据不支持废除操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
else
{
//有效数据不允许恢复
if (validflagStr)
{
MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
ArrayList param = new ArrayList();
string orderModelNo = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
param.Add(orderModelNo);
if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "废除" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
int count = ServerHelper.SetData("com.steering.pss.sale.order.CoreOrderModel.deleteLineInfo", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob);
if (count > 0)
{
doQuery();
Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
for (int i = 0; i < ultraGrid1.Rows.Count; i++)
{
rowD = ultraGrid1.Rows[i];
if (rowD.Cells["ORDER_MODEL_NO"].Value.ToString().Equals(orderModelNo))
{
rowD.Activate();
break;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
else
{
//从表删除恢复。
if (ultraGrid2.ActiveRow == null)
{
MessageBox.Show("请选择需要" + (isDelete ? "废除" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
Boolean validflagStr = Convert.ToBoolean(ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value);
if (isDelete)
{
//无效数据不允许删除。
if (!validflagStr)
{
MessageBox.Show("无效数据不支持废除操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
else
{
//有效数据不允许恢复
if (validflagStr)
{
MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
//恢复,判断主表状态,如果为无效则不允许恢复。
Boolean validflagStrMain = Convert.ToBoolean(ultraGrid1.ActiveRow.Cells["VALIDFLAG"].Value);
if (!validflagStrMain)
{
MessageBox.Show("范本主体无效,范本条目不允许恢复。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
ArrayList param = new ArrayList();
string orderModelNo = ultraGrid2.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
string xhNo = ultraGrid2.ActiveRow.Cells["MODEL_SEQ_NO"].Value.ToString();
param.Add(orderModelNo);
param.Add(xhNo);
if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "废除" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
int count = ServerHelper.SetData("com.steering.pss.sale.order.CoreOrderModel.deleteLineInfo_ITEM", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob);
if (count > 0)
{
BindOrderModelItem(orderModelNo);
Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
for (int i = 0; i < ultraGrid2.Rows.Count; i++)
{
rowD = ultraGrid2.Rows[i];
if (rowD.Cells["MODEL_SEQ_NO"].Value.ToString().Equals(xhNo))
{
rowD.Activate();
break;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}
///
/// 用于验证修改时,描述是否已存在
///
private static string VName = "";
///
/// 用于验证从表修改时,描述是否已存在
///
private static string VName_Item = "";
///
/// 修改功能
///
private void doUpdate()
{
//判断主从表。
if ("1".Equals(ultraTabControl1.SelectedTab.Key.ToString()))
{
if (ultraGrid1.ActiveRow == null)
{
MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
Boolean validflagStr = Convert.ToBoolean(ultraGrid1.ActiveRow.Cells["VALIDFLAG"].Value);
//无效数据不允许修改
if (!validflagStr)
{
MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (ValidInput())
{
//验证描述不允许重复。
string name = txtNM.Text.Trim();
if (!VName.Equals(name))
{
if (isRepeatName(name))
{
MessageBox.Show("范本描述\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
//确认修改吗?
if (MessageBox.Show("是否确认修改选中的数据!", "提示", MessageBoxButtons.YesNo) == DialogResult.No)
{
return;
}
ArrayList parm = new ArrayList();
string orderModelNo = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
//适用单位编号
parm.Add(cmbSy.Value.ToString());
//适用单位值
parm.Add(cmbSy.Text.Trim());
//范本描述
parm.Add(name);
//是否通用
parm.Add(chkTy.Checked ? "1" : "0");
//是否客户范本
parm.Add(chkFb.Checked ? "1" : "0");
//修改人
parm.Add(this.UserInfo.GetUserName());
//主键id
parm.Add(orderModelNo);
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.sale.order.CoreOrderModel";
ccp.MethodName = "doUpdate";
ccp.ServerParams = new object[] { parm };
ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode == -1) return;
doQuery();
//高亮显示修改的数据
Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
for (int i = 0; i < ultraGrid1.Rows.Count; i++)
{
row = ultraGrid1.Rows[i];
if (row.Cells["ORDER_MODEL_NO"].Value.ToString().Equals(orderModelNo))
{
row.Activate();
break;
}
}
MessageBox.Show("修改成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
{
//从表修改操作
if (ultraGrid2.ActiveRow == null)
{
MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
Boolean validflagStr = Convert.ToBoolean(ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value);
//无效数据不允许修改
if (!validflagStr)
{
MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (ValidInput_Item())
{
//验证描述不允许重复。
string name = txtXh.Text.Trim();
string no = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
if (!VName_Item.Equals(name))
{
if (isRepeatName_Item(name,no))
{
MessageBox.Show("条目序号\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
//确认修改吗?
if (MessageBox.Show("是否确认修改选中的数据!", "提示", MessageBoxButtons.YesNo) == DialogResult.No)
{
return;
}
ArrayList parm = new ArrayList();
string xhNo = ultraGrid2.ActiveRow.Cells["Model_Seq_No"].Value.ToString();
//条目序号
parm.Add(txtXh.Text.Trim());
//条目内容
parm.Add(txtTmDetails.Text.Trim());
//修改人
parm.Add(this.UserInfo.GetUserName());
//合同范本编号
string orderModelNo = ultraGrid2.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
parm.Add(orderModelNo);
//主键id
parm.Add(xhNo);
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.sale.order.CoreOrderModel";
ccp.MethodName = "doUpdate_Item";
ccp.ServerParams = new object[] { parm };
ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode == -1) return;
BindOrderModelItem(orderModelNo);
//高亮显示修改的数据
Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
for (int i = 0; i < ultraGrid2.Rows.Count; i++)
{
row = ultraGrid2.Rows[i];
if (row.Cells["Model_Seq_No"].Value.ToString().Equals(xhNo))
{
row.Activate();
break;
}
}
MessageBox.Show("修改成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
///
/// 查询
///
private void doQuery()
{
//ORDER_MODEL_DESC,USE_UNIT
string orderModelDesc = txtNMTitle.Text.Trim();
string userUnit = cmbSyTitle.Value.ToString();
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.doQuery", new Object[] { orderModelDesc, userUnit }, this.ob);
GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
//不同颜色区分是否有效数据
Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
for (int i = 0; i < ultraGrid1.Rows.Count; i++)
{
row = ultraGrid1.Rows[i];
if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
{
row.Cells["VALIDFLAG"].Value = false;
row.Appearance.ForeColor = Color.Red;
}
else
{
row.Cells["VALIDFLAG"].Value = true;
row.Appearance.ForeColor = Color.Black;
}
//是否通用
if (!row.Cells["GENERAL_FL"].Value.ToString().Equals("1"))
{
row.Cells["GENERAL_FL"].Value = false;
}
else
{
row.Cells["GENERAL_FL"].Value = true;
}
//是否合同范本
if (!row.Cells["CUSTOMER_MODEL_FL"].Value.ToString().Equals("1"))
{
row.Cells["CUSTOMER_MODEL_FL"].Value = false;
}
else
{
row.Cells["CUSTOMER_MODEL_FL"].Value = true;
}
//合同范本状态W:待审;S:审核通过;F审核失败
if (row.Cells["ORDER_MODEL_STS"].Value.ToString().Equals("W"))
{
row.Cells["ORDER_MODEL_STS"].Value = "待审";
}
else if (row.Cells["ORDER_MODEL_STS"].Value.ToString().Equals("S"))
{
row.Cells["ORDER_MODEL_STS"].Value = "审核通过";
}
else
{
row.Cells["ORDER_MODEL_STS"].Value = "审核失败";
}
}
//列自适应
GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid1, new UltraGridColumn[] {
});
}
///
/// 查询mm
///
private void doQueryNew()
{
//ORDER_MODEL_DESC,USE_UNIT
string orderModelDesc = txtNMTitle.Text.Trim();
string userUnit = "";
if (uceUnit.Checked)
{
userUnit = cmbSyTitle.Value.ToString();
}
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.doQueryNew", new Object[] { orderModelDesc, userUnit }, this.ob);
GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
//不同颜色区分是否有效数据
Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
for (int i = 0; i < ultraGrid1.Rows.Count; i++)
{
row = ultraGrid1.Rows[i];
if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
{
row.Cells["VALIDFLAG"].Value = false;
row.Appearance.ForeColor = Color.Red;
}
else
{
row.Cells["VALIDFLAG"].Value = true;
row.Appearance.ForeColor = Color.Black;
}
//是否通用
if (!row.Cells["GENERAL_FL"].Value.ToString().Equals("1"))
{
row.Cells["GENERAL_FL"].Value = false;
}
else
{
row.Cells["GENERAL_FL"].Value = true;
}
//是否合同范本
if (!row.Cells["CUSTOMER_MODEL_FL"].Value.ToString().Equals("1"))
{
row.Cells["CUSTOMER_MODEL_FL"].Value = false;
}
else
{
row.Cells["CUSTOMER_MODEL_FL"].Value = true;
}
//合同范本状态W:待审;S:审核通过;F审核失败
if (row.Cells["ORDER_MODEL_STS"].Value.ToString().Equals("W"))
{
row.Cells["ORDER_MODEL_STS"].Value = "待审";
}
else if (row.Cells["ORDER_MODEL_STS"].Value.ToString().Equals("S"))
{
row.Cells["ORDER_MODEL_STS"].Value = "审核通过";
}
else
{
row.Cells["ORDER_MODEL_STS"].Value = "审核失败";
}
}
//列自适应
GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid1, new UltraGridColumn[] {
});
}
///
/// 验证非空字段。
///
///
private bool ValidInput()
{
if (string.IsNullOrEmpty(txtNM.Text.Trim()))
{
MessageBox.Show("请输入范本描述!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
return true;
}
///
/// 验证范本条目非空项
///
///
private bool ValidInput_Item()
{
if (string.IsNullOrEmpty(txtXh.Text.Trim()))
{
MessageBox.Show("请输入条目序号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (string.IsNullOrEmpty(txtTmDetails.Text.Trim()))
{
MessageBox.Show("请输入条目内容!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
return true;
}
///
/// 范本描述是否重复。
///
///
///
private bool isRepeatName(string name)
{
DataTable dt = new DataTable();
dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.isRepeatName", new Object[] { name }, this.ob);
if (dt.Rows.Count > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 判断条目序号是否已存在
///
///
///
private bool isRepeatName_Item(string name,string modelNo)
{
DataTable dt = new DataTable();
dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.isRepeatName_Item", new Object[] { name, modelNo }, this.ob);
if (dt.Rows.Count > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 获取范本条目顺序号
///
///
private int GetIndex(string orderModelNo)
{
int index = 1;
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.GetIndex", new Object[] { orderModelNo }, this.ob);
if (dt.Rows.Count > 0)
{
if (!"".Equals(dt.Rows[0][0].ToString()))
{
index = Convert.ToInt32(dt.Rows[0][0]) + 1;
}
}
return index;
}
///
/// 自动生成编号
///
///
private string GetMaxCode()
{
//获取适用单位编码
string syNo = cmbSy.Value.ToString();
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.GetMaxCode", new Object[] { syNo }, this.ob);
string maxCode = "";
if (dt.Rows.Count > 0)
{
if (!"".Equals(dt.Rows[0][0].ToString()))
{
maxCode = dt.Rows[0][0].ToString();
//获取最后三位数字。
string maxNumber = (Convert.ToInt32(maxCode.Substring(maxCode.Length - 3)) + 1).ToString();
string codeStr = maxCode.Substring(0, maxCode.Length - 3);
while (maxNumber.Length < 3)
{
maxNumber = "0" + maxNumber;
}
maxCode = codeStr + maxNumber;
}
else
{
maxCode = syNo + "001";
}
}
return maxCode;
}
///
/// 条目序号自动生成编号
///
///
private string GetMaxCode_Item(string orderModelNo)
{
//获取最大序号
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.GetMaxCode_Item", new Object[] { orderModelNo }, this.ob);
string maxCode = "";
if (dt.Rows.Count > 0)
{
if (!"".Equals(dt.Rows[0][0].ToString()))
{
maxCode = (Convert.ToInt32(dt.Rows[0][0]) + 1).ToString();
while (maxCode.Length < 3)
{
maxCode = "0" + maxCode;
}
}
else
{
maxCode = "001";
}
}
return maxCode;
}
///
/// 新增
///
private void doAdd()
{
//判断当前编辑区显示的是范本主体,还是范本条目。
if ("1".Equals(ultraTabControl1.SelectedTab.Key))
{
if (ValidInput())
{
try
{
//验证描述不允许重复。
string name = txtNM.Text.Trim();
if (isRepeatName(name))
{
MessageBox.Show("范本描述\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
ArrayList parm = new ArrayList();
//自动生成编号
string autoCode = GetMaxCode();
if ("".Equals(autoCode))
{
MessageBox.Show("编号超出限制,请与管理员联系。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string syNo = autoCode;
parm.Add(syNo);
parm.Add(name);
//适用单位编码
parm.Add(cmbSy.Value.ToString());
//适用单位描述
parm.Add(cmbSy.Text.ToString());
//是否通用
parm.Add(chkTy.Checked ? "1" : "0");
//是否合同范本
parm.Add(chkFb.Checked ? "1" : "0");
//合同范本状态
parm.Add("W");
//有效标识
//创建人
parm.Add(this.UserInfo.GetUserName());
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.sale.order.CoreOrderModel";
ccp.MethodName = "doAdd";
ccp.ServerParams = new object[] { parm };
ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode == -1) return;
doQuery();
//高亮显示新增的数据
Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
for (int i = 0; i < ultraGrid1.Rows.Count; i++)
{
row = ultraGrid1.Rows[i];
if (row.Cells["ORDER_MODEL_NO"].Value.ToString().Equals(syNo))
{
row.Activate();
break;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
else
{
//从表新增
//验证非空项。
if (ultraGrid1.ActiveRow == null)
{
MessageUtil.ShowWarning("请先选择商务条款或者先新增商务条款!");
return;
}
if (ValidInput_Item())
{
try
{
//验证条目序号是否存在
string name = txtXh.Text.Trim();
string no = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
if (isRepeatName_Item(name,no))
{
MessageBox.Show("条目标题\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
ArrayList parm = new ArrayList();
string orderModelNo = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
//自动生成编号
string autoCode = GetMaxCode_Item(orderModelNo);
if ("".Equals(autoCode))
{
MessageBox.Show("编号超出限制,请与管理员联系。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string seqNo = autoCode;
//合同范本编码
parm.Add(orderModelNo);
//条目序号编码
parm.Add(autoCode);
//条目序号值
parm.Add(name);
//条目顺序号
parm.Add(GetIndex(orderModelNo));
//范本条目值
parm.Add(txtTmDetails.Text.Trim());
//有效标识
//创建人
parm.Add(this.UserInfo.GetUserName());
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.sale.order.CoreOrderModel";
ccp.MethodName = "doAdd_Item";
ccp.ServerParams = new object[] { parm };
ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode == -1) return;
BindOrderModelItem(orderModelNo);
//高亮显示新增的数据
Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
for (int i = 0; i < ultraGrid2.Rows.Count; i++)
{
row = ultraGrid2.Rows[i];
if (row.Cells["Model_Seq_No"].Value.ToString().Equals(seqNo))
{
row.Activate();
break;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
}
///
/// 适用单位数据源绑定
///
///
private void BindCmbSy(string saleRegion)
{
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.GetSy", new Object[] { saleRegion }, this.ob);
//编辑区域适用单位绑定,不提供空值。
cmbSy.DataSource = dt;
cmbSy.DisplayMember = "CUSTOMER_NM";
cmbSy.ValueMember = "CUSTOMER_NO";
cmbSy.DataBind();
cmbSy.SelectedIndex = 0;
//查询区域适用单位绑定,提供空值。
ComboBoxHelper.FillUltraComboItems(cmbSyTitle, dt);
cmbSyTitle.SelectedIndex = 0;
}
///
/// 根据登录账户,判断所属部门。
///
private string doGetSaleOrg()
{
// string departmentId = UserInfo.GetDepartment();
string saleRegion = ClsBaseInfo.GetSaleOrg(UserInfo.GetDeptid());
//if ("销售公司".Equals(departmentId))
//{
// saleRegion = "100101";
//}
//else if ("国贸公司".Equals(departmentId))
//{
// saleRegion = "100102";
//}
//else if ("钢贸公司".Equals(departmentId))
//{
// saleRegion = "100103";
//}
//else
//{
// saleRegion = "100101";
//}
return saleRegion;
}
///
/// 主表行选中事件,选中主表行,绑定合同条目数据源。
///
///
///
private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
{
string orderModelNo = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_NO"].Value.ToString();
BindOrderModelItem(orderModelNo);
//编辑区,Tab页面切换到合同范本主界面,并给编辑区Tab页面赋值。
ultraTabControl1.Tabs[0].Selected = true;
//编辑区控件赋值。
//cmbSy.Value = ultraGrid1.ActiveRow.Cells["USE_UNIT"].Value.ToString();
VName = ultraGrid1.ActiveRow.Cells["ORDER_MODEL_DESC"].Value.ToString();
txtNM.Text = VName;
chkTy.Checked = Convert.ToBoolean(ultraGrid1.ActiveRow.Cells["GENERAL_FL"].Value);
chkFb.Checked = Convert.ToBoolean(ultraGrid1.ActiveRow.Cells["CUSTOMER_MODEL_FL"].Value);
//子表不聚焦,聚焦编辑区会切换到子表编辑区。
ultraGrid2.ActiveRow = null;
txtXh.Text = "";
txtTmDetails.Text = "";
}
///
/// 绑定范本条目数据源
///
private void BindOrderModelItem(string orderModelNo)
{
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.order.CoreOrderModel.GetOrderModelItem", new Object[] { orderModelNo }, this.ob);
GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable2, true);
//不同颜色区分是否有效数据
Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
for (int i = 0; i < ultraGrid2.Rows.Count; i++)
{
row = ultraGrid2.Rows[i];
if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("1"))
{
row.Cells["VALIDFLAG"].Value = false;
row.Appearance.ForeColor = Color.Red;
}
else
{
row.Cells["VALIDFLAG"].Value = true;
row.Appearance.ForeColor = Color.Black;
}
}
}
private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
{
ultraTabControl1.Tabs[1].Selected = true;
VName_Item = ultraGrid2.ActiveRow.Cells["MODEL_SEQ"].Value.ToString();
txtXh.Text = VName_Item;
txtTmDetails.Text = ultraGrid2.ActiveRow.Cells["MODEL_ITM_VAL"].Value.ToString();
}
}
}