/// <summary> /// 获取要导出表头字段 /// </summary> /// <returns></returns> public ActionResult GetDeriveExcelColumn() { string JsonColumn = GZipHelper.Uncompress(WebHelper.GetCookie("JsonColumn_DeriveExcel")); return(Content(JsonColumn)); }
/// <summary> /// 解析XML字符串格式 /// </summary> /// <param name="Xml"></param> /// <param name="arrSql">返回SQL</param> /// <param name="arrParam">返回参数化</param> /// <param name="Action">操作动作</param> private void AnalysisXml(string Xml, out ArrayList arrSql, out ArrayList arrParam, out string Action) { Xml = GZipHelper.Uncompress(Xml); ArrayList _arrSql = new ArrayList(); ArrayList _arrParam = new ArrayList(); string _Action = "-1"; try { XmlDocument xd = new XmlDocument(); xd.LoadXml(Xml); foreach (XmlNode node in xd.ChildNodes) { if (node.Name.Trim() == "Request") { foreach (XmlNode subnode in node.ChildNodes) { if (subnode.Name.Trim() == "data") { //根据接口代码获取对象 Base_InterfaceManage interfacemanage = Repository().FindEntity("Code", subnode.Attributes["code"].Value); if (interfacemanage.InterfaceId != null) { _Action = interfacemanage.Action; //动作类型 string Constraint = interfacemanage.Constraints; //约束达式 foreach (XmlNode node_data in subnode.ChildNodes) { if (node_data.Name.Trim() == "no") { string pkName; string pkVal; switch (_Action) { case "Insert": //新增 Hashtable ht_add = this.XmlNodeToHashtable(node_data); _arrSql.Add(DatabaseCommon.InsertSql(Constraint.Trim(), ht_add)); _arrParam.Add(DatabaseCommon.GetParameter(ht_add)); break; case "Update": //修改 Hashtable ht_edit = this.XmlNodeToHashtable(node_data, out pkName, out pkVal); _arrSql.Add(new StringBuilder(Constraint.Trim())); _arrParam.Add(DatabaseCommon.GetParameter(ht_edit)); break; case "Delete": //删除 Hashtable ht_Delete = this.XmlNodeToHashtable(node_data, out pkName, out pkVal); _arrSql.Add(DatabaseCommon.DeleteSql(Constraint.Trim(), pkName)); _arrParam.Add(DbFactory.CreateDbParameter("@" + pkName, pkVal)); break; case "Select": //查询 Hashtable ht_Param = this.XmlNodeToHashtable(node_data); _arrSql.Add(Constraint.Trim()); _arrParam.Add(DatabaseCommon.GetParameter(ht_Param)); break; case "Procedure": //存储过程 Hashtable ExecuteByProc = this.XmlNodeToHashtable(node_data); _arrSql.Add(Constraint.Trim()); _arrParam.Add(ExecuteByProc); break; case "DataTableProc": //存储过程-DataTableProc Hashtable DataTableProc = this.XmlNodeToHashtable(node_data); _arrSql.Add(Constraint.Trim()); _arrParam.Add(DataTableProc); break; case "DataSetProc": //存储过程-DataSetProc Hashtable DataSetProc = this.XmlNodeToHashtable(node_data); _arrSql.Add(Constraint.Trim()); _arrParam.Add(DataSetProc); break; case "-1": //异常信息 break; default: break; } } } } else { log.Error(Xml.ToString() + "\r\n接口不存在\r\n"); } } } break; } } } catch (Exception e) { log.Error(Xml.ToString() + "\r\n" + e.Message + "\r\n"); } finally { arrSql = _arrSql; arrParam = _arrParam; Action = _Action; } }
/// <summary> /// 业务接口调用 /// </summary> /// <param name="Xml">XML格式</param> /// <param name="DeviceMark">设备号</param> /// <param name="Token">记号</param> /// <returns></returns> public string Invoke(string Xml, string DeviceMark, string Token) { //Stopwatch sw = new Stopwatch(); //sw.Start(); Xml = GZipHelper.Uncompress(Xml); StringBuilder Output = new StringBuilder(); ArrayList arraySql = new ArrayList(); ArrayList arrayParam = new ArrayList(); int Type = 0; bool IsOk = false; try { AnalysisXml(Xml, out arraySql, out arrayParam, out Type); switch (Type) { case 0: //新增 IsOk = DataFactory.SqlHelper().BatchExecuteBySql((object[])arraySql.ToArray(typeof(object)), (object[])arrayParam.ToArray(typeof(object))) >= 0 ? true : false; Output.Append(ResultMsg(IsOk, DbErrorMsg.ReturnMsg)); break; case 1: //修改 IsOk = DataFactory.SqlHelper().BatchExecuteBySql((object[])arraySql.ToArray(typeof(object)), (object[])arrayParam.ToArray(typeof(object))) >= 0 ? true : false; Output.Append(ResultMsg(IsOk, DbErrorMsg.ReturnMsg)); break; case 2: //删除 IsOk = DataFactory.SqlHelper().BatchExecuteBySql((object[])arraySql.ToArray(typeof(object)), (object[])arrayParam.ToArray(typeof(object))) >= 0 ? true : false; Output.Append(ResultMsg(IsOk, DbErrorMsg.ReturnMsg)); break; case 3: //查询 string strSql = string.Join(",", (string[])arraySql.ToArray(typeof(string))); object[] arrayParamobject = (object[])arrayParam.ToArray(typeof(object)); SqlParam[] paramArray = (SqlParam[])arrayParamobject[0]; DataTable dt = DataFactory.SqlHelper().GetDataTableBySQL(new StringBuilder(strSql), paramArray); if (DataTableHelper.IsExistRows(dt)) { Output.Append(DataTableHelper.DataTableToXML(dt)); } else { Output.Append(ResultMsg(false, "没有找到您要的相关数据")); } break; case 4: //存储过程-DataTableProc string DataTableProc = string.Join(",", (string[])arraySql.ToArray(typeof(string))); object[] DataTableProcParamobject = (object[])arrayParam.ToArray(typeof(object)); Hashtable DataTableProcparamArray = (Hashtable)DataTableProcParamobject[0]; DataTable DataTableProc_dt = DataFactory.SqlHelper().GetDataTableProc(DataTableProc, DataTableProcparamArray); if (DataTableHelper.IsExistRows(DataTableProc_dt)) { Output.Append(DataTableHelper.DataTableToXML(DataTableProc_dt)); } else { Output.Append(ResultMsg(false, "没有找到您要的相关数据")); } break; case 5: //存储过程-DataSetProc string DataSetProc = string.Join(",", (string[])arraySql.ToArray(typeof(string))); object[] DataSetProcParamobject = (object[])arrayParam.ToArray(typeof(object)); Hashtable DataSetProcparamArray = (Hashtable)DataSetProcParamobject[0]; DataSet DataSetProc_dt = DataFactory.SqlHelper().GetDataSetProc(DataSetProc, DataSetProcparamArray); if (DataSetProc_dt != null) { Output.Append(DataTableHelper.DataSetToXML(DataSetProc_dt)); } else { Output.Append(ResultMsg(false, "没有找到您要的相关数据")); } break; case 6: //存储过程-ExecuteByProc string ExecuteByProc = string.Join(",", (string[])arraySql.ToArray(typeof(string))); object[] ExecuteByProcParamobject = (object[])arrayParam.ToArray(typeof(object)); Hashtable ExecuteByProcparamArray = (Hashtable)ExecuteByProcParamobject[0]; IsOk = DataFactory.SqlHelper().ExecuteByProc(ExecuteByProc, ExecuteByProcparamArray) >= 0 ? true : false; Output.Append(ResultMsg(IsOk, DbErrorMsg.ReturnMsg)); break; case 7: //存储过程-BatchExecuteByProc IsOk = DataFactory.SqlHelper().BatchExecuteByProc((object[])arraySql.ToArray(typeof(object)), (object[])arrayParam.ToArray(typeof(object))) >= 0 ? true : false; Output.Append(ResultMsg(IsOk, DbErrorMsg.ReturnMsg)); break; case -1: //异常信息 Output.Append(ResultMsg(false, Logger.LogErrorMsg)); break; default: break; } } catch (Exception ex) { Output.Append(ResultMsg(false, ex.Message)); } //sw.Stop(); //LoggerTime.WriteLog("服务器处理总耗时:" + sw.ElapsedMilliseconds + "毫秒-----------\r\n"); return(GZipHelper.Compress(Output.ToString())); }