using Core.Mes.Client.Comm.Control;
using Core.Mes.Client.Comm.Server;
using Core.Mes.Client.Comm.Tool;
using CoreFS.CA06;
using Infragistics.Win.UltraWinGrid;
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace Core.StlMes.Client.Qcm
{
public partial class FrmSteelGrade : FrmBase
{
public FrmSteelGrade()
{
InitializeComponent();
}
private void FrmSteelGrade_Load(object sender, EventArgs e)
{
cmbGradeType.SelectedIndex = 0;
}
///
/// 重写基类方法
///
///
///
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "doQuery":
try
{
this.Cursor = Cursors.WaitCursor;
doQuery();
}
finally
{
this.Cursor = Cursors.Default;
}
break;
case "doAdd":
doAdd();
break;
case "doModify":
doModify();
break;
case "doDelete":
this.doDeleteOrResume(true);
break;
case "doResume":
this.doDeleteOrResume(false);
break;
case "Export":
GridHelper.ulGridToExcel(ultraGrid2, "钢级信息");
break;
case "Close":
this.Close();
break;
}
}
///
/// 非空项验证
///
///
private bool ValidInput()
{
if (string.IsNullOrEmpty(txtName.Text.Trim()))
{
MessageBox.Show("请输入钢级或牌号描述!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (ultraComboEditor1.Value.ToString2() == "")
{
MessageBox.Show("请选择是否TP系列!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
return true;
}
///
/// 获取钢级牌号代码最大值
///
///
private string GetMaxCode()
{
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSteelGrade.GetMaxCode", null, this.ob);
string maxCode = "";
if (dt.Rows.Count > 0)
{
if (!"".Equals(dt.Rows[0][0].ToString()))
{
maxCode = dt.Rows[0][0].ToString();
}
else
{
maxCode = "C000";
}
}
return maxCode;
}
///
/// 验证描述是否重复。
///
///
///
private bool isRepeatName(string name)
{
DataTable dt = new DataTable();
dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSteelGrade.GetName", new Object[] { name }, this.ob);
if (dt.Rows.Count > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 新增
///
private void doAdd()
{
if (ValidInput())
{
//验证描述不允许重复。
string name = txtName.Text.Trim();
if (isRepeatName(name))
{
MessageBox.Show("钢级\\牌号描述\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
try
{
ArrayList parm = new ArrayList();
//string chenCode = GridHelper.AutoCode(this.dataTable1);
//自动生成编号
string chenCode = StringUtil.SequenceIncrease(GetMaxCode());
parm.Add(chenCode);
parm.Add(name);
parm.Add(cmbGradeType.Value);
parm.Add(this.UserInfo.GetUserName());
parm.Add(txtMemo.Text);
parm.Add(ultraComboEditor1.Value.ToString2());
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.qcm.CoreSteelGrade";
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["STEELCODE"].Value.ToString().Equals(chenCode))
{
row.Activate();
break;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
///
/// 修改
///
private void doModify()
{
if (ultraGrid2.ActiveRow == null)
{
MessageBox.Show("请选择需要修改的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string validflagStr = ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value.ToString();
//无效数据不允许修改
if ("0".Equals(validflagStr))
{
MessageBox.Show("无效数据不支持修改操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
//正式用时 需要打开此段注释
string s1 = ultraGrid2.ActiveRow.GetValue("STEELNAME");
string s2 = ultraGrid2.ActiveRow.GetValue("STEELSTYLE");
if (txtName.Text.Trim() != ultraGrid2.ActiveRow.GetValue("STEELNAME") || cmbGradeType.Value.ToString2() != ultraGrid2.ActiveRow.GetValue("STEELSTYLE"))
{
DataTable dt1 = ServerHelper.GetData("com.steering.pss.qcm.CoreSteelGrade.getPsc", new object[] { ultraGrid2.ActiveRow.Cells["STEELCODE"].Value.ToString() }, this.ob);
if (dt1 != null && dt1.Rows.Count > 0)
{
MessageUtil.ShowWarning("此钢级/牌号已被产品规范码引用,不能修改!");
return;
}
}
if (ValidInput())
{
//验证描述不允许重复。
string name = txtName.Text.Trim();
if (!VName.Equals(name))
{
if (isRepeatName(name))
{
MessageBox.Show("钢级\\牌号描述\"" + name + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
//确认修改吗?
if (MessageBox.Show("是否确认修改选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
ArrayList parm = new ArrayList();
string chenCode = ultraGrid2.ActiveRow.Cells["STEELCODE"].Value.ToString();
parm.Add(name);
parm.Add(cmbGradeType.Value);
parm.Add(this.UserInfo.GetUserName());
parm.Add(txtMemo.Text);
parm.Add(ultraComboEditor1.Value.ToString2());
parm.Add(chenCode);
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.qcm.CoreSteelGrade";
ccp.MethodName = "doModify";
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["STEELCODE"].Value.ToString().Equals(chenCode))
{
row.Activate();
break;
}
}
}
}
///
/// 查询
///
private void doQuery()
{
bool validFlag = chkValid.Checked;
string titleName = "";
if (ultraCheckEditor1.Checked)
{
titleName = txtTitleName.Text.Trim();
}
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.CoreSteelGrade.getLineList", 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.Appearance.ForeColor = Color.Red;
}
else
{
row.Appearance.ForeColor = Color.Black;
}
}
//列自适应
GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid2, new UltraGridColumn[] {
ultraGrid2.DisplayLayout.Bands[0].Columns["MEMO"]
});
}
///
/// 用于验证修改时,描述是否已存在
///
private static string VName = "";
///
/// GRID ROW激活时信息带至编辑区
///
///
///
private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
{
Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid2.ActiveRow;
if (row != null)
{
//STEELCODE,STEELNAME,STEELSTYLE
txtName.Text = row.Cells["STEELNAME"].Value.ToString();
VName = txtName.Text.Trim();
cmbGradeType.Value = row.Cells["STEELSTYLE"].Value.ToString();
txtMemo.Text = row.Cells["MEMO"].Value.ToString();
ultraComboEditor1.Value = row.GetValue("IS_TP");
}
}
///
/// 作废或恢复
///
/// true作废 false恢复
private void doDeleteOrResume(bool isDelete)
{
if (ultraGrid2.ActiveRow == null)
{
MessageBox.Show("请选择需要" + (isDelete ? "作废" : "恢复") + "的数据!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string validflagStr = ultraGrid2.ActiveRow.Cells["VALIDFLAG"].Value.ToString();
//无效数据不允许作废
if ("0".Equals(validflagStr))
{
if (isDelete)
{
MessageBox.Show("无效数据不支持作废操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
else
{
//有效数据不允许恢复
if (!isDelete)
{
MessageBox.Show("有效数据不支持恢复操作。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
ArrayList param = new ArrayList();
string steelCode = ultraGrid2.ActiveRow.Cells["STEELCODE"].Value.ToString();
param.Add(steelCode);
if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "作废" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
int count = ServerHelper.SetData("com.steering.pss.qcm.CoreSteelGrade.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["STEELCODE"].Value.ToString().Equals(steelCode))
{
rowD.Activate();
break;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
private void ultraCheckEditor1_CheckedChanged(object sender, EventArgs e)
{
if (ultraCheckEditor1.Checked)
{
txtTitleName.ReadOnly = false;
}
else
{
txtTitleName.ReadOnly = true;
}
}
}
}