| | |
| | | |
| | | #region APP根据设备id进行自动登录 |
| | | |
| | | |
| | | |
| | | [HttpGet] |
| | | [Route("Web/getSysParameter")] |
| | | public object getSysParameter(string HClientID) |
| | |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #region 根据表名获取sql语句 |
| | | [HttpGet] |
| | | [Route("Web/getSQL")] |
| | | public object getSQL(string TableName, string ModeName, string OpertionType, string Identityid) |
| | | { |
| | | if (OpertionType == "insert") |
| | | { |
| | | string sql = $"select * from {TableName}"; |
| | | DataSet ds = oCN.RunProcReturn(sql, TableName); |
| | | |
| | | if (ds == null || ds.Tables[0].Rows.Count <= 0) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "系统参数不存在,请联系管理"; |
| | | objJsonResult.data = 0; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | sql = $"exec h_p_sqlhelper '{TableName}'"; |
| | | ds = oCN.RunProcReturn(sql, "h_p_sqlhelper"); |
| | | |
| | | if (ds == null || ds.Tables.Count < 2 || ds.Tables[1].Rows.Count <= 0) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "系统参数不存在,请联系管理"; |
| | | objJsonResult.data = 0; |
| | | return objJsonResult; |
| | | } |
| | | |
| | | StringBuilder sb = new StringBuilder(); |
| | | string columnsStr = ds.Tables[0].Rows[0][0].ToString(); |
| | | sb.AppendLine($"sqlRes = $\"INSERT INTO [{TableName}] ({columnsStr})"); |
| | | sb.AppendLine(" VALUES ("); |
| | | |
| | | // 2. 拼接 VALUES 里面的参数 |
| | | int count = ds.Tables[1].Rows.Count; |
| | | for (int i = 0; i < count; i++) |
| | | { |
| | | string propName = ds.Tables[1].Rows[i][0].ToString(); |
| | | string valueFormat = ""; |
| | | if (propName == "HMakeDate") |
| | | { |
| | | valueFormat = "getdata()"; |
| | | } |
| | | else if (propName == "HERPItemID") |
| | | { |
| | | valueFormat = "'{0}'"; |
| | | } |
| | | else |
| | | { |
| | | valueFormat = $"'{{{ModeName}.{propName}}}'"; // 默认通用逻辑 |
| | | } |
| | | sb.Append(" " + valueFormat); |
| | | |
| | | if (i < count - 1) |
| | | { |
| | | sb.Append(","); |
| | | } |
| | | sb.AppendLine(); |
| | | } |
| | | sb.AppendLine(" ); \";"); |
| | | sb.Append(" oCN.RunProc(sqlRes);"); |
| | | |
| | | objJsonResult.code = "1"; |
| | | objJsonResult.count = 1; |
| | | objJsonResult.Message = "成功"; |
| | | objJsonResult.data = sb; |
| | | return objJsonResult; |
| | | } |
| | | else |
| | | { |
| | | string whereKey = Identityid; |
| | | string sql = $"select * from {TableName}"; |
| | | DataSet ds = oCN.RunProcReturn(sql, TableName); |
| | | |
| | | if (ds == null || ds.Tables[0].Rows.Count <= 0) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "系统参数不存在,请联系管理"; |
| | | objJsonResult.data = 0; |
| | | return objJsonResult; |
| | | } |
| | | sql = $"exec h_p_sqlhelper '{TableName}'"; |
| | | ds = oCN.RunProcReturn(sql, "h_p_sqlhelper"); |
| | | |
| | | if (ds == null || ds.Tables.Count < 2 || ds.Tables[1].Rows.Count <= 0) |
| | | { |
| | | objJsonResult.code = "0"; |
| | | objJsonResult.count = 0; |
| | | objJsonResult.Message = "系统参数不存在,请联系管理"; |
| | | objJsonResult.data = 0; |
| | | return objJsonResult; |
| | | } |
| | | StringBuilder sb = new StringBuilder(); |
| | | |
| | | sb.Append($"sqlRes =$\"Update {TableName} set "); |
| | | |
| | | int count = ds.Tables[1].Rows.Count; |
| | | int setFieldCount = 0; |
| | | |
| | | for (int i = 0; i < count; i++) |
| | | { |
| | | string propName = ds.Tables[1].Rows[i][0].ToString(); |
| | | |
| | | |
| | | if (propName == whereKey) |
| | | continue; |
| | | |
| | | |
| | | if (setFieldCount > 0) |
| | | { |
| | | sb.Append(","); |
| | | } |
| | | string valueFormat = ""; |
| | | if (propName == "HModifyTime" || propName == "HUpDateDate") |
| | | { |
| | | valueFormat = $"{propName}=getdate()"; |
| | | } |
| | | else |
| | | { |
| | | valueFormat = $"{propName}='{{{ModeName}.{propName}}}'"; |
| | | } |
| | | sb.Append("\r\n " + valueFormat); |
| | | |
| | | setFieldCount++; |
| | | } |
| | | |
| | | sb.Append($" where {whereKey}='{{{ModeName}.{whereKey}}}'\""); |
| | | sb.AppendLine(); |
| | | sb.Append("oCN.RunProc(sqlRes);"); |
| | | |
| | | |
| | | objJsonResult.code = "1"; |
| | | objJsonResult.count = 1; |
| | | objJsonResult.Message = "成功"; |
| | | objJsonResult.data = sb; |
| | | return objJsonResult; |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | |
| | | |
| | | } |
| | | |