public override bool UpdateData(DataAction dataAction) { if (!_dataChanged) { return(true); } bool isError = false; try { DbData.BeginMultiTrans(); int index = DsData.Tables[0].Rows.IndexOf(_drCurrentMaster); if (!_customize.BeforeUpdate(index, DsData)) { DbData.RollbackMultiTrans(); return(false); } bool isNew = _drCurrentMaster.RowState == DataRowState.Added; if (Update(_drCurrentMaster)) { isError = isError || !TransferData(dataAction, index); _customize.AfterUpdate(); } else { isError = true; } // if (!isError) { DbData.EndMultiTrans(); } else { DbData.RollbackMultiTrans(); } if (isNew && !isError) { _autoIncreValues.UpdateNewStruct(_drCurrentMaster); } if (!isError) { base.InsertHistory(dataAction, DsData); DsData.AcceptChanges(); _dsDataTmp = DsData.Copy(); } DataChanged = false; } finally { if (DbData.Connection.State != ConnectionState.Closed) { DbData.Connection.Close(); } } return(!isError); }
public void GetData(CDTData ParentData) { ConditionForPackage(); string extrasql = string.Empty; if (_drTable.Table.Columns.Contains("ExtraSql")) { if (_drTable["ExtraSql"] != null) { extrasql = _drTable["Extrasql"].ToString(); } } string queryData = "select * from " + _drTable["TableName"].ToString(); if (_condition != string.Empty && !(_condition.Contains("@"))) { queryData += " where " + _condition; if (extrasql != string.Empty) { queryData += " and (" + extrasql + ")"; } } else if (extrasql != string.Empty) { queryData += " where " + extrasql; } string lkCondition = GenConditionForLookup(ParentData); if (lkCondition != string.Empty) { if ((_condition == string.Empty && extrasql == string.Empty) || (_condition != string.Empty && _condition.Contains("@"))) { queryData += " where " + lkCondition; } else { queryData += " and ( " + lkCondition + ")"; } } if (_drTable["SortOrder"].ToString() != string.Empty) { queryData += " order by " + DrTable["SortOrder"].ToString(); } DsData = DbData.GetDataSet(queryData); if (DsData != null) { DsData.Tables[0].TableName = _drTable["TableName"].ToString(); _dsDataTmp = DsData.Copy(); } }
public override bool UpdateData(DataAction dataAction) { if (!_dataChanged) { return(true); } DbData.BeginMultiTrans(); int index = DsData.Tables[0].Rows.IndexOf(_drCurrentMaster); if (index == -1) { return(false); } if (!_customize.BeforeUpdate(index, DsData)) { DbData.RollbackMultiTrans(); return(false); } DataRow[] arrDrCurrentDetails = new DataRow[_lstDrCurrentDetails.Count]; _lstDrCurrentDetails.CopyTo(arrDrCurrentDetails); bool isNew = _drCurrentMaster.RowState == DataRowState.Added; if ((dataAction != DataAction.Delete && Update(_drCurrentMaster) && UpdateDetail()) || (dataAction == DataAction.Delete && UpdateDetail() && Update(_drCurrentMaster))) { TransferData(dataAction, index); _customize.AfterUpdate(); } bool isError = DbData.HasErrors; if (!isError) { DbData.EndMultiTrans(); } else { DbData.RollbackMultiTrans(); } if (isNew && !isError) { _autoIncreValues.UpdateNewStruct(_drCurrentMaster); } if (!isError) { base.InsertHistory(dataAction, DsData); DsData.AcceptChanges(); _dsDataTmp = DsData.Copy(); } return(!isError); }
public override void GetData() { ConditionForPackage(); string query = string.Empty, queryMaster = string.Empty; this.GetQuery(ref queryMaster, ref query); DsData = DbData.GetDataSetDetail(queryMaster, query); string fkName = _drTableMaster["Pk"].ToString(); DataColumn pk = DsData.Tables[1].Columns[fkName]; DataColumn fk = DsData.Tables[0].Columns[fkName]; if (pk != null && fk != null) { DataRelation dr = new DataRelation(_drTable["TableName"].ToString(), pk, fk, true); DsData.Relations.Add(dr); } // DsData.Tables[0].PrimaryKey = new DataColumn[] { DsData.Tables[0].Columns[_drTable["pk"].ToString()] }; if (DsData != null) { _dsDataTmp = DsData.Copy(); } }
public override void GetData() { ConditionForPackage(); string extrasql = string.Empty; //xét trường hợp phân toàn quyền // string extraWs = string.Empty; if (DrTable["sysUserID"] != null) { string adminList = DrTable["sysUserID"].ToString().Trim(); if (adminList != string.Empty) { if (adminList != Config.GetValue("sysUserID").ToString().Trim()) { string dk = NotAdminListCondition(); dk = UpdateSpecialCondition(dk); extraWs = " (charindex('_" + Config.GetValue("sysUserID").ToString().Trim() + "_',ws)>0 or charindex('_" + Config.GetValue("sysUserGroupID").ToString().Trim() + "_',Grws)>0)"; if (dk != string.Empty) { extraWs += " or " + dk; } extraWS = dk; } } } // if (_drTable.Table.Columns.Contains("ExtraSql")) { if (_drTable["ExtraSql"] != null) { extrasql = _drTable["Extrasql"].ToString(); } } if (extraWs != string.Empty) { if (extrasql == string.Empty) { extrasql = extraWs; } else { extrasql += " and (" + extraWs + ")"; } } string queryData = "select * from " + _drTable["TableName"].ToString(); if (_condition != string.Empty && !(_condition.Contains("@"))) { queryData += " where " + _condition; if (extrasql != string.Empty) { queryData += " and (" + extrasql + ")"; } } else { fullData = true; if (extrasql != string.Empty) { queryData += " where " + extrasql; } } if (_drTable["SortOrder"].ToString() != string.Empty) { queryData += " order by " + DrTable["SortOrder"].ToString(); } DsData = DbData.GetDataSet(queryData); if (DsData != null) { string fkName = _drTable["Pk"].ToString(); DsData.Tables[0].Columns[fkName].Unique = true; DsData.Tables[0].PrimaryKey = new DataColumn[] { DsData.Tables[0].Columns[fkName] }; DsData.Tables[0].TableName = _drTable["TableName"].ToString(); _dsDataTmp = DsData.Copy(); } if (DataSoureChanged != null && fullData) { DataSoureChanged(this, new EventArgs()); } }
public override bool UpdateData(DataAction dataAction) { DateTime btime = DateTime.Now; DateTime etime = DateTime.Now; if (!_dataChanged) { return(true); } bool isNew = _drCurrentMaster.RowState == DataRowState.Added; //kiểm tra Record trước khi update có thỏa điều kiện phân quyền không Boolean chkOk = false; if (extraWS != string.Empty) { object pkValue = null; string fieldName = string.Empty; bool isDelete = false; bool isModify = false; DataView vOrg = new DataView(_drCurrentMaster.Table); if (_drCurrentMaster.RowState == DataRowState.Deleted) { _drCurrentMaster.RejectChanges(); isDelete = true; } if (_drCurrentMaster.RowState == DataRowState.Modified) { vOrg.RowStateFilter = DataViewRowState.ModifiedOriginal; vOrg.RowFilter = extraWS; isModify = true; } pkValue = _drCurrentMaster[PkMaster.FieldName]; DataRow[] DRowtmp = DsData.Tables[0].Select(extraWS); foreach (DataRow drtmp in DRowtmp) { if (pkValue == drtmp[PkMaster.FieldName]) { if (isModify) { if (vOrg.Count > 0) { chkOk = true; } } else { chkOk = true; } } } if (isDelete) { _drCurrentMaster.Delete(); } } else { chkOk = true; } if (!chkOk) { return(false); } //---- bool isError = false; try { btime = DateTime.Now; DbData.BeginMultiTrans(); this.CheckRules(dataAction); if (_drCurrentMaster.Table.DataSet.HasErrors) { DbData.RollbackMultiTrans(); return(false); } int index = DsData.Tables[0].Rows.IndexOf(_drCurrentMaster); if (!_customize.BeforeUpdate(index, DsData)) { DbData.EndMultiTrans(); return(false); } if (Update(_drCurrentMaster)) { TransferData(dataAction, index); _customize.AfterUpdate(); } isError = DbData.HasErrors; if (!isError) { etime = DateTime.Now; DbData.EndMultiTrans(); } else { DbData.RollbackMultiTrans(); } if (isNew && !isError) { _autoIncreValues.UpdateNewStruct(_drCurrentMaster); } if (!isError) { base.InsertHistory(dataAction, DsData, btime, etime); DsData.AcceptChanges(); _dsDataTmp = DsData.Copy(); } } catch (Exception ex) { } finally { if (this.DbData.Connection.State != ConnectionState.Closed) { this.DbData.Connection.Close(); } } return(!isError); }
public override void GetData() { ConditionForPackage(); string extrasql = string.Empty; //xét trường hợp phân toàn quyền // string extraWs = string.Empty; if (DrTable["sysUserID"] != null) { string adminList = DrTable["sysUserID"].ToString().Trim(); if (adminList != string.Empty) { if (adminList != Config.GetValue("sysUserID").ToString().Trim()) { string dk = NotAdminListCondition(); extraWs = " charindex('" + Config.GetValue("sysUserID").ToString().Trim() + "_',ws)>0"; if (dk != string.Empty) { extraWs += " or " + dk; } extraWS = dk; } } } // if (_drTable.Table.Columns.Contains("ExtraSql")) { if (_drTable["ExtraSql"] != null) { extrasql = _drTable["Extrasql"].ToString(); } } if (extraWs != string.Empty) { if (extrasql == string.Empty) { extrasql = extraWs; } else { extrasql += " and " + extraWs; } } string queryData = "select * from " + _drTable["TableName"].ToString(); if (_condition != string.Empty && !(_condition.Contains("@"))) { queryData += " where " + _condition; if (extrasql != string.Empty) { queryData += " and (" + extrasql + ")"; } } else { fullData = true; if (extrasql != string.Empty) { queryData += " where " + extrasql; } } if (_drTable["SortOrder"].ToString() != string.Empty) { queryData += " order by " + DrTable["SortOrder"].ToString(); } DsData = DbData.GetDataSet(queryData); if (DsData != null) { _dsDataTmp = DsData.Copy(); } }