SVN r437
SVN-Revision: r437
This commit is contained in:
@@ -31,6 +31,10 @@ namespace Lskj.PubBomImport
|
||||
/// </summary>
|
||||
private DataTable _detailColumns;
|
||||
private string guidField = "xxxxx_guid";
|
||||
/// <summary>
|
||||
/// 保存或修改时报错信息
|
||||
/// </summary>
|
||||
public string SaveErrorMessage = string.Empty;
|
||||
public GridView GcMainView
|
||||
{
|
||||
get { return gcMain.GridView; }
|
||||
@@ -127,7 +131,15 @@ namespace Lskj.PubBomImport
|
||||
}
|
||||
}
|
||||
}
|
||||
public bool BillSave(int comfirm = 0, bool canTipMsg = true)
|
||||
public void InitializeHeader(DataRow rowItem)
|
||||
{
|
||||
// 新增
|
||||
if (rowItem != null)
|
||||
{
|
||||
ControlObj.SetAllControlValue(rowItem, true);
|
||||
}
|
||||
}
|
||||
public bool BillSave(ref string billNo, int comfirm = 0, bool canTipMsg = true)
|
||||
{
|
||||
bool saveResult = false;
|
||||
if (ControlObj.VerifyNull())
|
||||
@@ -151,9 +163,9 @@ namespace Lskj.PubBomImport
|
||||
//MessageUtil.Show("表格中数据内容重复,保存失败!");
|
||||
return saveResult;
|
||||
}
|
||||
string billNo = this.lblOrderNo.Text.Trim();
|
||||
billNo = this.lblOrderNo.Text.Trim();
|
||||
string detailGuid = Guid.NewGuid().ToString();
|
||||
string masterSql = GetAddRecord(ref billNo);
|
||||
string masterSql = billModel.SaveState ? GetUpdateRecord(billNo) : GetAddRecord(ref billNo);
|
||||
string detailSql = GetDetailRecord(detailGuid, billNo).ToString();
|
||||
// 检查单据头数据合法性
|
||||
if (string.IsNullOrEmpty(masterSql)) return false;
|
||||
@@ -182,6 +194,37 @@ namespace Lskj.PubBomImport
|
||||
}
|
||||
return saveResult;
|
||||
}
|
||||
private string GetUpdateRecord(string parmaryValue)
|
||||
{
|
||||
StringBuilder updateBuilder = new StringBuilder();
|
||||
DataTable DetailedProperties = BaseImpl.GetDataTableResult(string.Format("select COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where table_name = '{0}'", billModel.MasterTable));
|
||||
string errorMessage = string.Empty;//数据不符合数据库规范的信息
|
||||
// 修改单据
|
||||
foreach (ControlModel model in this.ControlObj.ControlModels)
|
||||
{
|
||||
if (!model.IsSave ||
|
||||
model.FieldName.Equals(billModel.RtagidKey, StringComparison.OrdinalIgnoreCase) ||
|
||||
model.FieldType == ControlType.LabPic ||
|
||||
model.FieldType == ControlType.LabPicEx)
|
||||
continue;
|
||||
BaseUserControl userControl = this.ControlObj.FindControl(model);
|
||||
if (userControl != null)
|
||||
{
|
||||
string fieldValue = this.ControlObj.GetControlValue(model);
|
||||
if (SystemInfo.Instance.TrimWhiteSpace)
|
||||
fieldValue = fieldValue.Trim();
|
||||
if (fieldValue == "****") continue;
|
||||
|
||||
errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(DetailedProperties, model, fieldValue);
|
||||
if (string.IsNullOrEmpty(fieldValue) && model.Isintordecimal) fieldValue = "0";//数值保存时为空的话默认保存为0;
|
||||
|
||||
updateBuilder.Append(string.IsNullOrEmpty(fieldValue) ? string.Format("{0}={1}", model.FieldName, this.ControlObj.GetNullValue(model)) : string.Format("{0}=N'{1}',", model.FieldName, fieldValue.Contains("'") ? fieldValue.Replace("'", "''") : fieldValue));
|
||||
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(errorMessage)) SaveErrorMessage = "表头错误:" + errorMessage;
|
||||
return string.Format("update {0} set {1} where {2}='{3}'", billModel.MasterTable, updateBuilder.ToString().TrimEnd(','), billModel.PrimaryKey, parmaryValue);
|
||||
}
|
||||
private string GetAddRecord(ref string parmaryValue)
|
||||
{
|
||||
if (billModel.NewVer == 0)
|
||||
@@ -213,15 +256,20 @@ namespace Lskj.PubBomImport
|
||||
model.FieldType == ControlType.LabPic ||
|
||||
model.FieldType == ControlType.LabPicEx)
|
||||
continue;
|
||||
|
||||
string fieldValue = this.ControlObj.GetControlValue(model);
|
||||
if (SystemInfo.Instance.TrimWhiteSpace)
|
||||
fieldValue = fieldValue.Trim();
|
||||
if (fieldValue == "****") continue;
|
||||
|
||||
errorMessage = errorMessage + DatabaseFormatJudgment.SaveOrModifyBalidation(DetailedProperties, model, fieldValue);
|
||||
if (string.IsNullOrEmpty(fieldValue) && model.Isintordecimal) fieldValue = "0";//数值保存时为空的话默认保存为0;
|
||||
|
||||
fieldBuilder.Append(model.FieldName + ",");
|
||||
valueBuilder.Append(string.IsNullOrEmpty(fieldValue) ? this.ControlObj.GetNullValue(model) : string.Format("N'{0}',", fieldValue));
|
||||
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(errorMessage)) SaveErrorMessage = "表头错误:" + errorMessage;
|
||||
// 增加主键
|
||||
fieldBuilder.Append(billModel.PrimaryKey);
|
||||
valueBuilder.Append("N'" + parmaryValue + "'");
|
||||
@@ -331,13 +379,108 @@ namespace Lskj.PubBomImport
|
||||
}
|
||||
private void SetBillStatus(DataRow rowItem)
|
||||
{
|
||||
// 单据为新增状态
|
||||
this.dbpFP.Enabled = this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true;
|
||||
this.lbTitle.Text = billModel.TypeName + "(新增)";
|
||||
this.lblOrderNo.Text = BillImpl.GetBillNo(billModel.BillSeq);
|
||||
this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true;
|
||||
this.cb_templete.Enabled = true;
|
||||
this.billModel.SaveState = false;
|
||||
this.ControlObj.SetReadOnlyAllControl(false);
|
||||
this.rdBlue.Enabled = this.rdRed.Enabled = true;
|
||||
// 通过右键菜单打开单据,假如明细有数据则在初始化时使用传入数据.
|
||||
if (rowItem != null)
|
||||
{
|
||||
// 单据为修改状态,无需设置赋值时不需要计算面板属性
|
||||
bool isReadOnly = !string.IsNullOrEmpty(billModel.ModifyCond) && !ReplaceHelper.ReplaceRowParamCond(rowItem, billModel.ModifyCond);
|
||||
this.ControlObj.CanExecControl = false; // 单据为修改状态时,无需计算面板属性
|
||||
this.lbTitle.Text = billModel.TypeName + "(修改)";
|
||||
this.lblOrderNo.Text = rowItem[billModel.PrimaryKey] + "";
|
||||
this.rdBlue.Checked = "0".Equals(rowItem[billModel.RtagidKey] + "");
|
||||
this.rdRed.Checked = "1".Equals(rowItem[billModel.RtagidKey] + "");
|
||||
billModel.SaveState = true;
|
||||
this.rdBlue.Enabled = this.rdRed.Enabled = false;
|
||||
this.ControlObj.SetReadOnlyAllControl(isReadOnly);
|
||||
this.ControlObj.SetAllControlValue(rowItem);
|
||||
this.dbpFP.Enabled = this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = !isReadOnly;
|
||||
this.ControlObj.CanExecControl = true;
|
||||
this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = !isReadOnly;
|
||||
this.labelControl1.ForeColor = this.lblOrderNo.ForeColor = this.lbTitle.ForeColor = rdBlue.Checked ? Color.Blue : Color.Red;
|
||||
this.gcMain.GridView.OptionsBehavior.Editable = !isReadOnly;
|
||||
// 上一次查询
|
||||
int oldRowHandle = this.gcMain.GridView.FocusedRowHandle;
|
||||
//获取数据源并排序
|
||||
DataTable dt = BillImpl.GetDataTableResult(ReplaceHelper.ReplaceRowParam(rowItem, billModel.DetailSql));
|
||||
if (dt.Columns.Contains(billModel.DetailOrderField))
|
||||
{
|
||||
DataView dataView = dt.AsDataView();
|
||||
dataView.Sort = billModel.DetailOrderField;
|
||||
dt = dataView.ToTable();
|
||||
}
|
||||
if (billModel.DetailTreeTable)
|
||||
{
|
||||
//判断是否有tap_id和tap_pid
|
||||
(this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(dt);
|
||||
this.gcMain.GridView.SelectRowHandler(oldRowHandle);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.gcMain.GridControl.DataSource = dt;
|
||||
this.gcMain.GridView.SelectRowHandler(oldRowHandle);
|
||||
if (billModel.SelectLast && dt.Rows.Count > 0)
|
||||
{
|
||||
this.gcMain.GridView.SelectRowHandler(dt.Rows.Count - 1);
|
||||
}
|
||||
}
|
||||
BaseUserControl userControl = this.ControlObj.FindControl(billModel.RtagidKey);
|
||||
if (userControl != null)
|
||||
{
|
||||
userControl.EditText = this.rdRed.Checked ? "1" : "0";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 单据为新增状态
|
||||
this.dbpFP.Enabled = this.btnDelete.Enabled = this.btnBillSave.Enabled = this.btnBillApply.Enabled = true;
|
||||
this.lbTitle.Text = billModel.TypeName + "(新增)";
|
||||
this.lblOrderNo.Text = BillImpl.GetBillNo(billModel.BillSeq);
|
||||
this.cb_input.Enabled = this.btn_input.Enabled = this.txt_input.Enabled = true;
|
||||
this.cb_templete.Enabled = true;
|
||||
billModel.SaveState = false;
|
||||
this.ControlObj.SetReadOnlyAllControl(false);
|
||||
this.rdBlue.Enabled = this.rdRed.Enabled = true;
|
||||
// 通过右键菜单打开单据,假如明细有数据则在初始化时使用传入数据.
|
||||
if (billModel.DetailTreeTable)
|
||||
{
|
||||
(this.gcMain as TreeGridControlEx).TreeListObj.OptionsBehavior.Editable = true;
|
||||
(this.gcMain as TreeGridControlEx).SetGridViewDataSourceGenerateID(BillImpl.GetDataTableResult(billModel.DetailSql));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.gcMain.GridView.OptionsBehavior.Editable = true;
|
||||
this.gcMain.GridControl.DataSource = BillImpl.GetDataTableResult(billModel.DetailSql);
|
||||
}
|
||||
BaseUserControl userControl = this.ControlObj.FindControl(billModel.RtagidKey);
|
||||
if (userControl != null)
|
||||
{
|
||||
userControl.EditText = this.rdRed.Checked ? "1" : "0";
|
||||
}
|
||||
}
|
||||
this.lbTitle.Invalidate();
|
||||
}
|
||||
public void OnBillAdd()
|
||||
{
|
||||
this.SetBillStatus(null);
|
||||
this.ControlObj.ResetControlValue(billModel.ManuallyTriggerCorrelation, true);
|
||||
}
|
||||
public void AddOrUpdateBill(DataRow rowItem, DataTable newSource)
|
||||
{
|
||||
string masterSql = rowItem == null ? billModel.MasterSql.Replace("{" + billModel.PrimaryKey + "}", this.lblOrderNo.Text) : ReplaceHelper.ReplaceRowParam(rowItem, billModel.MasterSql);
|
||||
// 加载单据信息
|
||||
DataRow mainRow = BillImpl.GetDataRowResult(masterSql);
|
||||
this.SetBillStatus(mainRow);
|
||||
if (!billModel.SaveState)
|
||||
{
|
||||
this.InitializeHeader(rowItem);
|
||||
}
|
||||
string controlSql = "select '' as billdocument_id,'0' affirmer,'0' rtagid,'{材料代码}' as productid";
|
||||
if (mainRow != null)
|
||||
{
|
||||
//更新
|
||||
DataTable source = this.gcMain.GridControl.DataSourceTable();
|
||||
List<DataRow> deleteRows = new List<DataRow>();
|
||||
foreach (DataRow sourceRow in source.Rows)
|
||||
{
|
||||
string productId = sourceRow["ProductId"] + "";
|
||||
DataRow newSourceRow = newSource.Rows.Cast<DataRow>().Where(n => (n["ProductId"] + "").Equals(productId)).FirstOrDefault();
|
||||
|
||||
Reference in New Issue
Block a user