using Core.Mes.Client.Comm.Control;
using Core.Mes.Client.Comm.Server;
using Core.Mes.Client.Comm.Tool;
using CoreFS.CA06;
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace Core.StlMes.Client.Qcm
{
public partial class ComBaseWell : FrmBase
{
private string errMessage = "";
public ComBaseWell()
{
InitializeComponent();
}
public override void ToolBar_Click(object sender, string ToolbarKey)
{
switch (ToolbarKey)
{
case "Query":
DoQuery();
break;
case "Add":
DoAdd();
break;
case "Update":
DoUpdate();
break;
case "Delete":
DoDelete();
break;
case "Resume":
DoResume();
break;
case "Close":
this.Close();
break;
}
}
///
/// 查询
///
private void DoQuery()
{
string validFlag = "1";
if (this.ultraCheckEditor1.Checked)
validFlag = "0";
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.getComBaseWellData", new Object[] { validFlag }, this.ob);
if (dt != null && dt.Rows.Count > 0)
{
GridHelper.CopyDataToDatatable(ref dt, ref this.dataTable1, true);
SetUltraGridStyle();
}
}
///
///检查 增加数据
///
///
private ArrayList CheckAddColumns()
{
ArrayList list = new ArrayList();
string wellCode = this.ultraTextEditor1.Text.Trim().ToString();
if (wellCode.Length == 0 || wellCode.Length > 20 || !StringUtil.IsOnlyLetterAndDigit(wellCode))
{
errMessage = "产能井代码:1-20位有效数字与字母组成";
return null;
}
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkComBaseWell", new Object[] { wellCode }, this.ob);
if (dt != null && dt.Rows.Count > 0)
{
errMessage = "存在相同的产能井代码";
return null;
}
string wellName = this.ultraTextEditor2.Text.Trim().ToString();
if (wellName.Length == 0 || wellName.Length > 100)
{
errMessage = "产能井代码:1-50字母或者汉字组成";
return null;
}
string weight = this.ultraTextEditor3.Text.Trim().ToString();
if (weight.Length == 0 || !StringUtil.IsNumber(weight))
{
errMessage = "最大产能:数字组成,不能为空";
return null;
}
string memo = this.ultraTextEditor4.Text.Trim().ToString();
string userName = UserInfo.GetUserName();
list.Add(wellCode);
list.Add(wellName);
list.Add(weight);
list.Add(memo);
list.Add(userName);
return list;
}
///
/// 增加
///
private void DoAdd()
{
ArrayList listParams = CheckAddColumns();
if (listParams == null)
{
MessageBox.Show(errMessage, "提示");
return;
}
int count = ServerHelper.SetData("com.steering.pss.qcm.ComBaseWell.addComBaseWell", new Object[] { listParams }, this.ob);
if (count > 0)
{
DoQuery();
}
}
private ArrayList CheckUpdate()
{
ArrayList list = new ArrayList();
string wellName = this.ultraTextEditor2.Text.Trim().ToString();
if (wellName.Length == 0 || wellName.Length > 100)
{
errMessage = "产能井代码:1-50字母或者汉字组成";
return null;
}
string weight = this.ultraTextEditor3.Text.Trim().ToString();
if (weight.Length == 0 || !StringUtil.IsNumber(weight))
{
errMessage = "最大产能:数字组成,不能为空";
return null;
}
string memo = this.ultraTextEditor4.Text.Trim().ToString();
string userName = UserInfo.GetUserName();
string wellCode = this.ultraTextEditor1.Text.Trim().ToString();
if (wellCode.Length == 0 || wellCode.Length > 20 || !StringUtil.IsOnlyLetterAndDigit(wellCode))
{
errMessage = "产能井代码:1-20位有效数字与字母组成";
return null;
}
DataTable dt = ServerHelper.GetData("com.steering.pss.qcm.ComBaseWell.checkComBaseWell", new Object[] { wellCode }, this.ob);
if (dt == null || dt.Rows.Count == 0)
{
errMessage = "不存在的产能井代码";
return null;
}
list.Add(wellName);
list.Add(weight);
list.Add(memo);
list.Add(userName);
list.Add(wellCode);
return list;
}
///
/// 修改
///
private void DoUpdate()
{
ArrayList listParams = CheckUpdate();
if (listParams == null)
{
MessageBox.Show(errMessage, "提示");
return;
}
string wellCode = this.ultraTextEditor1.Text.Trim().ToString();
int count = ServerHelper.SetData("com.steering.pss.qcm.ComBaseWell.updateBaseWell", new Object[] { listParams }, this.ob);
if (count > 0)
{
DoQuery();
Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
for (int i = 0; i < ultraGrid1.Rows.Count; i++)
{
row = ultraGrid1.Rows[i];
if (row.Cells["WELL_CODE"].Value.ToString().Equals(wellCode))
{
row.Activate();
break;
}
}
}
else
{
MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
///
/// 删除
///
private void DoDelete()
{
if (MessageBox.Show("删除记录,您是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
string wellCode = ultraTextEditor1.Text.Trim().ToString();
string deleteName = UserInfo.GetUserName();
string validflag = ultraGrid1.DisplayLayout.ActiveRow.Cells["VALIDFLAGNAME"].Text.Trim().ToString();
if (wellCode.Length == 0 || validflag.Equals("无效"))
{
MessageBox.Show("请选取删除有效记录或者请输入删除人!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
int count = ServerHelper.SetData("com.steering.pss.qcm.ComBaseWell.deleteComBaseWell", new Object[] { deleteName, wellCode }, this.ob);
if (count > 0)
{
DoQuery();
SetActiveRow(wellCode);
}
else
{
MessageBox.Show("删除失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
///
/// 恢复数据
///
private void DoResume()
{
if (MessageBox.Show("恢复记录,您是否继续?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
string wellCode = ultraTextEditor1.Text.Trim().ToString();
string validflag = ultraGrid1.DisplayLayout.ActiveRow.Cells["VALIDFLAGNAME"].Text.Trim().ToString();
if (wellCode.Length == 0 || validflag.Equals("有效"))
{
MessageBox.Show("请选取需要恢复的无效记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
int count = ServerHelper.SetData("com.steering.pss.qcm.ComBaseWell.resumeComBaseWell", new Object[] { wellCode }, this.ob);
if (count > 0)
{
DoQuery();
SetActiveRow(wellCode);
}
else
{
MessageBox.Show("恢复失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
}
///
/// 激活行编辑区赋值
///
///
///
private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
{
this.ultraTextEditor1.Value = ultraGrid1.DisplayLayout.ActiveRow.Cells["WELL_CODE"].Text.ToString();
this.ultraTextEditor2.Value = ultraGrid1.DisplayLayout.ActiveRow.Cells["WELL_NAME"].Text.ToString();
this.ultraTextEditor3.Value = ultraGrid1.DisplayLayout.ActiveRow.Cells["WEIGHT"].Text.ToString();
this.ultraTextEditor4.Value = ultraGrid1.DisplayLayout.ActiveRow.Cells["MEMO"].Text.ToString();
}
///
/// 设置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 SetActiveRow(string wellCode)
{
Infragistics.Win.UltraWinGrid.UltraGridRow row = null;
for (int i = 0; i < ultraGrid1.Rows.Count; i++)
{
row = ultraGrid1.Rows[i];
if (row.Cells["WELL_CODE"].Value.ToString().Equals(wellCode))
{
row.Activate();
break;
}
}
}
/////
///// 操作数项
/////
/////
//private ComBaseWellObject GetOptionData()
//{
// ComBaseWellObject cbw = new ComBaseWellObject();
// cbw.WellCode = ultraTextEditor1.Text.Trim().ToString();
// cbw.WellName = ultraTextEditor2.Text.Trim().ToString();
// cbw.Weight = ultraTextEditor3.Text.Trim().ToString();
// cbw.Memo = ultraTextEditor4.Text.Trim().ToString();
// return cbw;
//}
//private void DoAdd1()
//{
// ComBaseWellObject cbw = GetOptionData();
// cbw.CreateName = UserInfo.GetUserName();
// cbw.CreateTime = System.DateTime.Now.ToString();
// int count = ServerHelper.SetData("com.steering.pss.qcm.ComBaseWell.addComBaseWell1", new Object[] { JSONFormat.Format(cbw) }, this.ob);
//}
}
}