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.PlnSaleOrd
{
public partial class FrmGXElements : FrmBase
{
public FrmGXElements()
{
InitializeComponent();
ExceptionHelper.RegistException();
}
private void FrmGXElements_Load(object sender, EventArgs e)
{
//bindcmbStyle();
//this.ultraComboEditor1.SelectedIndex = 0;
//this.cmbStyle.SelectedIndex = 0;
}
///
/// 重写基类方法
///
///
///
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "doQuery":
doQuery();
break;
case "doAdd":
doAdd();
break;
case "doModify":
doModify();
break;
case "doDelete":
this.doDeleteOrResume(true);
break;
case "doResume":
this.doDeleteOrResume(false);
break;
case "Export":
this.ExportData();
break;
case "Close":
this.Close();
break;
}
}
///
/// 新增
///
private void doAdd()
{
//验证描述不允许重复。
string CODE = GX_CODE.Text.Trim();
if (isRepeatCode(CODE))
{
MessageBox.Show("高新编码\"" + CODE + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (MessageUtil.ShowYesNoAndQuestion("是否确认新增?") == DialogResult.No) return;
ArrayList parm = new ArrayList();
//string chenCode = AutoCode(this.dataTable1);
parm.Add(CODE);
parm.Add(GX_NAME.Text.ToString2());
parm.Add(GX_YEAR.Text.ToString2());
parm.Add(this.UserInfo.GetUserName());
parm.Add(GX_Memo.Text);
parm.Add(GX_YFFY.Text.ToString2());
parm.Add(GX_FZR.Text.ToString2());
CoreClientParam ccp = new CoreClientParam();
ccp.ServerName = "com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp";
ccp.MethodName = "doAdd";
ccp.ServerParams = new object[] { parm };
ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode == -1)
{
return;
}
MessageUtil.ShowTips("新增成功!");
doQuery();
//高亮显示新增的数据
//Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
//for (int i = 0; i < ultraGrid2.Rows.Count; i++)
//{
// row = ultraGrid2.Rows[i];
// if (row.Cells["CHEM_CODE"].Value.ToString().Equals(chenCode))
// {
// row.Activate();
// break;
// }
//}
}
/////
///// 获取Table中最大编号,自增1返回。
/////
/////
/////
//private static string AutoCode(DataTable dt)
//{
// int maxCode = 0;
// //substring去除S001中的S,得到001。
// string maxCodeString = dt.Rows[0][0].ToString().Substring(1);
// //是否为数字
// if (StringUtil.IsNumber(maxCodeString))
// {
// maxCode = Convert.ToInt32(maxCodeString);
// }
// else
// {
// MessageBox.Show("传入编号格式有误,请查看代码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// }
// //比较得出最大id。
// for (int i = 1; i < dt.Rows.Count; i++)
// {
// string maxCodeString_Two = dt.Rows[i][0].ToString().Substring(1);
// int maxCode_Two = 0;
// if (StringUtil.IsNumber(maxCodeString_Two))
// {
// maxCode_Two = Convert.ToInt32(maxCodeString_Two);
// if (maxCode_Two > maxCode)
// {
// maxCode = maxCode_Two;
// }
// }
// }
// //新增行
// maxCode += 1;
// string codeTop = "";
// if (maxCode < 10)
// {
// codeTop = "00";
// }
// else if (maxCode < 100)
// {
// codeTop = "0";
// }
// //获取头文字D。
// string d = dt.Rows[0][0].ToString().Substring(0, 1);
// //头文字+0+最大数字
// string newCode = d + codeTop + maxCode;
// return newCode;
//}
///
/// 验证高新编码是否重复。
///
///
///
private bool isRepeatCode(string code)
{
DataTable dt = new DataTable();
dt = ServerHelper.GetData("com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp.GetCode", new Object[] { code }, this.ob);
if (dt.Rows.Count > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 用于验证修改时,描述是否已存在
///
private static string VName = "";
///
/// 修改
///
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 CODE = GX_CODE.Text.Trim();
//if (!VName.Equals(CODE))
//{
// if (isRepeatCode(CODE))
// {
// MessageBox.Show("高新编码\"" + CODE + "\"已存在,请重新输入!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
// return;
// }
//}
//确认修改吗?
if (MessageBox.Show("是否确认修改选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
ArrayList parm = new ArrayList();
// string chenCode = ultraGrid2.ActiveRow.Cells["CHEM_CODE"].Value.ToString();
parm.Add(GX_NAME.Text.ToString2());
parm.Add(GX_YEAR.Text.ToString2());
parm.Add(this.UserInfo.GetUserName());
parm.Add(GX_Memo.Text);
parm.Add(GX_YFFY.Text.ToString2());
parm.Add(GX_FZR.Text.ToString2());
parm.Add(CODE);
CoreClientParam ccp = new CoreClientParam();
//ccp.ServerName = "com.steering.pss.qcm.CoreChemistryElements";
ccp.ServerName = "com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp";
ccp.MethodName = "doModify";
ccp.ServerParams = new object[] { parm };
ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal);
if (ccp.ReturnCode == -1) return;
MessageUtil.ShowTips("修改成功!");
doQuery();
//高亮显示新增的数据
Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
for (int i = 0; i < ultraGrid2.Rows.Count; i++)
{
row = ultraGrid2.Rows[i];
if (row.Cells["GX_CODE"].Value.ToString().Equals(CODE))
{
row.Activate();
break;
}
}
}
///
/// 查询
///
private void doQuery()
{
bool validFlag = chkValid.Checked;
string titleName = txtTitleName.Text.Trim();
DataTable dt = ServerHelper.GetData("com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp.getGXList", 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;
}
}
SetStaticsInfo();
//列自适应
GridHelper.RefreshAndAutoSizeExceptRows(ultraGrid2, new UltraGridColumn[] {
ultraGrid2.DisplayLayout.Bands[0].Columns["MEMO"]
});
}
///
/// GRID ROW激活时信息带至编辑区
///
///
///
private void ultraGrid2_AfterRowActivate(object sender, EventArgs e)
{
Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid2.ActiveRow;
if (row != null)
{
GX_CODE.Text = row.Cells["GX_CODE"].Value.ToString();
GX_NAME.Text = row.Cells["GX_NAME"].Value.ToString();
GX_YEAR.Text = row.Cells["GX_TIME"].Value.ToString();
GX_Memo.Text = row.Cells["MEMO"].Value.ToString();
GX_YFFY.Text = row.Cells["GX_YFFY"].Value.ToString();
GX_FZR.Text = row.Cells["GX_FZR"].Value.ToString();
}
}
///
/// 导出
///
private void ExportData()
{
GridHelper.ulGridToExcel(ultraGrid2, "高新项目管理");
}
private void SetStaticsInfo()
{
try
{
if (this.ultraGrid2.Rows.Count == 0)
{
this.ultraGrid2.DisplayLayout.Bands[0].Summaries.Clear();
}
else
{
ArrayList alist = new ArrayList();
alist.Add("GX_YFFY");
SetStaticsInfoSum(ref this.ultraGrid2, alist, true);
}
}
catch { }
}
public static void SetStaticsInfoSum(ref UltraGrid myGrid1, ArrayList alistColumns, bool clearExists)
{
try
{
UltraGridBand band = myGrid1.DisplayLayout.Bands[0];
if (clearExists)
band.Summaries.Clear();
band.Override.SummaryFooterCaptionVisible = Infragistics.Win.DefaultableBoolean.False;
for (int i = 0; i < alistColumns.Count; i++)
{
try
{
SummarySettings summary = band.Summaries.Add(SummaryType.Sum, band.Columns[alistColumns[i].ToString()]);
summary.SummaryDisplayArea = SummaryDisplayAreas.BottomFixed;
summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
if (alistColumns[i].ToString().Contains("COUNT"))
{
summary.DisplayFormat = "{0:N0}";
}
else
{
summary.DisplayFormat = "{0:N3}";
}
summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Right;
summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
// summary.Appearance.FontData.Bold = DefaultableBoolean.True;
summary.Lines = 3;
}
catch { }
}
}
catch { }
}
///
/// 作废或恢复
///
/// 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 CODE = ultraGrid2.ActiveRow.Cells["GX_CODE"].Value.ToString();
param.Add(CODE);
if (param.Count > 0 && MessageBox.Show("是否确认" + (isDelete ? "作废" : "恢复") + "选中的数据!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int count = ServerHelper.SetData("com.steering.pss.plnsaleord.GpOptimize.CorePlnZgMStoGp.deleteLineInfo", new Object[] { param, UserInfo.GetUserName(), isDelete }, this.ob);
if (count > 0)
{
MessageUtil.ShowTips((isDelete ? "作废" : "恢复") + "成功!");
doQuery();
Infragistics.Win.UltraWinGrid.UltraGridRow rowD = null;
for (int i = 0; i < ultraGrid2.Rows.Count; i++)
{
rowD = ultraGrid2.Rows[i];
if (rowD.Cells["GX_CODE"].Value.ToString().Equals(CODE))
{
rowD.Activate();
break;
}
}
}
}
}
}
}