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.SaleBase
{
public partial class frmSpeclLine : FrmBase
{
public frmSpeclLine()
{
InitializeComponent();
}
///
/// 重写基类方法
///
///
///
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "doQuery":
doQuery();
break;
case "doAdd":
doAdd();
break;
case "doUpdate":
doUpdate();
break;
case "doDelete":
this.doDeleteOrRecovery(true);
break;
case "doRecovery":
this.doDeleteOrRecovery(false);
break;
case "doClose":
this.Close();
break;
}
}
private void frmSpeclLine_Load(object sender, EventArgs e)
{
BindCmbStationName();
cmbStationName.SelectedIndex = 0;
doQuery();
}
protected override void OnLoad(EventArgs e)
{
try
{
base.OnLoad(e);
ultraGrid2.DisplayLayout.Override.FilterUIType = Infragistics.Win.UltraWinGrid.FilterUIType.FilterRow;
ultraGrid2.DisplayLayout.Override.FilterOperatorDefaultValue = Infragistics.Win.UltraWinGrid.FilterOperatorDefaultValue.Contains;
//ultraGrid2.DisplayLayout.Override.CellClickAction = Infragistics.Win.UltraWinGrid.CellClickAction.RowSelect;
}
catch (System.Exception ex)
{ }
}
///
/// 绑定到站信息
///
private void BindCmbStationName()
{
cmbStationName.Items.Clear();
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSpeclLine.GetStation", null, this.ob);
ComboBoxHelper.FillUlcmItemsAddEmpty(cmbStationName, dt);
}
///
/// 专用线条件是否可编辑
///
///
///
private void uceIsName_CheckedChanged(object sender, EventArgs e)
{
if (uceIsName.Checked)
{
txtSpeclLineTitle.Enabled = true;
}
else
{
txtSpeclLineTitle.Enabled = false;
}
}
///
/// 查询
///
private void doQuery()
{
bool validFlag = chkValid.Checked;
string titleName = txtSpeclLineTitle.Text.Trim();
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSpeclLine.doQuery", new Object[] { validFlag, titleName }, this.ob);
GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, 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;
}
}
//列自适应
GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid2, new UltraGridColumn[] {
ultraGrid2.DisplayLayout.Bands[0].Columns["MEMO"]
});
}
///
/// 验证非空字段。
///
///
private bool ValidInput()
{
if (string.IsNullOrEmpty(txtSpeclLineName.Text.Trim()))
{
MessageBox.Show("请输入专用线名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
return true;
}
///
/// 专用线名称是否重复。
///
///
///
private bool isRepeatName(string name)
{
DataTable dt = new DataTable();
//不依据到站编码,他是唯一的,他与客户挂钩。
//string stationCode = cmbStationName.Value.ToString();
dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSpeclLine.isRepeatName", new Object[] { name }, this.ob);
if (dt.Rows.Count > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 获取专用线代码最大值
///
///
private string GetMaxCode()
{
//判断到站编码是否为空。
string stationCode = "";
if (cmbStationName.Value == null||"".Equals(cmbStationName.Value.ToString()))
{
//为空则查询到站编码=x0000000x的专用线编码最大值加一。
stationCode = "XX000000X";
}
else
{
stationCode = cmbStationName.Value.ToString();
}
//不为空,则查询到站编码等于stationName的专用线编码最大值。
//专用线代码加一
DataTable dt = ServerHelper.GetData("com.steering.pss.sale.base.CoreSpeclLine.GetMaxCode", new Object[] { stationCode }, this.ob);
string maxCode = "";
if (dt.Rows.Count > 0)
{
if (!"".Equals(dt.Rows[0][0].ToString()))
{
maxCode = dt.Rows[0][0].ToString();
//获取最后三位数字。
int maxNumber = Convert.ToInt32(maxCode.Substring(maxCode.Length - 3)) + 1;
string codeStr = maxCode.Substring(0, maxCode.Length - 3);
if (maxNumber > 999)
{
return "";
}
else if (maxNumber > 99)
{
}
else if (maxNumber > 9)
{
maxCode = codeStr + "0" + maxNumber;
}
else
{
maxCode = codeStr + "00" + maxNumber;
}
}
else
{
maxCode = stationCode + "001";
}
}
return maxCode;
}
///
/// 新增
///
private void doAdd()
{
if (ValidInput())
{
try
{
//验证描述不允许重复。
string name = txtSpeclLineName.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 speclLineCode = autoCode;
parm.Add(speclLineCode);
parm.Add(name);
string stationCode = "";
if (cmbStationName.Value == null||"".Equals(cmbStationName.Value.ToString()))
{
stationCode = "XX000000X";
}
else
{
stationCode = cmbStationName.Value.ToString();
}
parm.Add(stationCode);
parm.Add(txtMemo.Text);
parm.Add(this.UserInfo.GetUserName());
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.sale.base.CoreSpeclLine";
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 < ultraGrid2.Rows.Count; i++)
{
row = ultraGrid2.Rows[i];
if (row.Cells["spcl_ln_no"].Value.ToString().Equals(speclLineCode))
{
row.Activate();
break;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
///
/// 修改
///
private void doUpdate()
{
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())
{
//验证描述不允许重复。
string name = txtSpeclLineName.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 speclLineCode = ultraGrid2.ActiveRow.Cells["spcl_ln_no"].Value.ToString(); ;
parm.Add(name);
string stationCode = "";
if (cmbStationName.Value == null||"".Equals(cmbStationName.Value.ToString()))
{
stationCode = "XX000000X";
}
else
{
stationCode = cmbStationName.Value.ToString();
}
parm.Add(stationCode);
parm.Add(txtMemo.Text);
parm.Add(this.UserInfo.GetUserName());
parm.Add(speclLineCode);
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.sale.base.CoreSpeclLine";
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 < ultraGrid2.Rows.Count; i++)
{
row = ultraGrid2.Rows[i];
if (row.Cells["spcl_ln_no"].Value.ToString().Equals(speclLineCode))
{
row.Activate();
break;
}
}
}
}
///
/// 废除或恢复
///
/// true废除 false恢复
private void doDeleteOrRecovery(bool isDelete)
{
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;
}
}
ArrayList param = new ArrayList();
string speclLineCode = ultraGrid2.ActiveRow.Cells["spcl_ln_no"].Value.ToString();
param.Add(speclLineCode);
if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "废除" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
int count = ServerHelper.SetData("com.steering.pss.sale.base.CoreSpeclLine.deleteLineInfo", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob);
if (count > 0)
{
doQuery();
Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
for (int i = 0; i < ultraGrid2.Rows.Count; i++)
{
rowD = ultraGrid2.Rows[i];
if (rowD.Cells["spcl_ln_no"].Value.ToString().Equals(speclLineCode))
{
rowD.Activate();
break;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
///
/// 用于验证修改时,描述是否已存在
///
private static string VName = "";
///
/// GRID ROW激活时信息带至编辑区
///
///
///
private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
{
Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid2.ActiveRow;
if (row != null)
{
txtSpeclLineName.Text = row.Cells["spcl_ln_nm"].Text.Trim();
VName = txtSpeclLineName.Text.Trim();
cmbStationName.Value = row.Cells["station_no"].Value.ToString();
txtMemo.Text = row.Cells["memo"].Value.ToString();
}
}
private void button1_Click(object sender, EventArgs e)
{
this.BindCmbStationName();
}
}
}