/*******************************************************************************
* Copyright(c) 2014 dongke All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:FormUtility.cs
* 2.功能描述:窗体共通类
* 编辑履历:
* 作者 日期 版本 修改内容
* 陈冰 2014/9/2 1.00 新建
*******************************************************************************/
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dongke.IBOSS.PRD.Basics.BaseControls;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Client.Controls.FormCommon;
namespace Dongke.IBOSS.PRD.Client.Controls
{
///
/// 窗体共通类
///
public class FormUtility
{
///
/// 获取产品信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
public static DataTable BindGoodsRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue)
{
try
{
DataTable returnTable = new DataTable("dataTable");
F_SelectGoods frmSelectGoods = new F_SelectGoods();
frmSelectGoods.SetGoodsCode = codeValue;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
if ("GoodsCode".Equals(searchName))
{
frmSelectGoods.SetGoodsCode = rowItem.Cells[searchName].EditedFormattedValue + "";
}
else
{
return null;
}
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
rowItem.Cells[searchName].Value = codeValue;
}
return null;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
DialogResult dialogResult = frmSelectGoods.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = frmSelectGoods.SelTable;
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
dataGridView.Rows.RemoveAt(rowIndex);
}
returnTable = selDt.Copy();
if (selDt != null && selDt.Rows.Count != 0)
{
DataTable dgvTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["GoodsID"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
if (dgvTable != null)
{
for (int j = 0; j < dgvTable.Rows.Count; j++)
{
if (dgvTable.Rows[j].RowState != DataRowState.Deleted
&& selDt.Rows[i].RowState != DataRowState.Deleted
&& (Convert.ToInt32(selDt.Rows[i]["GoodsID"])
== Convert.ToInt32(dgvTable.Rows[j]["GoodsID"])))
{
isContinue = false;
break;
}
}
}
if (isContinue)
{
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
((DataTable)dataGridView.DataSource).Rows.Add(newRow);
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
}
else
{
rowItem.Cells[searchName].Value = codeValue;
DataTable tmpTable = (DataTable)dataGridView.DataSource;
if (string.IsNullOrEmpty(codeValue))
{
dataGridView.Rows.RemoveAt(rowItem.Index);
}
// 除去新行
for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
{
if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(tmpTable.Rows[i]["GoodsID"] + ""))
{
tmpTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取员工信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
/// 工号
public static DataTable BindStaffRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue, int userId, bool isSelectOne)
{
try
{
DataTable returnTable = new DataTable("dataTable");
S_CMN_010 frmCMN010 = new S_CMN_010();
frmCMN010.UserId = userId;
frmCMN010.IsSelectOne = isSelectOne;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
if ("StaffCode".Equals(searchName))
{
frmCMN010.StaffCode1 = rowItem.Cells[searchName].EditedFormattedValue + "";
}
else
{
return null;
}
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
rowItem.Cells[searchName].Value = codeValue;
}
return null;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
DialogResult dialogResult = frmCMN010.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = frmCMN010.SelTable;
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
//临时待修改
if (isSelectOne == true)
{
dataGridView.Rows[rowIndex].Cells["StaffCode"].Value = selDt.Rows[0]["StaffCode"].ToString();
dataGridView.Rows[rowIndex].Cells["StaffName"].Value = selDt.Rows[0]["StaffName"].ToString();
dataGridView.Rows[rowIndex].Cells["StaffId"].Value = selDt.Rows[0]["StaffId"].ToString();
dataGridView.Rows[rowIndex].Cells["JobsName"].Value = selDt.Rows[0]["JobsName"].ToString();
if (dataGridView.Columns["Jobs"] != null)
{
dataGridView.Rows[rowIndex].Cells["Jobs"].Value = selDt.Rows[0]["Jobs"].ToString();
}
if (dataGridView.Columns["StaffStatus"] != null)
{
dataGridView.Rows[rowIndex].Cells["StaffStatus"].Value = selDt.Rows[0]["StaffStatus"].ToString();
}
if (dataGridView.Columns["StaffStatusName"] != null)
{
dataGridView.Rows[rowIndex].Cells["StaffStatusName"].Value = selDt.Rows[0]["StaffStatusName"].ToString();
}
if (dataGridView.Columns["OrganizationName"] != null)
{
dataGridView.Rows[rowIndex].Cells["OrganizationName"].Value = selDt.Rows[0]["OrganizationName"].ToString();
}
return null;
}
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
dataGridView.Rows.RemoveAt(rowIndex);
}
returnTable = selDt.Copy();
if (selDt != null && selDt.Rows.Count != 0)
{
DataTable dgvTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["Staffid"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
if (dgvTable != null)
{
for (int j = 0; j < dgvTable.Rows.Count; j++)
{
if (dgvTable.Rows[j].RowState != DataRowState.Deleted
&& selDt.Rows[i].RowState != DataRowState.Deleted
&& (Convert.ToInt32(selDt.Rows[i]["Staffid"])
== Convert.ToInt32(dgvTable.Rows[j]["Staffid"])))
{
isContinue = false;
break;
}
}
}
if (isContinue)
{
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
((DataTable)dataGridView.DataSource).Rows.Add(newRow);
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
}
else
{
//临时待修改
if (isSelectOne == true)
{
dataGridView.Rows[rowIndex].Cells["StaffCode"].Value = "";
return null;
}
rowItem.Cells[searchName].Value = codeValue;
DataTable tmpTable = (DataTable)dataGridView.DataSource;
if (string.IsNullOrEmpty(codeValue))
{
dataGridView.Rows.RemoveAt(rowItem.Index);
}
// 除去新行
for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
{
if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(tmpTable.Rows[i]["Staffid"] + ""))
{
tmpTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取员工信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
/// 工号
public static DataTable BindClassStaffRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue, int userId, bool isSelectOne)
{
try
{
DataTable returnTable = new DataTable("dataTable");
S_CMN_010 frmCMN010 = new S_CMN_010();
frmCMN010.UserId = userId;
frmCMN010.IsSelectOne = isSelectOne;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
if ("StaffCode".Equals(searchName))
{
frmCMN010.StaffCode1 = rowItem.Cells[searchName].EditedFormattedValue + "";
}
else
{
return null;
}
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
rowItem.Cells[searchName].Value = codeValue;
}
return null;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
DialogResult dialogResult = frmCMN010.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = frmCMN010.SelTable;
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
//临时待修改
if (isSelectOne == true)
{
dataGridView.Rows[rowIndex].Cells["StaffCode"].Value = selDt.Rows[0]["StaffCode"].ToString();
dataGridView.Rows[rowIndex].Cells["StaffName"].Value = selDt.Rows[0]["StaffName"].ToString();
dataGridView.Rows[rowIndex].Cells["StaffId"].Value = selDt.Rows[0]["StaffId"].ToString();
dataGridView.Rows[rowIndex].Cells["SJobsName"].Value = selDt.Rows[0]["JobsName"].ToString();
if (dataGridView.Columns["Jobs"] != null)
{
dataGridView.Rows[rowIndex].Cells["Jobs"].Value = selDt.Rows[0]["Jobs"].ToString();
}
if (dataGridView.Columns["StaffStatus"] != null)
{
dataGridView.Rows[rowIndex].Cells["StaffStatus"].Value = selDt.Rows[0]["StaffStatus"].ToString();
}
if (dataGridView.Columns["StaffStatusName"] != null)
{
dataGridView.Rows[rowIndex].Cells["StaffStatusName"].Value = selDt.Rows[0]["StaffStatusName"].ToString();
}
if (dataGridView.Columns["OrganizationName"] != null)
{
dataGridView.Rows[rowIndex].Cells["OrganizationName"].Value = selDt.Rows[0]["OrganizationName"].ToString();
}
if (dataGridView.Columns["SOrganizationId"] != null)
{
dataGridView.Rows[rowIndex].Cells["SOrganizationId"].Value = selDt.Rows[0]["OrganizationID"].ToString();
}
return null;
}
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
dataGridView.Rows.RemoveAt(rowIndex);
}
returnTable = selDt.Copy();
if (selDt != null && selDt.Rows.Count != 0)
{
DataTable dgvTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["Staffid"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
if (dgvTable != null)
{
for (int j = 0; j < dgvTable.Rows.Count; j++)
{
if (dgvTable.Rows[j].RowState != DataRowState.Deleted
&& selDt.Rows[i].RowState != DataRowState.Deleted
&& (Convert.ToInt32(selDt.Rows[i]["Staffid"])
== Convert.ToInt32(dgvTable.Rows[j]["Staffid"])))
{
isContinue = false;
break;
}
}
}
if (isContinue)
{
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
((DataTable)dataGridView.DataSource).Rows.Add(newRow);
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
}
else
{
//临时待修改
if (isSelectOne == true)
{
dataGridView.Rows[rowIndex].Cells["StaffCode"].Value = "";
return null;
}
rowItem.Cells[searchName].Value = codeValue;
DataTable tmpTable = (DataTable)dataGridView.DataSource;
if (string.IsNullOrEmpty(codeValue))
{
dataGridView.Rows.RemoveAt(rowItem.Index);
}
// 除去新行
for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
{
if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(tmpTable.Rows[i]["Staffid"] + ""))
{
tmpTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取工号信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
public static DataTable BindUserRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue)
{
try
{
DataTable returnTable = new DataTable("dataTable");
S_CMN_013 frmSCMN013 = new S_CMN_013();
frmSCMN013.SetUserCode = codeValue;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
if ("UserCode".Equals(searchName))
{
frmSCMN013.SetUserCode = rowItem.Cells[searchName].EditedFormattedValue + "";
}
else
{
return null;
}
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
rowItem.Cells[searchName].Value = codeValue;
}
return null;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
DialogResult dialogResult = frmSCMN013.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = frmSCMN013.SelTable;
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
dataGridView.Rows.RemoveAt(rowIndex);
}
returnTable = selDt.Copy();
if (selDt != null && selDt.Rows.Count != 0)
{
DataTable dgvTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["UserID"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
if (dgvTable != null)
{
for (int j = 0; j < dgvTable.Rows.Count; j++)
{
if (dgvTable.Rows[j].RowState != DataRowState.Deleted
&& selDt.Rows[i].RowState != DataRowState.Deleted
&& (Convert.ToInt32(selDt.Rows[i]["UserID"])
== Convert.ToInt32(dgvTable.Rows[j]["UserID"])))
{
isContinue = false;
break;
}
}
}
if (isContinue)
{
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
((DataTable)dataGridView.DataSource).Rows.Add(newRow);
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
}
else
{
rowItem.Cells[searchName].Value = codeValue;
DataTable tmpTable = (DataTable)dataGridView.DataSource;
if (string.IsNullOrEmpty(codeValue))
{
dataGridView.Rows.RemoveAt(rowItem.Index);
}
// 除去新行
for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
{
if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(tmpTable.Rows[i]["UserID"] + ""))
{
tmpTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取工号信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
public static DataTable BindUserRowDataSource2(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue)
{
try
{
DataTable returnTable = new DataTable("dataTable");
S_CMN_013 frmSCMN013 = new S_CMN_013();
frmSCMN013.SetUserCode = codeValue;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
if ("UserCode1".Equals(searchName))
{
frmSCMN013.SetUserCode = rowItem.Cells[searchName].EditedFormattedValue + "";
}
else
{
return null;
}
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
rowItem.Cells[searchName].Value = codeValue;
}
return null;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
DialogResult dialogResult = frmSCMN013.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = frmSCMN013.SelTable;
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
dataGridView.Rows.RemoveAt(rowIndex);
}
returnTable = selDt.Copy();
if (selDt != null && selDt.Rows.Count != 0)
{
DataTable dgvTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["UserID"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
if (dgvTable != null)
{
for (int j = 0; j < dgvTable.Rows.Count; j++)
{
if (dgvTable.Rows[j].RowState != DataRowState.Deleted
&& selDt.Rows[i].RowState != DataRowState.Deleted
&& (Convert.ToInt32(selDt.Rows[i]["UserID"])
== Convert.ToInt32(dgvTable.Rows[j]["UserID"])))
{
isContinue = false;
break;
}
}
}
if (isContinue)
{
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
((DataTable)dataGridView.DataSource).Rows.Add(newRow);
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
}
else
{
rowItem.Cells[searchName].Value = codeValue;
DataTable tmpTable = (DataTable)dataGridView.DataSource;
if (string.IsNullOrEmpty(codeValue))
{
dataGridView.Rows.RemoveAt(rowItem.Index);
}
// 除去新行
for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
{
if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(tmpTable.Rows[i]["UserID"] + ""))
{
tmpTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取缺陷信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
public static DataTable BindDefectRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue)
{
try
{
DataTable returnTable = new DataTable("dataTable");
S_CMN_014 frmSCMN014 = new S_CMN_014();
frmSCMN014.SetDefectCode = codeValue;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
if ("DefectCode".Equals(searchName))
{
frmSCMN014.SetDefectCode = rowItem.Cells[searchName].EditedFormattedValue + "";
}
else
{
return null;
}
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
rowItem.Cells[searchName].Value = codeValue;
}
return null;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
DialogResult dialogResult = frmSCMN014.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = frmSCMN014.SelTable;
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
dataGridView.Rows.RemoveAt(rowIndex);
}
returnTable = selDt.Copy();
if (selDt != null && selDt.Rows.Count != 0)
{
DataTable dgvTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["DefectID"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
if (dgvTable != null)
{
for (int j = 0; j < dgvTable.Rows.Count; j++)
{
if (dgvTable.Rows[j].RowState != DataRowState.Deleted
&& selDt.Rows[i].RowState != DataRowState.Deleted
&& (Convert.ToInt32(selDt.Rows[i]["DefectID"])
== Convert.ToInt32(dgvTable.Rows[j]["DefectID"])))
{
isContinue = false;
break;
}
}
}
if (isContinue)
{
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
((DataTable)dataGridView.DataSource).Rows.Add(newRow);
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
}
else
{
rowItem.Cells[searchName].Value = codeValue;
DataTable tmpTable = (DataTable)dataGridView.DataSource;
if (string.IsNullOrEmpty(codeValue))
{
dataGridView.Rows.RemoveAt(rowItem.Index);
}
// 除去新行
for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
{
if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(tmpTable.Rows[i]["DefectID"] + ""))
{
tmpTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取缺陷信息后绑定数据源(列表可重复)
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
public static DataTable BindDefectRowRepeatDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue)
{
try
{
DataTable returnTable = new DataTable("dataTable");
S_CMN_014 frmSCMN014 = new S_CMN_014();
frmSCMN014.SetDefectCode = codeValue;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
if ("DefectCode".Equals(searchName) || "MissDefectCode".Equals(searchName))
{
frmSCMN014.SetDefectCode = rowItem.Cells[searchName].EditedFormattedValue + "";
}
else
{
return null;
}
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
rowItem.Cells[searchName].Value = codeValue;
}
return null;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
DialogResult dialogResult = frmSCMN014.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = frmSCMN014.SelTable;
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
dataGridView.Rows.RemoveAt(rowIndex);
}
returnTable = selDt.Copy();
if (selDt != null && selDt.Rows.Count != 0)
{
DataTable dgvTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["DefectID"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
//if (dgvTable != null)
//{
// for (int j = 0; j < dgvTable.Rows.Count; j++)
// {
// if (dgvTable.Rows[j].RowState != DataRowState.Deleted
// && selDt.Rows[i].RowState != DataRowState.Deleted
// )
// //&& (Convert.ToInt32(selDt.Rows[i]["DefectID"])
// //== Convert.ToInt32(dgvTable.Rows[j]["DefectID"])))
// {
// isContinue = false;
// break;
// }
// }
//}
if (isContinue)
{
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
((DataTable)dataGridView.DataSource).Rows.Add(newRow);
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
}
else
{
rowItem.Cells[searchName].Value = codeValue;
DataTable tmpTable = (DataTable)dataGridView.DataSource;
if (string.IsNullOrEmpty(codeValue))
{
dataGridView.Rows.RemoveAt(rowItem.Index);
}
// 除去新行
for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
{
if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(tmpTable.Rows[i]["DefectID"] + ""))
{
tmpTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取工种信息后绑定数据源(单条绑定)
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
public static DataTable BindJobsOneRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue)
{
try
{
DataTable returnTable = new DataTable("dataTable");
S_CMN_008 frmSCMN008 = new S_CMN_008();
frmSCMN008.SetJobsCode = codeValue;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
if ("JobsCode".Equals(searchName) || "MissJobsCode".Equals(searchName))
{
frmSCMN008.SetJobsCode = rowItem.Cells[searchName].EditedFormattedValue + "";
}
else
{
return null;
}
DialogResult dialogResult = frmSCMN008.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
foreach (DataColumn col in frmSCMN008.DataSource.Columns)
{
if (dataGridView.Columns.Contains(col.ColumnName))
{
rowItem.Cells[col.ColumnName].Value = frmSCMN008.JobsRow[col.ColumnName];
}
}
}
else
{
rowItem.Cells[searchName].Value = codeValue;
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取工种信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
public static DataTable BindJobsRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue)
{
try
{
DataTable returnTable = new DataTable("dataTable");
S_CMN_018 frmSCMN018 = new S_CMN_018();
frmSCMN018.SetJobsCode = codeValue;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
if ("JobsCode".Equals(searchName))
{
frmSCMN018.SetJobsCode = rowItem.Cells[searchName].EditedFormattedValue + "";
}
else
{
return null;
}
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
rowItem.Cells[searchName].Value = codeValue;
}
else
{
dataGridView.Rows.RemoveAt(rowIndex);
}
return null;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
DialogResult dialogResult = frmSCMN018.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = frmSCMN018.SelTable;
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
dataGridView.Rows.RemoveAt(rowIndex);
}
returnTable = selDt.Copy();
if (selDt != null && selDt.Rows.Count != 0)
{
DataTable dgvTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["JobsID"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
if (dgvTable != null)
{
for (int j = 0; j < dgvTable.Rows.Count; j++)
{
if (dgvTable.Rows[j].RowState != DataRowState.Deleted
&& selDt.Rows[i].RowState != DataRowState.Deleted
&& (Convert.ToInt32(selDt.Rows[i]["JobsID"])
== Convert.ToInt32(dgvTable.Rows[j]["JobsID"])))
{
isContinue = false;
break;
}
}
}
if (isContinue)
{
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
((DataTable)dataGridView.DataSource).Rows.Add(newRow);
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
}
else
{
rowItem.Cells[searchName].Value = codeValue;
DataTable tmpTable = (DataTable)dataGridView.DataSource;
if (string.IsNullOrEmpty(codeValue))
{
dataGridView.Rows.RemoveAt(rowItem.Index);
}
// 除去新行
for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
{
if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(tmpTable.Rows[i]["JobsID"] + ""))
{
tmpTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取员工信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
/// 工号
public static DataTable BindManagerRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue, int managerSalaryID, bool isSelectOne)
{
try
{
DataTable returnTable = new DataTable("dataTable");
TAT_CMN_001 frmCMN010 = new TAT_CMN_001();
frmCMN010.ManagerSalaryID = managerSalaryID;
frmCMN010.IsSelectOne = isSelectOne;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
if ("StaffCode".Equals(searchName))
{
frmCMN010.StaffCode1 = rowItem.Cells[searchName].EditedFormattedValue + "";
}
else
{
return null;
}
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
rowItem.Cells[searchName].Value = codeValue;
}
return null;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
DialogResult dialogResult = frmCMN010.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = frmCMN010.SelTable;
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
//临时待修改
if (isSelectOne == true)
{
dataGridView.Rows[rowIndex].Cells["StaffCode"].Value = selDt.Rows[0]["StaffCode"].ToString();
dataGridView.Rows[rowIndex].Cells["StaffName"].Value = selDt.Rows[0]["StaffName"].ToString();
dataGridView.Rows[rowIndex].Cells["StaffId"].Value = selDt.Rows[0]["StaffId"].ToString();
dataGridView.Rows[rowIndex].Cells["JobsName"].Value = selDt.Rows[0]["JobsName"].ToString();
if (dataGridView.Columns["Jobs"] != null)
{
dataGridView.Rows[rowIndex].Cells["Jobs"].Value = selDt.Rows[0]["Jobs"].ToString();
}
if (dataGridView.Columns["StaffStatus"] != null)
{
dataGridView.Rows[rowIndex].Cells["StaffStatus"].Value = selDt.Rows[0]["StaffStatus"].ToString();
}
if (dataGridView.Columns["StaffStatusName"] != null)
{
dataGridView.Rows[rowIndex].Cells["StaffStatusName"].Value = selDt.Rows[0]["StaffStatusName"].ToString();
}
if (dataGridView.Columns["OrganizationName"] != null)
{
dataGridView.Rows[rowIndex].Cells["OrganizationName"].Value = selDt.Rows[0]["OrganizationName"].ToString();
}
return null;
}
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
dataGridView.Rows.RemoveAt(rowIndex);
}
returnTable = selDt.Copy();
if (selDt != null && selDt.Rows.Count != 0)
{
DataTable dgvTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["Staffid"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
if (dgvTable != null)
{
for (int j = 0; j < dgvTable.Rows.Count; j++)
{
if (dgvTable.Rows[j].RowState != DataRowState.Deleted
&& selDt.Rows[i].RowState != DataRowState.Deleted
&& (Convert.ToInt32(selDt.Rows[i]["Staffid"])
== Convert.ToInt32(dgvTable.Rows[j]["Staffid"])))
{
isContinue = false;
break;
}
}
}
if (isContinue)
{
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
((DataTable)dataGridView.DataSource).Rows.Add(newRow);
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
}
else
{
//临时待修改
if (isSelectOne == true)
{
dataGridView.Rows[rowIndex].Cells["StaffCode"].Value = "";
return null;
}
rowItem.Cells[searchName].Value = codeValue;
DataTable tmpTable = (DataTable)dataGridView.DataSource;
if (string.IsNullOrEmpty(codeValue))
{
dataGridView.Rows.RemoveAt(rowItem.Index);
}
// 除去新行
for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
{
if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(tmpTable.Rows[i]["Staffid"] + ""))
{
tmpTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取工序信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
/// 多选标记
/// 工序数据源
public static DataTable BindtProcedureRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue, int flag, DataTable dataSource)
{
try
{
DataTable returnTable = new DataTable("dataTable");
S_CMN_016 frmSCMN016 = new S_CMN_016(flag);
frmSCMN016.SetJobsCode = codeValue;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
frmSCMN016.SetJobsCode = rowItem.Cells[searchName].EditedFormattedValue + "";
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
rowItem.Cells[searchName].Value = codeValue;
}
else
{
dataGridView.Rows.RemoveAt(rowItem.Index);
returnTable = (DataTable)dataGridView.DataSource;
}
return returnTable;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
frmSCMN016.DataSource = dataSource;
DialogResult dialogResult = frmSCMN016.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = new DataTable();
//判断是否多选
if (flag == 1)
{
selDt = frmSCMN016.dataDT;
string filter = "Sel = 1";
selDt.DefaultView.RowFilter = filter;
selDt = selDt.DefaultView.ToTable();
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
dataGridView.Rows.RemoveAt(rowIndex);
}
DataTable dgvTable = (DataTable)dataGridView.DataSource;
if (selDt != null && selDt.Rows.Count != 0)
{
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["ProcedureID"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
if (dgvTable != null)
{
for (int j = 0; j < dgvTable.Rows.Count; j++)
{
if (dgvTable.Rows[j].RowState != DataRowState.Deleted
&& selDt.Rows[i].RowState != DataRowState.Deleted
&& (Convert.ToInt32(selDt.Rows[i]["ProcedureID"])
== Convert.ToInt32(dgvTable.Rows[j]["ProcedureID"])))
{
isContinue = false;
break;
}
}
}
if (isContinue)
{
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
dgvTable.Rows.Add(newRow);
}
}
}
returnTable = dgvTable;
}
else
{
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
for (int i = rowIndex; i >= 0; i--)
{
dataGridView.Rows.RemoveAt(i);
}
}
DataTable dgvTable = (DataTable)dataGridView.DataSource;
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in dataSource.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& dataSource.Columns.Contains(column.ColumnName))
{
newRow[column.ColumnName] = dataSource.Rows[0][column.ColumnName];
}
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = false;
}
newRow["procedureID"] = frmSCMN016.ProductionLineRow["procedureID"].ToString();
newRow["procedureCode"] = frmSCMN016.ProductionLineRow["procedureCode"].ToString();
newRow["procedureName"] = frmSCMN016.ProductionLineRow["procedureName"].ToString();
if (dgvTable.Rows.Count > 0)
{
newRow["RptProcedureID"] = 0;
newRow["RptSProcedureID"] = 0;
}
dgvTable.Rows.Add(newRow);
returnTable = dgvTable;
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
else
{
if (string.IsNullOrEmpty(codeValue))
{
dataGridView.Rows.RemoveAt(rowItem.Index);
}
returnTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
{
if (returnTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(returnTable.Rows[i]["ProcedureID"] + ""))
{
returnTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
/// 获取窑炉信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
public static DataTable BindKilnRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue)
{
try
{
DataTable returnTable = new DataTable("dataTable");
S_CMN_023 frmSCMN023 = new S_CMN_023();
frmSCMN023.SetKilnCode = codeValue;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
if ("kilnCode".Equals(searchName))
{
frmSCMN023.SetKilnCode = rowItem.Cells[searchName].EditedFormattedValue + "";
}
else
{
return null;
}
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
rowItem.Cells[searchName].Value = codeValue;
}
return null;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
DialogResult dialogResult = frmSCMN023.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = frmSCMN023.SelTable;
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
dataGridView.Rows.RemoveAt(rowIndex);
}
returnTable = selDt.Copy();
if (selDt != null && selDt.Rows.Count != 0)
{
DataTable dgvTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["KilnID"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
if (dgvTable != null)
{
for (int j = 0; j < dgvTable.Rows.Count; j++)
{
if (dgvTable.Rows[j].RowState != DataRowState.Deleted
&& selDt.Rows[i].RowState != DataRowState.Deleted
&& (Convert.ToInt32(selDt.Rows[i]["KilnID"])
== Convert.ToInt32(dgvTable.Rows[j]["KilnID"])))
{
isContinue = false;
break;
}
}
}
if (isContinue)
{
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
((DataTable)dataGridView.DataSource).Rows.Add(newRow);
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
}
else
{
rowItem.Cells[searchName].Value = codeValue;
DataTable tmpTable = (DataTable)dataGridView.DataSource;
if (string.IsNullOrEmpty(codeValue))
{
dataGridView.Rows.RemoveAt(rowItem.Index);
}
// 除去新行
for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
{
if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(tmpTable.Rows[i]["KilnID"] + ""))
{
tmpTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 获取工号信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
public static DataTable BindUserRowDataSource_FunctionCode(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue)
{
try
{
DataTable returnTable = new DataTable("dataTable");
S_CMN_013 frmSCMN013 = new S_CMN_013();
frmSCMN013.SetUserCode = codeValue;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
if ("UserCode1".Equals(searchName))
{
frmSCMN013.SetUserCode = rowItem.Cells[searchName].EditedFormattedValue + "";
}
else
{
return null;
}
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
rowItem.Cells[searchName].Value = codeValue;
}
return null;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
DialogResult dialogResult = frmSCMN013.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = frmSCMN013.SelTable;
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
// 如果是进行修改的,需要清除当前行信息
if (dataGridView.Rows.Count > rowItem.Index)
{
dataGridView.Rows.RemoveAt(rowIndex);
}
returnTable = selDt.Copy();
if (selDt != null && selDt.Rows.Count != 0)
{
DataTable dgvTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["UserID"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
if (dgvTable != null)
{
for (int j = 0; j < dgvTable.Rows.Count; j++)
{
if (dgvTable.Rows[j].RowState != DataRowState.Deleted
&& selDt.Rows[i].RowState != DataRowState.Deleted
&& (Convert.ToInt32(selDt.Rows[i]["UserID"])
== Convert.ToInt32(dgvTable.Rows[j]["UserID"])))
{
isContinue = false;
break;
}
}
}
if (isContinue)
{
DataRow newRow = dgvTable.NewRow();
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
((DataTable)dataGridView.DataSource).Rows.Add(newRow);
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
}
else
{
rowItem.Cells[searchName].Value = codeValue;
DataTable tmpTable = (DataTable)dataGridView.DataSource;
if (string.IsNullOrEmpty(codeValue))
{
dataGridView.Rows.RemoveAt(rowItem.Index);
}
// 除去新行
for (int i = tmpTable.Rows.Count - 1; i >= 0; i--)
{
if (tmpTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(tmpTable.Rows[i]["UserID"] + ""))
{
tmpTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
// 工艺配置--工序
///
/// 获取工序信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
/// 多选标记
/// 工序数据源
public static DataTable BindtTransferProcedureRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue, int flag, DataTable dataSource)
{
try
{
DataTable returnTable = new DataTable("dataTable");
S_CMN_016 frmSCMN016 = new S_CMN_016(flag);
frmSCMN016.SetJobsCode = codeValue;
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
frmSCMN016.SetJobsCode = rowItem.Cells[searchName].EditedFormattedValue + "";
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
if (flag == 1)
{
rowItem.Cells[searchName].Value = codeValue;
}
else
{
rowItem.Cells[searchName].Value = "";
rowItem.Cells["PERPROCEDUREID"].Value = DBNull.Value;
}
}
else
{
dataGridView.Rows.RemoveAt(rowItem.Index);
returnTable = (DataTable)dataGridView.DataSource;
}
return returnTable;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
frmSCMN016.DataSource = dataSource;
DialogResult dialogResult = frmSCMN016.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = new DataTable();
//判断是否多选
if (flag == 1)
{
selDt = frmSCMN016.dataDT;
string filter = "Sel = 1";
selDt.DefaultView.RowFilter = filter;
selDt = selDt.DefaultView.ToTable();
if (selDt == null)
{
return null;
}
if ((DataTable)dataGridView.DataSource == null)
{
return null;
}
// 如果是进行修改的,需要清除当前行信息 wangx
DataTable dgvTable = (DataTable)dataGridView.DataSource;
bool isEdit = false;
if (dgvTable.Rows.Count > rowItem.Index)
{
//dataGridView.Rows.RemoveAt(rowIndex);
isEdit = true;
}
if (selDt != null && selDt.Rows.Count != 0)
{
// 除去新行
for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
{
if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(dgvTable.Rows[i]["ProcedureID"] + "")
&& string.IsNullOrEmpty(dgvTable.Rows[i]["PerprocedureID"] + "")
&& string.IsNullOrEmpty(dgvTable.Rows[i]["OUTTECDEPID"] + "")
&& string.IsNullOrEmpty(dgvTable.Rows[i]["INTECDEPID"] + "")
&& string.IsNullOrEmpty(dgvTable.Rows[i]["DisplayNo"] + ""))
{
dgvTable.Rows.RemoveAt(i);
}
}
// 除去新行 end
bool isContinue = true;
for (int i = 0; i < selDt.Rows.Count; i++)
{
isContinue = true;
////if (dgvTable != null)
////{
//// for (int j = 0; j < dgvTable.Rows.Count; j++)
//// {
//// if (dgvTable.Rows[j].RowState != DataRowState.Deleted
//// && selDt.Rows[i].RowState != DataRowState.Deleted
//// && (Convert.ToInt32(selDt.Rows[i]["ProcedureID"])
//// == Convert.ToInt32(dgvTable.Rows[j]["ProcedureID"].ToString() == "" ? 0 : dgvTable.Rows[j]["ProcedureID"])))
//// {
//// isContinue = false;
//// break;
//// }
//// }
////}
if (isContinue)
{
DataRow newRow = null;
bool isNewRow = true;
if (isEdit) //存在编辑行
{
if (i == 0)
{
newRow = dgvTable.Rows[rowIndex];
isNewRow = false;
}
else
{
newRow = dgvTable.NewRow();
}
}
else
{
newRow = dgvTable.NewRow();
}
foreach (DataColumn column in selDt.Columns)
{
if (dgvTable.Columns.Contains(column.ColumnName)
&& selDt.Columns.Contains(column.ColumnName)
&& !"Sel".Equals(column.ColumnName))
{
// 对应列名赋值
newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
}
}
// 是否有选择
if (dgvTable.Columns.Contains("Sel"))
{
newRow["Sel"] = 0;
}
foreach (DataColumn col in dgvTable.Columns)
{
col.AllowDBNull = true;
}
if (isNewRow)
//if (dgvTable.Rows.Count <= rowItem.Index)
dgvTable.Rows.Add(newRow);
}
}
}
returnTable = dgvTable;
// 除去新行
for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
{
if (returnTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(returnTable.Rows[i]["ProcedureID"] + "")
&& string.IsNullOrEmpty(dgvTable.Rows[i]["PerprocedureID"] + "")
&& string.IsNullOrEmpty(dgvTable.Rows[i]["OUTTECDEPID"] + "")
&& string.IsNullOrEmpty(dgvTable.Rows[i]["INTECDEPID"] + "")
&& string.IsNullOrEmpty(dgvTable.Rows[i]["DisplayNo"] + ""))
{
returnTable.Rows.RemoveAt(i);
}
}
}
else
{
// 如果是进行修改的,需要清除当前行信息
DataTable dgvTable = (DataTable)dataGridView.DataSource;
bool isEdit = false;
if (dgvTable.Rows.Count > rowItem.Index)
{
isEdit = true;
//for (int i = rowIndex; i > 0; i--)
//{
// dataGridView.Rows.RemoveAt(i);
//}
}
DataRow newRow = null;
if (isEdit)
{
newRow = dgvTable.Rows[rowIndex];
}
else
{
newRow = dgvTable.NewRow();
}
//foreach (DataColumn column in dataSource.Columns)
//{
// if (dgvTable.Columns.Contains(column.ColumnName)
// && dataSource.Columns.Contains(column.ColumnName))
// {
// newRow[column.ColumnName] = dataSource.Rows[0][column.ColumnName];
// }
//}
//foreach (DataColumn col in dgvTable.Columns)
//{
// col.AllowDBNull = false;
//}
newRow["PerprocedureID"] = frmSCMN016.ProductionLineRow["procedureID"].ToString();
//newRow["procedureCode"] = frmSCMN016.ProductionLineRow["procedureCode"].ToString();
newRow["PerprocedureName"] = frmSCMN016.ProductionLineRow["procedureName"].ToString();
//if (dgvTable.Rows.Count > 0)
//{
// newRow["RptProcedureID"] = 0;
// newRow["RptSProcedureID"] = 0;
//}
if (!isEdit)
{
dgvTable.Rows.Add(newRow);
}
returnTable = dgvTable;
// 除去新行
if (!isEdit)
{
for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
{
if (returnTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(returnTable.Rows[i]["PerprocedureID"] + "") && i > rowIndex)
{
returnTable.Rows.RemoveAt(i);
}
}
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
else
{
rowItem.Cells[searchName].Value = codeValue;
if (string.IsNullOrEmpty(codeValue))
{
//dataGridView.Rows.RemoveAt(rowItem.Index);
}
returnTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
{
if (returnTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(returnTable.Rows[i]["ProcedureID"] + "")
&& string.IsNullOrEmpty(returnTable.Rows[i]["PerprocedureID"] + "")
&& string.IsNullOrEmpty(returnTable.Rows[i]["OUTTECDEPID"] + "")
&& string.IsNullOrEmpty(returnTable.Rows[i]["INTECDEPID"] + "")
&& string.IsNullOrEmpty(returnTable.Rows[i]["DisplayNo"] + ""))
{
returnTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
// 工艺配置--组织机构(出)
///
/// 获取组织机构信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
/// 多选标记
/// 工序数据源
public static DataTable BindtTransferOutOrganizationRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue, int flag, DataTable dataSource)
{
try
{
DataTable returnTable = new DataTable("dataTable");
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
S_CMN_027 frmSCMN001 = new S_CMN_027(flag, rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim());
// frmSCMN001.CurrentUserOrganizationCode = codeValue;
//frmSCMN001.CurrentUserOrganizationCode = rowItem.Cells[searchName].EditedFormattedValue + "";
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
//rowItem.Cells[searchName].Value = codeValue;
rowItem.Cells[searchName].Value = "";
rowItem.Cells["OUTTECDEPID"].Value = DBNull.Value;
}
else
{
dataGridView.Rows.RemoveAt(rowItem.Index);
returnTable = (DataTable)dataGridView.DataSource;
}
return returnTable;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
frmSCMN001.DataSource = dataSource;
DialogResult dialogResult = frmSCMN001.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = new DataTable();
//判断是否多选
if (flag == 1)
{
//selDt = frmSCMN001.dataDT;
//string filter = "Sel = 1";
//selDt.DefaultView.RowFilter = filter;
//selDt = selDt.DefaultView.ToTable();
//if (selDt == null)
//{
// return null;
//}
//if ((DataTable)dataGridView.DataSource == null)
//{
// return null;
//}
//// 如果是进行修改的,需要清除当前行信息 wangx
//DataTable dgvTable = (DataTable)dataGridView.DataSource;
//bool isEdit = false;
//if (dgvTable.Rows.Count > rowItem.Index)
//{
// //dataGridView.Rows.RemoveAt(rowIndex);
// isEdit = true;
//}
//if (selDt != null && selDt.Rows.Count != 0)
//{
// // 除去新行
// for (int i = dgvTable.Rows.Count - 1; i >= 0; i--)
// {
// if (dgvTable.Rows[i].RowState == DataRowState.Deleted)
// {
// continue;
// }
// if (string.IsNullOrEmpty(dgvTable.Rows[i]["ProcedureID"] + "")
// && string.IsNullOrEmpty(dgvTable.Rows[i]["PerprocedureID"] + ""))
// {
// dgvTable.Rows.RemoveAt(i);
// }
// }
// // 除去新行 end
// bool isContinue = true;
// for (int i = 0; i < selDt.Rows.Count; i++)
// {
// isContinue = true;
// if (dgvTable != null)
// {
// for (int j = 0; j < dgvTable.Rows.Count; j++)
// {
// if (dgvTable.Rows[j].RowState != DataRowState.Deleted
// && selDt.Rows[i].RowState != DataRowState.Deleted
// && (Convert.ToInt32(selDt.Rows[i]["ProcedureID"])
// == Convert.ToInt32(dgvTable.Rows[j]["ProcedureID"].ToString() == "" ? 0 : dgvTable.Rows[j]["ProcedureID"])))
// {
// isContinue = false;
// break;
// }
// }
// }
// if (isContinue)
// {
// DataRow newRow = null;
// bool isNewRow = true;
// if (isEdit) //存在编辑行
// {
// if (i == 0)
// {
// newRow = dgvTable.Rows[rowIndex];
// isNewRow = false;
// }
// else
// {
// newRow = dgvTable.NewRow();
// }
// }
// else
// {
// newRow = dgvTable.NewRow();
// }
// foreach (DataColumn column in selDt.Columns)
// {
// if (dgvTable.Columns.Contains(column.ColumnName)
// && selDt.Columns.Contains(column.ColumnName)
// && !"Sel".Equals(column.ColumnName))
// {
// // 对应列名赋值
// newRow[column.ColumnName] = selDt.Rows[i][column.ColumnName];
// }
// }
// // 是否有选择
// if (dgvTable.Columns.Contains("Sel"))
// {
// newRow["Sel"] = 0;
// }
// foreach (DataColumn col in dgvTable.Columns)
// {
// col.AllowDBNull = true;
// }
// if (isNewRow)
// //if (dgvTable.Rows.Count <= rowItem.Index)
// dgvTable.Rows.Add(newRow);
// }
// }
//}
//returnTable = dgvTable;
//// 除去新行
//for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
//{
// if (returnTable.Rows[i].RowState == DataRowState.Deleted)
// {
// continue;
// }
// if (string.IsNullOrEmpty(returnTable.Rows[i]["ProcedureID"] + ""))
// {
// returnTable.Rows.RemoveAt(i);
// }
//}
}
else
{
// 如果是进行修改的,需要清除当前行信息
DataTable dgvTable = (DataTable)dataGridView.DataSource;
bool isEdit = false;
if (dgvTable.Rows.Count > rowItem.Index)
{
isEdit = true;
}
DataRow newRow = null;
if (isEdit)
{
newRow = dgvTable.Rows[rowIndex];
}
else
{
newRow = dgvTable.NewRow();
}
//foreach (DataColumn column in dataSource.Columns)
//{
// if (dgvTable.Columns.Contains(column.ColumnName)
// && dataSource.Columns.Contains(column.ColumnName))
// {
// newRow[column.ColumnName] = dataSource.Rows[0][column.ColumnName];
// }
//}
//foreach (DataColumn col in dgvTable.Columns)
//{
// col.AllowDBNull = false;
//}
newRow["OUTTECDEPID"] = frmSCMN001.OrganizationRow["ID"].ToString();
//newRow["procedureCode"] = frmSCMN016.ProductionLineRow["procedureCode"].ToString();
newRow["outName"] = frmSCMN001.OrganizationRow["Name"].ToString();
//if (dgvTable.Rows.Count > 0)
//{
// newRow["RptProcedureID"] = 0;
// newRow["RptSProcedureID"] = 0;
//}
if (!isEdit)
{
dgvTable.Rows.Add(newRow);
}
returnTable = dgvTable;
// 除去新行
if (!isEdit)
{
for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
{
if (returnTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(returnTable.Rows[i]["OUTTECDEPID"] + "") && i > rowIndex)
{
returnTable.Rows.RemoveAt(i);
}
}
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
else
{
rowItem.Cells[searchName].Value = codeValue;
if (string.IsNullOrEmpty(codeValue))
{
//dataGridView.Rows.RemoveAt(rowItem.Index);
}
returnTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
{
if (returnTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(returnTable.Rows[i]["ProcedureID"] + "")
&& string.IsNullOrEmpty(returnTable.Rows[i]["PerprocedureID"] + "")
&& string.IsNullOrEmpty(returnTable.Rows[i]["OUTTECDEPID"] + "")
&& string.IsNullOrEmpty(returnTable.Rows[i]["INTECDEPID"] + "")
&& string.IsNullOrEmpty(returnTable.Rows[i]["DisplayNo"] + ""))
{
returnTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
// 工艺配置--组织机构(出)
///
/// 获取组织机构信息后绑定数据源
///
/// 绑定的列表对象
/// 行号
/// 列名
/// 该列原来的值
/// 多选标记
/// 工序数据源
public static DataTable BindtTransferInOrganizationRowDataSource(C_DataGridView dataGridView, int rowIndex,
string searchName, string codeValue, int flag, DataTable dataSource)
{
try
{
DataTable returnTable = new DataTable("dataTable");
DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
int columnIndex = dataGridView.CurrentCell.ColumnIndex;
S_CMN_027 frmSCMN001 = new S_CMN_027(flag, rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim());
//S_CMN_027 frmSCMN001 = new S_CMN_027(flag);
//// frmSCMN001.CurrentUserOrganizationCode = codeValue;
//DataGridViewRow rowItem = dataGridView.Rows[rowIndex];
//int columnIndex = dataGridView.CurrentCell.ColumnIndex;
//frmSCMN001.CurrentUserOrganizationCode = rowItem.Cells[searchName].EditedFormattedValue + "";
if (rowItem.Cells[searchName].EditedFormattedValue == null ||
string.IsNullOrEmpty(rowItem.Cells[searchName].EditedFormattedValue.ToString().Trim()))
{
if (!string.IsNullOrEmpty(codeValue))
{
//rowItem.Cells[searchName].Value = codeValue;
rowItem.Cells[searchName].Value = "";
rowItem.Cells["INTECDEPID"].Value = DBNull.Value;
}
else
{
dataGridView.Rows.RemoveAt(rowItem.Index);
returnTable = (DataTable)dataGridView.DataSource;
}
return returnTable;
}
// 防止2次关闭才能关掉
if (codeValue == rowItem.Cells[searchName].Value + "")
{
return null;
}
frmSCMN001.DataSource = dataSource;
DialogResult dialogResult = frmSCMN001.ShowDialog();
// 只有点确定时才进行下面的操作
if (dialogResult.Equals(DialogResult.OK))
{
DataTable selDt = new DataTable();
// 如果是进行修改的,需要清除当前行信息
DataTable dgvTable = (DataTable)dataGridView.DataSource;
bool isEdit = false;
if (dgvTable.Rows.Count > rowItem.Index)
{
isEdit = true;
}
DataRow newRow = null;
if (isEdit)
{
newRow = dgvTable.Rows[rowIndex];
}
else
{
newRow = dgvTable.NewRow();
}
//foreach (DataColumn column in dataSource.Columns)
//{
// if (dgvTable.Columns.Contains(column.ColumnName)
// && dataSource.Columns.Contains(column.ColumnName))
// {
// newRow[column.ColumnName] = dataSource.Rows[0][column.ColumnName];
// }
//}
//foreach (DataColumn col in dgvTable.Columns)
//{
// col.AllowDBNull = false;
//}
newRow["INTECDEPID"] = frmSCMN001.OrganizationRow["ID"].ToString();
//newRow["procedureCode"] = frmSCMN016.ProductionLineRow["procedureCode"].ToString();
newRow["InName"] = frmSCMN001.OrganizationRow["Name"].ToString();
//if (dgvTable.Rows.Count > 0)
//{
// newRow["RptProcedureID"] = 0;
// newRow["RptSProcedureID"] = 0;
//}
if (!isEdit)
{
dgvTable.Rows.Add(newRow);
}
returnTable = dgvTable;
// 除去新行
if (!isEdit)
{
for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
{
if (returnTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(returnTable.Rows[i]["INTECDEPID"] + "") && i > rowIndex)
{
returnTable.Rows.RemoveAt(i);
}
}
}
dataGridView.CurrentCell = dataGridView.Rows[rowIndex].Cells[columnIndex];
dataGridView.ProcessRightKey(Keys.Enter);
}
else
{
rowItem.Cells[searchName].Value = codeValue;
if (string.IsNullOrEmpty(codeValue))
{
//dataGridView.Rows.RemoveAt(rowItem.Index);
}
returnTable = (DataTable)dataGridView.DataSource;
// 除去新行
for (int i = returnTable.Rows.Count - 1; i >= 0; i--)
{
if (returnTable.Rows[i].RowState == DataRowState.Deleted)
{
continue;
}
if (string.IsNullOrEmpty(returnTable.Rows[i]["ProcedureID"] + "")
&& string.IsNullOrEmpty(returnTable.Rows[i]["PerprocedureID"] + "")
&& string.IsNullOrEmpty(returnTable.Rows[i]["OUTTECDEPID"] + "")
&& string.IsNullOrEmpty(returnTable.Rows[i]["INTECDEPID"] + "")
&& string.IsNullOrEmpty(returnTable.Rows[i]["DisplayNo"] + ""))
{
returnTable.Rows.RemoveAt(i);
}
}
}
return returnTable;
}
catch (Exception ex)
{
throw ex;
}
}
}
}