using Core.Mes.Client.Comm.Control;
using Core.Mes.Client.Comm.Format;
using Core.Mes.Client.Comm.Server;
using Core.Mes.Client.Comm.Tool;
using Core.StlMes.Client.Qcm.model;
using CoreFS.CA06;
using Infragistics.Win.UltraWinEditors;
using Infragistics.Win.UltraWinGrid;
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace Core.StlMes.Client.Qcm
{
public partial class FrmComBaseWell : FrmBase
{
int _jic = 1;
string _wellname = "";
string errMessage = "";
private UltraComboEditor _cmbProcess = new UltraComboEditor();
public FrmComBaseWell()
{
InitializeComponent();
ExceptionHelper.RegistException();
}
private void InitUi()
{
_cmbProcess.Visible = false;
this.Controls.Add(_cmbProcess);
QcmBaseQuery.NitializeProcess(_cmbProcess, false, ob);
ultraGrid1.DisplayLayout.Bands[0].Columns["PROCESS_CDOE"].EditorComponent = _cmbProcess;
ultraGrid1.DisplayLayout.Bands[0].Columns["PROCESS_CDOE"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
}
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "Query":
DoQuery(true);
break;
case "Save":
DoSave();
break;
case "Delete":
DeleteOrResume(true);
break;
case "Resume":
DeleteOrResume(false);
break;
case "Invalid":
DoQuery(false);
break;
case "Close":
this.Close();
break;
}
}
///
/// 查询
///
private void DoQuery(Boolean flag)
{
string validFlag = "1";
if (!flag)
validFlag = "0";
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.getComBaseWellData", new Object[] { validFlag }, this.ob);
GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
SetUltraGridStyle();
UltraGridColumn[] col = new UltraGridColumn[] { ultraGrid1.DisplayLayout.Bands[0].Columns["MEMO"] };
GridHelper.RefreshAndAutoSizeExceptColumns(ultraGrid1, col);
UltraGridRow[] rows = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "WELL_NAME" }, new string[] { _wellname });
if (rows.Length > 0)
{
rows[0].Activate();
}
foreach (UltraGridRow row in ultraGrid1.Rows)
{
ControlGrid1Edit(row);
}
_wellname = "";
}
private void DoSave()
{
ultraGrid1.UpdateData();
ultraGrid2.UpdateData();
UltraGridRow ugr = ultraGrid1.ActiveRow;
ArrayList baseWell = new ArrayList();
ArrayList monthWell = new ArrayList();
int grid1Cnt = ultraGrid1.Rows.AsQueryable().Where("CHK = 'True'").Count();
int grid2Cnt = ultraGrid2.Rows.AsQueryable().Where("CHK = 'True'").Count();
if ((grid1Cnt + grid2Cnt) == 0)
{
MessageUtil.ShowWarning("请选择你要操作的记录!");
return;
}
ComBaseWellEntity com = GetBaseWell(ugr);
if (com == null) return;
if (!CheckWellData(com))
{
MessageUtil.ShowWarning(errMessage);
return;
}
_wellname = com.WellName;
baseWell.Add(JSONFormat.Format(com));
foreach (UltraGridRow row in ultraGrid2.Rows)
{
if (row.Cells["CHK"].Value.ToString() == "True")
{
ComBaseWellMonthEntity comm = GetMonthWell(row);
if (comm != null)
{
if (!CheckMonthData(comm, row))
{
MessageUtil.ShowWarning(errMessage);
return;
}
monthWell.Add(JSONFormat.Format(comm));
}
else
{
return;
}
}
}
if (MessageBox.Show("是否保存选择记录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
if (baseWell.Count > 0 || monthWell.Count > 0)
{
int count = ServerHelper.SetData("com.steering.pss.qcm.ComBaseWell.saveWell", new Object[] { baseWell, monthWell }, this.ob);
if (count > 0)
{
MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
DoQuery(true);
}
}
}
private ComBaseWellEntity GetBaseWell(UltraGridRow row)
{
if (row.Cells["WELL_NAME"].Value.ToString() == "")
{
MessageUtil.ShowWarning("请输入产能井描述!");
return null;
}
if (row.Cells["WEIGHT"].Value.ToString() == "")
{
MessageUtil.ShowWarning("请输入最大产能!");
return null;
}
ComBaseWellEntity com = new ComBaseWellEntity();
com.WellCode = row.Cells["WELL_CODE"].Value.ToString();
com.WellName = row.Cells["WELL_NAME"].Value.ToString();
com.Weight = row.Cells["WEIGHT"].Value.ToString();
com.CreateName = this.UserInfo.GetUserName();
com.Validflag = row.Cells["VALIDFLAGNAME"].Value.ToString();
com.UpdateName = UserInfo.GetUserName();
com.Memo = row.Cells["MEMO"].Value.ToString();
com.ProcessCdoe = row.GetValue("PROCESS_CDOE");
com.ProcessDesc = row.GetText("PROCESS_CDOE");
return com;
}
///
/// 检查标准数据
///
///
///
private bool CheckWellData(ComBaseWellEntity com)
{
if (com.Validflag.Equals("无效"))
{
errMessage = "无效记录不能操作";
return false;
}
//验证标准名称在ultraGrid1是否重复
UltraGridRow[] rows = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "WELL_NAME", "CHK" }, new string[] { com.WellName, "True" });
if (rows.Length > 1)
{
errMessage = "产能井描述:" + com.WellName + " 重复,请重新输入";
return false;
}
if (com.Validflag.Equals(""))
{
//验证标准名称在数据表是否重复
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkComBaseWell", new Object[] { com.WellName }, this.ob);
if (dt != null && dt.Rows.Count > 0)
{
errMessage = "产能井描述:" + com.WellName + " 重复,请重新输入";
return false;
}
}
else
{
//验证标准名称是否重复
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkBaseWellUpdate", new Object[] { com.WellName, com.WellCode }, this.ob);
if (dt != null && dt.Rows.Count > 0)
{
errMessage = "产能井描述:" + com.WellName + " 重复,请重新输入";
return false;
}
}
return true;
}
private bool CheckMonthData(ComBaseWellMonthEntity com, UltraGridRow row)
{
ultraGrid1.UpdateData();
UltraGridRow ugr = ultraGrid1.ActiveRow;
if (com.Validflag.Equals("无效"))
{
errMessage = "无效记录不能操作";
return false;
}
//验证标准名称在ultraGrid2是否重复
UltraGridRow[] rows = GridHelper.GetRowsWithKey(ultraGrid2, new string[] { "YEAR", "CHK" }, new string[] { com.Year, "True" });
if (rows.Length > 1)
{
errMessage = "年份:" + com.Year + " 重复,请重新输入";
return false;
}
if (com.Validflag.Equals(""))
{
//验证标准名称在数据表是否重复
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkYear", new Object[] { com.WellCode, com.Year }, this.ob);
if (dt != null && dt.Rows.Count > 0)
{
errMessage = "年份:" + com.Year + " 重复,请重新输入";
return false;
}
}
else
{
//验证标准名称是否重复
if (com.Year != row.GetValue("YEAR_OLD"))
{
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkYear", new Object[] { com.WellCode, com.Year }, this.ob);
if (dt != null && dt.Rows.Count > 0)
{
errMessage = "年份:" + com.Year + " 重复,请重新输入";
return false;
}
}
}
string weight = ugr.Cells["WEIGHT"].Value.ToString();
if (weight != "")
{
double wellNum = Convert.ToDouble(weight);
if (com.Month1 != "")
{
if (!StringUtil.IsNumber(com.Month1))
{
errMessage = "1月份的产能值请输入数字!";
return false;
}
if (Convert.ToDouble(com.Month1) > wellNum)
{
errMessage = "1月份的产能值不能超过最大产能值!";
return false;
}
}
if (com.Month2 != "")
{
if (!StringUtil.IsNumber(com.Month2))
{
errMessage = "2月份的产能值请输入数字!";
return false;
}
if (Convert.ToDouble(com.Month2) > wellNum)
{
errMessage = "2月份的产能值不能超过最大产能值!";
return false;
}
}
if (com.Month3 != "")
{
if (!StringUtil.IsNumber(com.Month3))
{
errMessage = "3月份的产能值请输入数字!";
return false;
}
if (Convert.ToDouble(com.Month3) > wellNum)
{
errMessage = "3月份的产能值不能超过最大产能值!";
return false;
}
}
if (com.Month4 != "")
{
if (!StringUtil.IsNumber(com.Month4))
{
errMessage = "4月份的产能值请输入数字!";
return false;
}
if (Convert.ToDouble(com.Month4) > wellNum)
{
errMessage = "4月份的产能值不能超过最大产能值!";
return false;
}
}
if (com.Month5 != "")
{
if (!StringUtil.IsNumber(com.Month5))
{
errMessage = "5月份的产能值请输入数字!";
return false;
}
if (Convert.ToDouble(com.Month5) > wellNum)
{
errMessage = "5月份的产能值不能超过最大产能值!";
return false;
}
}
if (com.Month6 != "")
{
if (!StringUtil.IsNumber(com.Month6))
{
errMessage = "6月份的产能值请输入数字!";
return false;
}
if (Convert.ToDouble(com.Month6) > wellNum)
{
errMessage = "6月份的产能值不能超过最大产能值!";
return false;
}
}
if (com.Month7 != "")
{
if (!StringUtil.IsNumber(com.Month7))
{
errMessage = "7月份的产能值请输入数字!";
return false;
}
if (Convert.ToDouble(com.Month7) > wellNum)
{
errMessage = "7月份的产能值不能超过最大产能值!";
return false;
}
}
if (com.Month8 != "")
{
if (!StringUtil.IsNumber(com.Month8))
{
errMessage = "8月份的产能值请输入数字!";
return false;
}
if (Convert.ToDouble(com.Month8) > wellNum)
{
errMessage = "8月份的产能值不能超过最大产能值!";
return false;
}
}
if (com.Month9 != "")
{
if (!StringUtil.IsNumber(com.Month9))
{
errMessage = "9月份的产能值请输入数字!";
return false;
}
if (Convert.ToDouble(com.Month9) > wellNum)
{
errMessage = "9月份的产能值不能超过最大产能值!";
return false;
}
}
if (com.Month10 != "")
{
if (!StringUtil.IsNumber(com.Month10))
{
errMessage = "10月份的产能值请输入数字!";
return false;
}
if (Convert.ToDouble(com.Month10) > wellNum)
{
errMessage = "10月份的产能值不能超过最大产能值!";
return false;
}
}
if (com.Month11 != "")
{
if (!StringUtil.IsNumber(com.Month11))
{
errMessage = "11月份的产能值请输入数字!";
return false;
}
if (Convert.ToDouble(com.Month11) > wellNum)
{
errMessage = "11月份的产能值不能超过最大产能值!";
return false;
}
}
if (com.Month12 != "")
{
if (!StringUtil.IsNumber(com.Month12))
{
errMessage = "12月份的产能值请输入数字!";
return false;
}
if (Convert.ToDouble(com.Month12) > wellNum)
{
errMessage = "12月份的产能值不能超过最大产能值!";
return false;
}
}
}
else
{
errMessage = "请维护产能井的最大产能!";
return false;
}
return true;
}
private ComBaseWellMonthEntity GetMonthWell(UltraGridRow row)
{
ComBaseWellMonthEntity com = new ComBaseWellMonthEntity();
if (row.Cells["YEAR"].Value.ToString() == "")
{
MessageUtil.ShowWarning("请选择年份!");
return null;
}
com.WellCode = row.Cells["Well_CODE"].Value.ToString();
com.WellName = row.Cells["WELL_NAME"].Value.ToString();
com.Year = row.Cells["YEAR"].Value.ToString();
com.Month1 = row.Cells["MONTH_1"].Value.ToString();
com.Month2 = row.Cells["MONTH_2"].Value.ToString();
com.Month3 = row.Cells["MONTH_3"].Value.ToString();
com.Month4 = row.Cells["MONTH_4"].Value.ToString();
com.Month5 = row.Cells["MONTH_5"].Value.ToString();
com.Month6 = row.Cells["MONTH_6"].Value.ToString();
com.Month7 = row.Cells["MONTH_7"].Value.ToString();
com.Month8 = row.Cells["MONTH_8"].Value.ToString();
com.Month9 = row.Cells["MONTH_9"].Value.ToString();
com.Month10 = row.Cells["MONTH_10"].Value.ToString();
com.Month11 = row.Cells["MONTH_11"].Value.ToString();
com.Month12 = row.Cells["MONTH_12"].Value.ToString();
com.CreateName = UserInfo.GetUserName();
com.UpdateName = UserInfo.GetUserName();
com.Validflag = row.GetValue("VALIDFLAG");
com.Memo = row.GetValue("MEMO");
com.YearOld = row.GetValue("YEAR_OLD");
return com;
}
///
/// 设置ultraGrid1行颜色
///
private void SetUltraGridStyle()
{
for (int i = 0; i < ultraGrid1.Rows.Count; i++)
{
Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid1.Rows[i];
if (!row.Cells["VALIDFLAGNAME"].Value.ToString().Equals("有效"))
{
row.Appearance.ForeColor = Color.Red;
}
else
{
row.Appearance.ForeColor = Color.Black;
}
}
}
private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
{
ultraGrid1.UpdateData();
UltraGridRow ugr = ultraGrid1.ActiveRow;
DataRow[] dr = dataTable1.Select("", "WELL_CODE DESC");
string jic = "";
string jicStr = "";
if (dr.Length > 0)
{
jic = dr[0]["WELL_CODE"].ToString();
}
if (!jic.Equals(""))
{
int number = int.Parse(jic.Substring(1, 3));
jicStr = "J" + string.Format("{0:000}", number + 1);
_jic = number + 1;
}
else
{
jicStr = "J" + string.Format("{0:000}", _jic);
_jic = _jic + 1;
}
//赋值理化索引号
ugr.Cells["WELL_CODE"].Value = jicStr;
ControlGrid1Edit(e.Row);
}
private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
{
ultraGrid1.UpdateData();
UltraGridRow ugr = ultraGrid1.ActiveRow;
for (int i = 0; i < ultraGrid1.Rows.Count; i++)
{
if (!ultraGrid1.Rows[i].Equals(ugr))
{
ultraGrid1.Rows[i].Cells["CHK"].Value = false;
}
}
if (ugr == null || ugr.GetValue("VALIDFLAGNAME") != "有效")
{
ultraGrid2.Enabled = false;
dataTable2.Clear();
return;
}
else
ultraGrid2.Enabled = true;
string wellcode = ugr.Cells["WELL_CODE"].Value.ToString();
QueryMonthWell(wellcode);
for (int i = 0; i < ultraGrid2.Rows.Count; i++)
{
Infragistics.Win.UltraWinGrid.UltraGridRow row = ultraGrid2.Rows[i];
if (!row.Cells["VALIDFLAG"].Value.ToString().Equals("有效"))
{
row.Appearance.ForeColor = Color.Red;
}
else
{
row.Appearance.ForeColor = Color.Black;
}
}
}
private void QueryMonthWell(string wellcode)
{
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.getMonthWell", new Object[] { wellcode }, this.ob);
GridHelper.CopyDataToDatatable(ref dt, ref dataTable2, true);
foreach (UltraGridRow row in ultraGrid2.Rows)
{
for (int i = 0; i < row.Cells.Count; i++)
{
if (!row.Cells[i].Column.Key.Equals("CHK"))
row.Cells[i].Activation = Activation.ActivateOnly;
}
}
}
private void ultraGrid2_AfterRowInsert(object sender, RowEventArgs e)
{
UltraGridRow ugr1 = ultraGrid1.ActiveRow;
UltraGridRow ugr2 = ultraGrid2.ActiveRow;
ugr2.Cells["WELL_CODE"].Value = ugr1.Cells["WELL_CODE"].Value.ToString();
ugr2.Cells["WELL_NAME"].Value = ugr1.Cells["WELL_NAME"].Value.ToString();
//增加行如果没有勾选则不可编辑
if (!Convert.ToBoolean(ugr2.Cells["CHK"].Value))
{
for (int i = 0; i < ugr2.Cells.Count; i++)
{
if (!ugr2.Cells[i].Column.Key.Equals("CHK"))
ugr2.Cells[i].Activation = Activation.ActivateOnly;
}
}
}
private void ultraGrid2_CellChange(object sender, CellEventArgs e)
{
ultraGrid2.UpdateData();
if (e.Cell.Column.Key.Equals("CHK"))
{
if (e.Cell.Value.ToString() == "True")
{
CellsCollection cells = e.Cell.Row.Cells;
for (int i = 0; i < cells.Count; i++)
{
if (!cells[i].Column.Key.Equals("CHK"))
{
e.Cell.Row.Cells[i].Activation = Activation.AllowEdit;
}
}
}
else
{
CellsCollection cells = e.Cell.Row.Cells;
for (int i = 0; i < cells.Count; i++)
{
if (!cells[i].Column.Key.Equals("CHK"))
{
e.Cell.Row.Cells[i].Activation = Activation.ActivateOnly;
}
}
}
}
}
private void InitYear()
{
UltraComboEditor uce = new UltraComboEditor();
DataTable dt = new DataTable();
dt.Columns.Add("YEAR", Type.GetType("System.Int32"));
for (int i = 2000; i <= 2100; i++)
dt.Rows.Add(new object[] { i });
uce.DataSource = dt;
uce.ValueMember = "YEAR";
uce.DisplayMember = "YEAR";
this.Controls.Add(uce);
uce.Visible = false;
ultraGrid2.DisplayLayout.Bands[0].Columns["YEAR"].EditorComponent = uce;
ultraGrid2.DisplayLayout.Bands[0].Columns["YEAR"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList;
}
private void FrmComBaseWell_Load(object sender, EventArgs e)
{
InitYear();
ultraGrid2.Enabled = false;
InitUi();
}
private int IsSelected()
{
int i = 0;
foreach (UltraGridRow row in ultraGrid1.Rows)
{
if (row.Cells["CHK"].Value.ToString() == "True")
i++;
}
foreach (UltraGridRow row in ultraGrid2.Rows)
{
if (row.Cells["CHK"].Value.ToString() == "True")
i++;
}
if (i > 0)
return 0;
else
return -1;
}
///
/// 检验作废或者恢复
///
/// 有效标识
///
///
private bool CheckDeleteOrResume(string valid, bool flag)
{
if (valid.Equals(""))
{
errMessage = "记录未保存,不能" + (flag ? "作废" : "恢复");
return false;
}
if (flag)
{
if (valid.Equals("无效"))
{
errMessage = "无效记录不能作废";
return false;
}
}
else
{
if (valid.Equals("有效"))
{
errMessage = "有效记录不能恢复";
return false;
}
}
return true;
}
private void DeleteOrResume(bool flag)
{
ultraGrid1.UpdateData();
ultraGrid2.UpdateData();
if (IsSelected() == -1)
{
MessageUtil.ShowWarning("请选择你要操作的记录!");
return;
}
//标准基础
ArrayList wellData = new ArrayList();
UltraGridRow[] rows = GridHelper.GetRowsWithKey(ultraGrid1, new string[] { "CHK" }, new string[] { "True" });
if (rows.Length > 0)
{
foreach (UltraGridRow ugr in rows)
{
ComBaseWellEntity com = GetBaseWell(ugr);
com.DeleteName = UserInfo.GetUserName();
wellData.Add(JSONFormat.Format(com));
if (!CheckDeleteOrResume(com.Validflag, flag))
{
MessageBox.Show(errMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
_wellname = com.WellName;
if (flag)
{
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkWellDelete", new Object[] { com.WellCode }, this.ob);
if (dt != null && dt.Rows.Count > 0 && Convert.ToInt32(dt.Rows[0][0]) > 0)
{
MessageBox.Show("产能井[ " + com.WellName + " ]已经被引用,不能作废!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
}
}
//产能井月量
ArrayList monthData = new ArrayList();
rows = GridHelper.GetRowsWithKey(ultraGrid2, new string[] { "CHK" }, new string[] { "True" });
if (rows.Length > 0)
{
foreach (UltraGridRow ugr in rows)
{
ComBaseWellMonthEntity com = GetMonthWell(ugr);
com.DeleteName = UserInfo.GetUserName();
monthData.Add(JSONFormat.Format(com));
if (!CheckDeleteOrResume(com.Validflag, flag))
{
MessageBox.Show(errMessage, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (flag)
{
//预留判断是否被引用
}
_wellname = com.WellName;
if (!flag)
{
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkFromResume", new Object[] { com.WellCode }, this.ob);
if (dt != null && dt.Rows.Count > 0)
{
MessageBox.Show("产能井 [ " + com.WellName + " ]已经作废,不能恢复!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
}
}
if (MessageBox.Show("是否" + (flag ? "作废" : "恢复") + "选择记录", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
if (wellData.Count > 0 || monthData.Count > 0)
{
int count = ServerHelper.SetData("com.steering.pss.qcm.ComBaseWell.deleteOrResume", new Object[] { wellData, monthData, flag }, this.ob);
if (count > 0)
{
MessageBox.Show((flag ? "作废" : "恢复") + "成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Question);
DoQuery(true);
}
}
}
private void ultraGrid1_CellChange(object sender, CellEventArgs e)
{
ultraGrid1.UpdateData();
if (e.Cell.Column.Key == "CHK")
{
ControlGrid1Edit(e.Cell.Row);
}
}
private void ControlGrid1Edit(UltraGridRow row)
{
if (row.GetValue("CHK") == "True")
{
row.Cells["WELL_NAME"].Activation = Activation.AllowEdit;
row.Cells["WEIGHT"].Activation = Activation.AllowEdit;
row.Cells["PROCESS_CDOE"].Activation = Activation.AllowEdit;
row.Cells["MEMO"].Activation = Activation.AllowEdit;
}
else
{
row.Cells["WELL_NAME"].Activation = Activation.ActivateOnly;
row.Cells["WEIGHT"].Activation = Activation.ActivateOnly;
row.Cells["PROCESS_CDOE"].Activation = Activation.ActivateOnly;
row.Cells["MEMO"].Activation = Activation.ActivateOnly;
}
}
}
}