SVN-Revision: r860
This commit is contained in:
wyf
2025-07-16 08:04:22 +00:00
parent eb41c7c1e4
commit c7318bf0b5
+227 -123
View File
@@ -2030,134 +2030,238 @@ namespace Lskj.PubBomAlter
/// <param name="e"></param>
private void OnBtnFxSaveClick(object sender, EventArgs e)
{
DataTable sourceTable = treeGridControlEx.GridControl.DataSourceTable();
foreach (DataRow sourceRow in sourceTable.Rows)
WaitForm.ShowForm("正在保存数据...");
try
{
string xgtigName = $"{sysModel.PrefixKey}xgtig";
if (sourceRow.Table.Columns.Contains(xgtigName) && (sourceRow[xgtigName] + "").Equals("1"))
DataTable sourceTable = treeGridControlEx.TreeListObj.DataSource as DataTable;
string pattern = @"(\w+)\((.*?)\)";
Regex regex = new Regex(pattern);
Match match = regex.Match(BomAlterModel.VerifySql);
if (match.Success)
{
if (sourceTable.Columns.Contains("Plm_lmb_SmartBmFa"))
string functionName = match.Groups[1].Value;
string parameters = match.Groups[2].Value;
if (!string.IsNullOrEmpty(functionName))
{
string projectId = sourceRow["Plm_lmb_SmartBmFa"] + "";
if (!string.IsNullOrEmpty(projectId))
DataTable sqlParametersTab = BaseImpl.GetDataTableResult($"SELECT PARAMETER_NAME,PARAMETER_MODE,CHARACTER_MAXIMUM_LENGTH,DATA_TYPE FROM INFORMATION_SCHEMA.PARAMETERS WHERE SPECIFIC_NAME = '{functionName}' ORDER BY ORDINAL_POSITION;");
foreach (DataRow sourceRow in sourceTable.Rows)
{
string specValue = "";
string modelValue = "";
string zhsxValue = "";
string unitValue = "";
string czValue = "";
string nameValue = "";
string sourceSql = GcMainModuleObj.MenuSql;
sourceSql = ReplaceHelper.ReplaceRowParam(sourceRow, sourceSql);
DataTable dataTable = BaseImpl.GetDataTableResult(sourceSql);
List<SysSetModel> controlList = new List<SysSetModel>();
foreach (DataRow item in dataTable.Rows)
string xgtigName = $"{sysModel.PrefixKey}xgtig";
string idName = $"{sysModel.PrefixKey}id";
if (sourceRow.Table.Columns.Contains(xgtigName) && (sourceRow[xgtigName] + "").Equals("1"))
{
controlList.Add(new SysSetModel(item));
}
string primaryVlaue = sourceRow["productid"] + "";
DataRow selectSource = BaseImpl.GetDataRowResult(string.Format("select * from p_producttab where productid = '{0}'", primaryVlaue));
if (selectSource == null)
{
primaryVlaue = sourceRow[$"{sysModel.PrefixKey}id"] + "";
selectSource = BaseImpl.GetDataRowResult($"select * from {sysModel.MenuTable} where {sysModel.PrefixKey}id = '{primaryVlaue}'");
}
SysSetModel nameModel = controlList.Where(n => n.OrderId.Equals(1)).FirstOrDefault();
if (nameModel != null)
{
nameValue = selectSource.Table.Columns.Contains(nameModel.DbName) ? selectSource[nameModel.DbName] + "" : "";
}
//反写规格
List<SysSetModel> specModels = controlList.Where(n => n.SpecDbName.Equals(1)).OrderBy(n => n.SpecSort).ToList();
StringBuilder specText = new StringBuilder();
for (int i = 0; i < specModels.Count; i++)
{
SysSetModel specModel = specModels[i];
string value = selectSource.Table.Columns.Contains(specModel.DbName) ? selectSource[specModel.DbName] + "" : "";
if (!string.IsNullOrWhiteSpace(value))
if (sourceTable.Columns.Contains("Plm_lmb_SmartBmFa"))
{
if (i == 0)
string projectId = sourceRow["Plm_lmb_SmartBmFa"] + "";
if (!string.IsNullOrEmpty(projectId))
{
specText.Append(string.Format("{0}{1}{2}", specModel.ConnectorStrGg, value, specModel.EndConnectorStrGg));
}
else
{
specText.Append(string.Format("{0}{1}{2}{3}", specModel.ConnectorStr, specModel.ConnectorStrGg, value, specModel.EndConnectorStrGg));
string id = sourceRow.Table.Columns.Contains(idName) ? sourceRow[idName] + "" : "";
string specValue = "";
string modelValue = "";
string zhsxValue = "";
string unitValue = "";
string czValue = "";
string nameValue = "";
string sourceSql = GcMainModuleObj.MenuSql;
sourceSql = ReplaceHelper.ReplaceRowParam(sourceRow, sourceSql);
DataTable dataTable = BaseImpl.GetDataTableResult(sourceSql);
List<SysSetModel> controlList = new List<SysSetModel>();
foreach (DataRow item in dataTable.Rows)
{
controlList.Add(new SysSetModel(item));
}
string primaryVlaue = sourceRow["productid"] + "";
DataRow selectSource = BaseImpl.GetDataRowResult(string.Format("select * from p_producttab where productid = '{0}'", primaryVlaue));
if (selectSource == null)
{
primaryVlaue = sourceRow[$"{sysModel.PrefixKey}id"] + "";
selectSource = BaseImpl.GetDataRowResult($"select * from {sysModel.MenuTable} where {sysModel.PrefixKey}id = '{primaryVlaue}'");
}
SysSetModel nameModel = controlList.Where(n => n.OrderId.Equals(1)).FirstOrDefault();
if (nameModel != null)
{
nameValue = selectSource.Table.Columns.Contains(nameModel.DbName) ? selectSource[nameModel.DbName] + "" : "";
}
//反写规格
List<SysSetModel> specModels = controlList.Where(n => n.SpecDbName.Equals(1)).OrderBy(n => n.SpecSort).ToList();
StringBuilder specText = new StringBuilder();
for (int i = 0; i < specModels.Count; i++)
{
SysSetModel specModel = specModels[i];
string value = selectSource.Table.Columns.Contains(specModel.DbName) ? selectSource[specModel.DbName] + "" : "";
if (!string.IsNullOrWhiteSpace(value))
{
if (i == 0)
{
specText.Append(string.Format("{0}{1}{2}", specModel.ConnectorStrGg, value, specModel.EndConnectorStrGg));
}
else
{
specText.Append(string.Format("{0}{1}{2}{3}", specModel.ConnectorStr, specModel.ConnectorStrGg, value, specModel.EndConnectorStrGg));
}
}
}
specValue = specText.ToString();
//反写型号
List<SysSetModel> modelModels = controlList.Where(n => n.ModelDbName.Equals(1)).OrderBy(n => n.ModelSort).ToList();
StringBuilder modelText = new StringBuilder();
for (int i = 0; i < modelModels.Count; i++)
{
SysSetModel modelModel = modelModels[i];
string value = selectSource.Table.Columns.Contains(modelModel.DbName) ? selectSource[modelModel.DbName] + "" : "";
if (!string.IsNullOrWhiteSpace(value))
{
if (i == 0)
{
modelText.Append(string.Format("{0}{1}{2}", modelModel.ConnectorStrGg, value, modelModel.EndConnectorStrGg));
}
else
{
modelText.Append(string.Format("{0}{1}{2}{3}", modelModel.ConnectorStr, modelModel.ConnectorStrGg, value, modelModel.EndConnectorStrGg));
}
}
}
modelValue = modelText.ToString();
//反写综合属性
List<SysSetModel> zhsxModels = controlList.Where(n => n.ZhSxdbName.Equals(1)).OrderBy(n => n.ProDeSort).ToList();
StringBuilder zhsxText = new StringBuilder();
for (int i = 0; i < zhsxModels.Count; i++)
{
SysSetModel zhsxModel = zhsxModels[i];
string value = selectSource.Table.Columns.Contains(zhsxModel.DbName) ? selectSource[zhsxModel.DbName] + "" : "";
if (value.Equals("无"))
{
value = "";
}
if (!string.IsNullOrWhiteSpace(value))
{
if (i == 0)
{
zhsxText.Append(string.Format("{0}{1}{2}", zhsxModel.ConnectorStrZhsx, value, zhsxModel.EndConnectorStrZhsx));
}
else
{
zhsxText.Append(string.Format("{0}{1}{2}{3}", zhsxModel.ConnectorStr, zhsxModel.ConnectorStrZhsx, value, zhsxModel.EndConnectorStrZhsx));
}
}
}
zhsxValue = zhsxText.ToString();
//反写材质属性
List<SysSetModel> czModels = controlList.Where(n => n.CzdbName.Equals(1)).OrderBy(n => n.GradeSort).ToList();
StringBuilder czText = new StringBuilder();
for (int i = 0; i < czModels.Count; i++)
{
SysSetModel czModel = czModels[i];
string value = selectSource.Table.Columns.Contains(czModel.DbName) ? selectSource[czModel.DbName] + "" : "";
if (value.Equals("无"))
{
value = "";
}
if (!string.IsNullOrWhiteSpace(value))
{
if (i == 0)
{
czText.Append(string.Format("{0}{1}{2}", czModel.ConnectorStrCz, value, czModel.EndConnectorStrCz));
}
else
{
czText.Append(string.Format("{0}{1}{2}{3}", czModel.ConnectorStr, czModel.ConnectorStrCz, value, czModel.EndConnectorStrCz));
}
}
}
czValue = czText.ToString();
using (SqlCommand command = new SqlCommand(functionName, SqlHelper._connection))
{
string[] parametersArray = parameters.Split(',');
foreach (DataRow parameterRow in sqlParametersTab.Rows)
{
string parameterName = parameterRow["PARAMETER_NAME"] + "";
string parameterMode = parameterRow["PARAMETER_MODE"] + "";
int.TryParse(parameterRow["CHARACTER_MAXIMUM_LENGTH"] + "", out int dataLength);
string dataType = parameterRow["DATA_TYPE"] + "";
SqlParameter sqlParameter = null;
if (parameterMode.Equals("int"))
{
sqlParameter = new SqlParameter(parameterName, SqlDbType.Int);
}
else
{
sqlParameter = new SqlParameter(parameterName, SqlDbType.VarChar, dataLength);
}
if (parameterMode.Equals("IN"))
{
sqlParameter.Direction = ParameterDirection.Input;
}
else
{
sqlParameter.Direction = ParameterDirection.Output;
}
command.Parameters.Add(sqlParameter);
}
for (int i = 0; i < command.Parameters.Count; i++)
{
SqlParameter sqlParameter = command.Parameters[i];
if (parametersArray.Length > i)
{
string commandParameter = parametersArray[i];
string field = commandParameter.Replace("@", "").Replace("{", "").Replace("}", "");
string value = "";
if (field.Equals("spec"))
{
value = specValue;
}
else if (field.Equals("model"))
{
value = modelValue;
}
else if (field.Equals("grade"))
{
value = czValue;
}
else if (field.Equals("productdescrip"))
{
value = zhsxValue;
}
else if (field.Equals("appellation"))
{
value = nameValue;
}
else
{
value = sourceRow.Table.Columns.Contains(field) ? sourceRow[field] + "" : commandParameter.Replace("@", "");
value = value.Replace("@", "").Replace("{", "").Replace("}", "");
}
sqlParameter.Value = value;
}
}
SqlParameter returnValue = new SqlParameter("@return", SqlDbType.Int, 4);
returnValue.Direction = ParameterDirection.ReturnValue;
command.Parameters.Add(returnValue);
command.CommandType = CommandType.StoredProcedure;
command.ExecuteNonQuery();
}
}
}
}
specValue = specText.ToString();
//反写型号
List<SysSetModel> modelModels = controlList.Where(n => n.ModelDbName.Equals(1)).OrderBy(n => n.ModelSort).ToList();
StringBuilder modelText = new StringBuilder();
for (int i = 0; i < modelModels.Count; i++)
{
SysSetModel modelModel = modelModels[i];
string value = selectSource.Table.Columns.Contains(modelModel.DbName) ? selectSource[modelModel.DbName] + "" : "";
if (!string.IsNullOrWhiteSpace(value))
{
if (i == 0)
{
modelText.Append(string.Format("{0}{1}{2}", modelModel.ConnectorStrGg, value, modelModel.EndConnectorStrGg));
}
else
{
modelText.Append(string.Format("{0}{1}{2}{3}", modelModel.ConnectorStr, modelModel.ConnectorStrGg, value, modelModel.EndConnectorStrGg));
}
}
}
modelValue = modelText.ToString();
//反写综合属性
List<SysSetModel> zhsxModels = controlList.Where(n => n.ZhSxdbName.Equals(1)).OrderBy(n => n.ProDeSort).ToList();
StringBuilder zhsxText = new StringBuilder();
for (int i = 0; i < zhsxModels.Count; i++)
{
SysSetModel zhsxModel = zhsxModels[i];
string value = selectSource.Table.Columns.Contains(zhsxModel.DbName) ? selectSource[zhsxModel.DbName] + "" : "";
if (value.Equals("无"))
{
value = "";
}
if (!string.IsNullOrWhiteSpace(value))
{
if (i == 0)
{
zhsxText.Append(string.Format("{0}{1}{2}", zhsxModel.ConnectorStrZhsx, value, zhsxModel.EndConnectorStrZhsx));
}
else
{
zhsxText.Append(string.Format("{0}{1}{2}{3}", zhsxModel.ConnectorStr, zhsxModel.ConnectorStrZhsx, value, zhsxModel.EndConnectorStrZhsx));
}
}
}
zhsxValue = zhsxText.ToString();
//反写材质属性
List<SysSetModel> czModels = controlList.Where(n => n.CzdbName.Equals(1)).OrderBy(n => n.GradeSort).ToList();
StringBuilder czText = new StringBuilder();
for (int i = 0; i < czModels.Count; i++)
{
SysSetModel czModel = czModels[i];
string value = selectSource.Table.Columns.Contains(czModel.DbName) ? selectSource[czModel.DbName] + "" : "";
if (value.Equals("无"))
{
value = "";
}
if (!string.IsNullOrWhiteSpace(value))
{
if (i == 0)
{
czText.Append(string.Format("{0}{1}{2}", czModel.ConnectorStrCz, value, czModel.EndConnectorStrCz));
}
else
{
czText.Append(string.Format("{0}{1}{2}{3}", czModel.ConnectorStr, czModel.ConnectorStrCz, value, czModel.EndConnectorStrCz));
}
}
}
czValue = czText.ToString();
}
}
else
{
MessageUtil.Show("保存逻辑配置错误");
}
}
else
{
MessageUtil.Show("保存逻辑配置错误");
}
}
catch (Exception)
{
}
finally
{
WaitForm.HideForm();
}
}
/// <summary>
@@ -2171,14 +2275,6 @@ namespace Lskj.PubBomAlter
{
SearchObj.SearchGrid();
}
btnFxSave.Enabled = false;
string xgtigName = $"{sysModel.PrefixKey}xgtig";
DataTable sourceTable = treeGridControlEx.GridControl.DataSourceTable();
if (sourceTable != null && sourceTable.Columns.Contains(xgtigName))
{
var selectRows = sourceTable.AsEnumerable().Where(n => (n[xgtigName] + "").Equals("1"));
btnFxSave.Enabled = selectRows.Count() > 0;
}
}
/// <summary>
/// 查询后事件
@@ -2189,6 +2285,14 @@ namespace Lskj.PubBomAlter
{
try
{
btnFxSave.Enabled = false;
string xgtigName = $"{sysModel.PrefixKey}xgtig";
DataTable sourceTable = treeGridControlEx.TreeListObj.DataSource as DataTable;
if (sourceTable != null && sourceTable.Columns.Contains(xgtigName))
{
var selectRows = sourceTable.AsEnumerable().Where(n => (n[xgtigName] + "").Equals("1"));
btnFxSave.Enabled = selectRows.Count() > 0;
}
this.OnAfterDataSourceCallback -= OnAfterDataSource;
TreeListNode focusedNode = TreeGridObj.TreeListObj.FocusedNode;
if (focusedNode != null)