public string Exec(HtnDataInfo p_info) { string _result = "OK"; if (p_info == null) { return(_result); } string _sql = string.Empty; //Hashtable _ht = new Hashtable(); foreach (DataRow _dr in _dt.Rows) { if (p_info.IsUpdate) //可更新 { _sql = p_info.IsRowExist(_dr) ? p_info.Update : p_info.Insert; } else if (!p_info.IsExist(_dr)) { _sql = p_info.Insert; } if (string.IsNullOrEmpty(_sql)) { continue; } //_ht.Add(_sql, GetParams(p_info, _dr)); int r = HtnData.ExecNonQuery(_sql, GetParams(p_info, _dr)); } //HtnData.ExecuteSqlTran(_ht); return(_result); }
/// <summary> /// 特殊处理 /// </summary> /// <returns></returns> private string GetHTNItem() { string _result = _sqlval; string _ids = string.Empty; //string _sql = "SELECT ID FROM HTN_TREATMENTHISTORY WHERE ID NOT IN (SELECT TREATMENTID FROM HTN_TREATMENTHISTORYITEM)"; string _sql = "select top 100 ID from HTN_TreatmentHistory a where not exists (select 1 from HTN_TreatmentHistoryItem b where a.ID = b.TreatmentId)"; DataTable _dt = HtnData.Query(_sql); if (_dt == null || _dt.Rows.Count == 0) { return(string.Empty); } foreach (DataRow _dr in _dt.Rows) { _ids += string.Format("'{0}',", _dr.Str("ID")); } _ids = _ids.TrimEnd(','); string _filter = string.Format(" AND TREATMENTID IN ({0})", _ids); _result = string.Format(_result, _filter); return(_result); }
public HtnSaveData(string p_xml) { _dt = HtnData.XmlToData(p_xml); if (_dt == null || _dt.Rows.Count == 0) { return; } Key = _dt.TableName; }
public HtnDataInfo(DataRow p_dr) { _ids = new List <string>(); _sqlkey = p_dr.Str("SQLKey"); _sqlval = p_dr.Str("SQLVal"); _sqlpk = p_dr.Str("SQLPk"); _sqlup = p_dr.Str("SQLUp") == "1"; _model = HtnData.Query("select top 1 * from " + _sqlkey); _exist = string.Format("select count(*) as [len] from {0} where {1} = ", _sqlkey, _model.Columns[0].ColumnName) + "'{0}'"; }
/// <summary> /// 获取Select语句 /// </summary> /// <returns></returns> private string GetSelect() { string _result = _sqlval; if (!_result.Contains("{0}")) { return(_result); } if (_sqlkey == "HTN_TreatmentHistoryItem") { return(GetHTNItem()); } if (string.IsNullOrEmpty(_sqlpk)) { return(_result.Replace("{0}", "")); } string _sql = string.Format("select max([{0}]) as maxkey from {1}", _sqlpk, _sqlkey); DataTable _dt = HtnData.Query(_sql); if (_dt == null || _dt.Rows.Count == 0) { return(_result.Replace("{0}", "")); } DataRow _dr = _dt.Rows[0]; string _kekval = _dr.Str("maxkey"); if (string.IsNullOrEmpty(_kekval)) { return(_result.Replace("{0}", "")); } if (_dt.Columns[0].DataType == typeof(DateTime) || _dt.Columns[0].DataType == typeof(string)) { _result = string.Format(_result, " AND " + _sqlpk + " >= '" + _kekval + "'"); } else { _result = string.Format(_result, " AND " + _sqlpk + " >= " + _kekval); } return(_result); }
/// <summary> /// 数据库种判断是否存在 /// </summary> /// <param name="p_dr"></param> /// <returns></returns> public bool IsRowExist(DataRow p_dr) { DataTable _existdt = HtnData.Query(string.Format(_exist, p_dr.Str(0))); return(_existdt != null && _existdt.Rows.Count > 0 && _existdt.Rows[0].Str("len") != "0"); }