CommonService.cs


using System;
using System.Reflection;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using com.unicafe.common;
using com.unicafe.workflow;


namespace com.ascs.plp.publics
{
/// <summary>
/// DataGridPager 的摘要说明。
/// </summary>
public class CommonService
{
/// **************************************************************************
/// BEIGIN
/// <summary>
/// 构造函数
/// </summary>
/// **************************************************************************
public CommonService()
{
}
/// **************************************************************************
/// END
/// **************************************************************************


//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
//以下是对主页面的处理方法集
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 对首次加载的页面进行处理
/// </summary>
/// <param name="thePage">调用此方法的页面对象,建议直接使用this关键字</param>
/// <param name="sql">用于生成绑定DataGrid的数据集的SQL语句</param>
/// <param name="theDG">被绑定的DataGrid控件对象</param>
/// <param name="SessionName">用于与服务器进行交互的Session名称,值为"Data"或"Data1"</param>
/// <param name="PreviousText">“上一页”文本控件</param>
/// <param name="NextText">“下一页”文本控件</param>
/// <param name="PageInfo">“当前第m页/共n页”文本控件</param>
/// <returns>布尔型返回值,执行成功返回true,执行失败返回false,并将错误信息写入错误日志</returns>
/// **************************************************************************
public static bool HandleDataGrid( System.Web.UI.Page thePage,
string sql,
System.Web.UI.WebControls.DataGrid theDG,
string SessionName,
System.Web.UI.WebControls.Label PreviousText,
System.Web.UI.WebControls.Label NextText,
System.Web.UI.WebControls.Label PageInfo)
{
//绑定DataGrid控件
if(BindDataGrid(thePage, sql, theDG, SessionName, false) == false) return false;

//检查是否需要定位
if(LocationDataGrid(thePage, theDG, SessionName) == false) return false;

//给导航文本赋值
if(PageNavigatorText(theDG, PreviousText, NextText, PageInfo) == false) return false;

return true;
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 改变查询条件后,重新查询数据库并重新绑定
/// </summary>
/// <param name="thePage">调用此方法的页面对象,建议直接使用this关键字</param>
/// <param name="sql">用于生成绑定DataGrid的数据集的SQL语句</param>
/// <param name="theDG">被绑定的DataGrid控件对象</param>
/// <param name="SessionName">用于与服务器进行交互的Session名称,值为"Data"或"Data1"</param>
/// <param name="PreviousText">“上一页”文本控件</param>
/// <param name="NextText">“下一页”文本控件</param>
/// <param name="PageInfo">“当前第m页/共n页”文本控件</param>
/// <returns>布尔型返回值,执行成功返回true,执行失败返回false,并将错误信息写入错误日志</returns>
/// **************************************************************************
public static bool ReBindDataGrid( System.Web.UI.Page thePage,
string sql,
System.Web.UI.WebControls.DataGrid theDG,
string SessionName,
System.Web.UI.WebControls.Label PreviousText,
System.Web.UI.WebControls.Label NextText,
System.Web.UI.WebControls.Label PageInfo)
{
//绑定DataGrid控件
if(BindDataGrid(thePage, sql, theDG, SessionName, false) == false) return false;

//给导航文本赋值
if(PageNavigatorText(theDG, PreviousText, NextText, PageInfo) == false) return false;

return true;
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 对DataGrid控件的分页导航链接文本进行赋值
/// </summary>
/// <param name="theDG">DataGrid控件对象</param>
/// <param name="PreviousText">“上一页”文本控件</param>
/// <param name="NextText">“下一页”文本控件</param>
/// <param name="PageInfo">“当前第m页/共n页”文本控件</param>
/// <returns>布尔型返回值,执行成功返回true,执行失败返回false,并将错误信息写入错误日志</returns>
/// **************************************************************************
public static bool PageNavigatorText(DataGrid theDG, Label PreviousText, Label NextText, Label PageInfo)
{
try
{
//给上一页赋值
if (theDG.CurrentPageIndex == 0)
{
PreviousText.Text = "上一页";
}
else
{
PreviousText.Text = "<a href=\"javascript:__doPostBack('" + PreviousText.ClientID +"','')\">上一页</a>";
}

//给下一页赋值
if ((theDG.CurrentPageIndex + 1) == theDG.PageCount)
{
NextText.Text = "下一页";
}
else
{
NextText.Text = "<a href=\"javascript:__doPostBack('" + NextText.ClientID +"','')\">下一页</a>";
}

//给当前第M页/第N页赋值
PageInfo.Text = "当前第<font id=\"PageIndex\">" + Convert.ToString((theDG.CurrentPageIndex + 1)) + "</font>页 / 共" + theDG.PageCount.ToString() + "页";
return true;
}
catch(Exception e)
{
LogService.Write ("PageNavigatorText(DataGrid theDG, Label PreviousText, Label NextText, Label PageInfo, Label TotalText)");
LogService.Write ("在对DataGrid控件的分页导航链接进行处理时发生错误。");
LogService.Write (e.Message);
return false;
}
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 将DataGrid控件与数据查询结果集进行绑定
/// </summary>
/// <param name="thePage">调用此方法的页面对象,建议直接使用this关键字</param>
/// <param name="SqlStatement">用于生成绑定DataGrid的数据集的SQL语句</param>
/// <param name="theDG">被绑定的DataGrid控件对象</param>
/// <param name="SessionName">与服务器相交互的Session名称,值为"Data"或"Data1"</param>
/// <param name="ChangePage">是否需要进行当前页的定位</param>
/// <returns>布尔型返回值,执行成功返回true,执行失败返回false,并将错误信息写入错误日志</returns>
/// **************************************************************************
public static bool BindDataGrid(System.Web.UI.Page thePage, string SqlStatement, System.Web.UI.WebControls.DataGrid theDG, string SessionName, bool ChangePage)
{
//声明并创建一个SqlConnection对象的实例
SqlConnection Connection = new SqlConnection (com.unicafe.common.Configuration.GetDBConnectionString());
try
{
//声明一个用于存储DataGrid对象总页数的整型变量
int PageCount;

//声明并创建一个用于保存数据的DataSet对象
DataSet ds = new DataSet();

SqlDataAdapter SqlDA = new SqlDataAdapter(SqlStatement, Connection);
SqlDA.Fill(ds, "TempDataTable");

DataTable theDT;
theDT = ds.Tables["TempDataTable"];


//判断是否要进行分页调整操作,如果不调整,则将当前页定为第一页
if (ChangePage == true)
{
//计算总页数
if (theDT.Rows.Count % theDG.PageSize == 0)
{
PageCount = theDT.Rows.Count / theDG.PageSize;
}
else
{
PageCount = theDT.Rows.Count / theDG.PageSize + 1;
}
//如果总页数为零,则当前页设为第一页;如果当前页不为零,且当前页超过了总页数,则将当前页置为总页数;其它情况不予处理
if (PageCount == 0)
{
theDG.CurrentPageIndex = 0;
}
else if (theDG.CurrentPageIndex >= PageCount)
{
theDG.CurrentPageIndex = PageCount - 1;
}
else
{
//其它情况不予处理
}
}
else
{
//将当前页定为第一页
theDG.CurrentPageIndex = 0;
}

//将theDG与查询结果集进行绑定
//声明一个用于存储数据集的DataView对象
System.Data.DataView theDV = new DataView(theDT);
theDG.DataSource= theDV;
theDG.DataBind();

//如果总行数为0,则显示页脚,否则不显示
if(theDG.Items.Count == 0)
{
theDG.ShowFooter = true;
theDG.FooterStyle.CopyFrom(theDG.ItemStyle);
}
else
{
theDG.ShowFooter = false;
}

//添加响应鼠标移动的代码行
MouseMoveOnDataGrid(theDG);

//对目标页面的Session变量赋值
thePage.Session[SessionName] = theDT;

//关闭数据库连接对象
Connection.Close();
return true;
}
catch(Exception e)
{
if(Connection.State.ToString() == "Open") Connection.Close();
LogService.Write ("BindDataGrid(System.Web.UI.Page thePage, string SqlStatement, System.Web.UI.WebControls.DataGrid theDG, string SessionName, bool ChangePage)");
LogService.Write ("在将DataGrid控件与数据查询结果集进行绑定时发生错误。");
LogService.Write (e.Message);
return false;
}
}
/// **************************************************************************
/// END
/// **************************************************************************





/// **************************************************************************
/// BEIGIN
/// <summary>
/// 将DataGrid控件与数据查询结果集进行绑定
/// </summary>
/// <param name="thePage">调用此方法的页面对象,建议直接使用this关键字</param>
/// <param name="SqlCmd">用于生成绑定DataGrid的数据集的SqlCommand对象</param>
/// <param name="theDG">被绑定的DataGrid控件对象</param>
/// <param name="SessionName">与服务器相交互的Session名称,值为"Data"或"Data1"</param>
/// <param name="ChangePage">是否需要进行当前页的定位</param>
/// <returns>布尔型返回值,执行成功返回true,执行失败返回false,并将错误信息写入错误日志</returns>
/// **************************************************************************
public static bool BindDataGrid(System.Web.UI.Page thePage, System.Data.SqlClient.SqlCommand SqlCmd, System.Web.UI.WebControls.DataGrid theDG, string SessionName, bool ChangePage)
{
//声明并创建一个SqlConnection对象的实例
SqlConnection Connection = new SqlConnection (com.unicafe.common.Configuration.GetDBConnectionString());
try
{
//声明一个用于存储DataGrid对象总页数的整型变量
int PageCount;

//声明并创建一个用于保存数据的DataSet对象
DataSet ds = new DataSet();

SqlDataAdapter SqlDA = new SqlDataAdapter(SqlCmd);
SqlDA.Fill(ds, "TempDataTable");

//输出到XML文件中
//ds.WriteXml("c:\\data.xml",System.Data.XmlWriteMode.WriteSchema);

DataTable theDT;
theDT = ds.Tables["TempDataTable"];


//判断是否要进行分页调整操作,如果不调整,则将当前页定为第一页
if (ChangePage == true)
{
//计算总页数
if (theDT.Rows.Count % theDG.PageSize == 0)
{
PageCount = theDT.Rows.Count / theDG.PageSize;
}
else
{
PageCount = theDT.Rows.Count / theDG.PageSize + 1;
}
//如果总页数为零,则当前页设为第一页;如果当前页不为零,且当前页超过了总页数,则将当前页置为总页数;其它情况不予处理
if (PageCount == 0)
{
theDG.CurrentPageIndex = 0;
}
else if (theDG.CurrentPageIndex >= PageCount)
{
theDG.CurrentPageIndex = PageCount - 1;
}
else
{
//其它情况不予处理
}
}
else
{
//将当前页定为第一页
theDG.CurrentPageIndex = 0;
}

//将theDG与查询结果集进行绑定
//声明一个用于存储数据集的DataView对象
System.Data.DataView theDV = new DataView(theDT);
theDG.DataSource= theDV;
theDG.DataBind();

//如果总行数为0,则显示页脚,否则不显示
if(theDG.Items.Count == 0)
{
theDG.ShowFooter = true;
theDG.FooterStyle.CopyFrom(theDG.ItemStyle);
}
else
{
theDG.ShowFooter = false;
}

//添加响应鼠标移动的代码行
CommonService.MouseMoveOnDataGrid(theDG);

//对目标页面的Session变量赋值
thePage.Session[SessionName] = theDT;

//关闭数据库连接对象
Connection.Close();
return true;
}
catch(Exception e)
{
if(Connection.State.ToString() == "Open") Connection.Close();
LogService.Write ("BindDataGrid(System.Web.UI.Page thePage, System.Data.SqlClient.SqlCommand SqlCmd, System.Web.UI.WebControls.DataGrid theDG, string SessionName, bool ChangePage)");
LogService.Write ("在将DataGrid控件与数据查询结果集进行绑定时发生错误。");
LogService.Write (e.Message);
return false;
}
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 响应DataGrid控件页面索引改变的方法<br/>
/// </summary>
/// <param name="thePage">调用此方法的页面对象,建议直接使用this关键字</param>
/// <param name="theDG">进行分页导航的DataGrid对象</param>
/// <param name="SessionName">与服务器相交互的Session名称,值为"Data"或"Data1"</param>
/// <param name="PreviousText">“上一页”文本</param>
/// <param name="NextText">“下一页”文本</param>
/// <param name="PageInfo">“当前第m页”文本</param>
/// <returns>布尔型返回值,执行成功返回true,执行失败返回false,并将错误信息写入错误日志</returns>
/// **************************************************************************
public static bool PageNavigate(System.Web.UI.Page thePage, DataGrid theDG, string SessionName, Label PreviousText, Label NextText, Label PageInfo)
{
System.Data.DataTable theDT;
System.Data.DataView theDV;
try
{
if (thePage.Request.Form["__EVENTTARGET"].ToString() == PreviousText.ID)
{
//转到上一页
theDG.CurrentPageIndex --;
theDT = (DataTable)thePage.Session[SessionName];
theDV = new DataView(theDT);
theDG.DataSource = theDV;
theDG.DataBind();

//添加响应鼠标移动的代码行
MouseMoveOnDataGrid(theDG);

//为导航文本赋值
CommonService.PageNavigatorText(theDG, PreviousText, NextText, PageInfo);
}
else if (thePage.Request.Form["__EVENTTARGET"].ToString() == NextText.ID)
{
//转到下一页
theDG.CurrentPageIndex ++;
theDT = (DataTable)thePage.Session[SessionName];
theDV = new DataView(theDT);
theDG.DataSource = theDV;
theDG.DataBind();

//添加响应鼠标移动的代码行
MouseMoveOnDataGrid(theDG);

//为导航文本赋值
CommonService.PageNavigatorText(theDG, PreviousText, NextText, PageInfo);
}
else
{
}
return true;
}
catch(Exception e)
{
LogService.Write ("PageNavigate(System.Web.UI.Page thePage, DataGrid theDG, string SessionName, Label PreviousText, Label NextText, Label PageInfo)");
LogService.Write ("响应DataGrid控件页面索引改变的方法发生错误。");
LogService.Write (e.Message);
return false;
}
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 将DataGrid定位到特定的索引页上
/// </summary>
/// <param name="thePage">调用此方法的页面对象,建议使用this关键字</param>
/// <param name="theDG">被定位的DataGrid对象</param>
/// <param name="SessionName">用于和服务器进行交互的Session名称,建议使用"Data"和"Data1"两者中的一个</param>
/// <returns>布尔型返回值,执行成功返回true,执行失败返回false,并将错误信息写入错误日志</returns>
/// **************************************************************************
public static bool LocationDataGrid(System.Web.UI.Page thePage, System.Web.UI.WebControls.DataGrid theDG, string SessionName)
{
System.Data.DataTable theDT;
System.Data.DataView theDV;
int PageIndex;

try
{
try
{
PageIndex = int.Parse(thePage.Request.QueryString["PageIndex"]) - 1;
}
catch
{
return true;
}
if(PageIndex >= theDG.PageCount)
{
theDG.CurrentPageIndex = theDG.PageCount - 1;
}
else
{
theDG.CurrentPageIndex = PageIndex;
}
theDT = (DataTable)thePage.Session[SessionName];
theDV = new DataView(theDT);
theDG.DataSource = theDV;
theDG.DataBind();

//添加响应鼠标移动的代码行
MouseMoveOnDataGrid(theDG);

return true;
}
catch(Exception e)
{
//不用定位
LogService.Write ("LocationDataGrid(System.Web.UI.Page thePage, DataGrid theDG, string SessionName)");
LogService.Write ("在将DataGrid定位到特定的索引页上时发生错误。");
LogService.Write (e.Message);
return false;
}
}
/// **************************************************************************
/// END
/// **************************************************************************




/// **************************************************************************
/// BEIGIN
/// <summary>
/// 为DataGrid添加响应鼠标移动的代码
/// </summary>
/// <param name="theDG">被添加鼠标移动响应代码的DataGrid控件</param>
/// **************************************************************************
public static void MouseMoveOnDataGrid(System.Web.UI.WebControls.DataGrid theDG)
{
for (int i=0; i<theDG.Items.Count; i++)
{
theDG.Items[i].Attributes["onMouseOver"] = "javascript:this.bgColor='LemonChiffon'; ";
theDG.Items[i].Attributes["onMouseOut"] = "javascript:this.bgColor='white';";
theDG.Items[i].Attributes["ondblclick"] = "javascript:Select(this);";
//theDG.Items[i].Attributes["style"] = "cursor:hand";
}
}
/// **************************************************************************
/// END
/// **************************************************************************









/// **************************************************************************
/// BEIGIN
/// <summary>
/// 根据不同的删除方法进行不同的调用,对选中的数据进行删除(二期老版本)
/// </summary>
/// <param name="thePage">调用此方法的页面对象</param>
/// <param name="theDG">存储数据的DataGrid控件对象</param>
/// <param name="sql">删除之后重新绑定数据时所用的SQL语句,用ViewState["sql"].ToString()作为参数即可</param>
/// <param name="SessionName">用于和服务器进行交互的Session名称,建议使用"Data"和"Data1"两者中的一个</param>
/// <param name="CheckBoxName">存储选中标志的CheckBox控件的ID</param>
/// <param name="DataTypes">主关键字列表的数据类型组成的字符型数组,一定要按删除方法的参数的先后顺序排列</param>
/// <param name="Pk">存储主关键字的Hidden控件对象名组成的字符型数组,一定要按删除方法的参数的先后顺序排列</param>
/// <param name="ClassName">定义删除方法的类名称(需要给出完整路径)</param>
/// <param name="MethodName">删除方法的名称</param>
/// <param name="PathLevel">出错页面与当前页面的相对路径关系</param>
/// <param name="ErrorMessage">出错信息文本</param>
/// <returns>布尔型返回值,成功执行返回true,发生错误返回false</returns>
/// **************************************************************************
public static bool DelSelectRecord( System.Web.UI.Page thePage,
System.Web.UI.WebControls.DataGrid theDG,
string sql,
string SessionName,
string CheckBoxName,
string[] DataTypes,
string[] Pk,
string ClassName,
string MethodName,
int PathLevel,
string ErrorMessage)
{
//生成错误页面的路径
string path = "";

//获取当前的流程ID(FlowId)
string FlowId = "";

for(int k=0; k<PathLevel; k++)
{
path = path + "../";
}

//打开数据库连接
SqlConnection SqlCn = new SqlConnection (com.unicafe.common.Configuration.GetDBConnectionString());
SqlCn.Open();

try
{
//开始事务
//SqlTransaction SqlTrans = SqlCn.BeginTransaction();
//声明存储主关键字的变量
object[] obj = new object[DataTypes.Length];

//对本页上DataGrid的所有行进行遍历
for (int i=0; i<theDG.Items.Count; i++)
{
//将当前行赋值给一个DataGridItem对象
DataGridItem _item = theDG.Items[i];

//判断当前行上的CheckBox控件赋值给一个CheckBox对象
CheckBox CheckFlag = (CheckBox)_item.FindControl(CheckBoxName);

//判断当前行上的复选框是否被选中,如果被选中则进行删除处理,否则不予处理
if(CheckFlag.Checked == true)
{
//获取关键字的值,逐个加入对象数组obj
for (int j=0; j<Pk.Length; j++)
{
obj[j] = ((System.Web.UI.HtmlControls.HtmlInputHidden)_item.FindControl(Pk[j].ToString())).Value; //取各项主关键字
}

//调用删除方法进行删除处理,如果没有成功删除则回滚事务并进入错误页面
if(Reflection(ClassName, MethodName, DataTypes, obj, SqlCn) == false)
{
//SqlTrans.Rollback();
//path = path + "publics/Error.aspx?errmsg=" + ErrorMessage;
//定向到错误页面
//thePage.Response.Redirect(path);
//打开错误信息提示页面
Prompt.PromptError(thePage, ErrorMessage);
return false;
}
}
}

//提交数据库修改
//SqlTrans.Commit();

//重新绑定DataGrid控件
if(CommonService.BindDataGrid(thePage,sql,theDG,SessionName,true) == false)
{
//打开错误信息提示页面
Prompt.PromptError(thePage, "已经成功删除选定的数据,但在重新绑定数据时发生错误。");
return false;
}
else
{
//判断此记录是否在某工作流中
FlowId = thePage.Request.QueryString["flowid"];
//LogService.Write("现在要删除的流程ID:" + FlowId);
if (FlowId != null)
{
WorkflowMgr wMgr = new WorkflowMgr();
wMgr.DelMessage(FlowId);
thePage.Response.Write("<script>");
thePage.Response.Write("window.parent.refreshOpener();");
thePage.Response.Write("window.parent.close();");
thePage.Response.Write("</script>");
}
}
return true;
}
catch(Exception e)
{
//打开错误信息提示页面
Prompt.PromptError(thePage, ErrorMessage);
LogService.Write(e.Message);
return false;
}
finally
{
SqlCn.Close();
}
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 根据不同的情况调用不同的删除方法(二期老版本)
/// </summary>
/// <param name="ClassName">定义该删除方法的类名</param>
/// <param name="MethodName">删除方法名</param>
/// <param name="DataType">主关键字字段数据类型组成的数组</param>
/// <param name="pk">主关键字字段组成的数组</param>
/// **************************************************************************
public static bool Reflection(string ClassName, string MethodName, string[] DataTypes, object[] pk, SqlConnection SqlCn)
{
try
{
Assembly[] asm = AppDomain.CurrentDomain.GetAssemblies();
Type t=null;
int i=0;
do
{
t = asm[i].GetType(ClassName);
i++;
} while (t == null && i<asm.Length);

object obj = Activator.CreateInstance(t);

//将传入的数据类型字符串转化为数据类型数组
Type[] types = ConvertDataType(SqlCn, DataTypes);
//根据方法名和数据类型数组获取方法
MethodInfo m = t.GetMethod(MethodName,types);
//根据数据类型转化数据
object[] aryObj = ConvertData(SqlCn, DataTypes, pk);
//如果转化成功则调用查找到的方法执行
if (aryObj == null)
{
LogService.Write("public static bool reflection(string ClassName, string MethodName, string[] DataType, object[] pk)");
LogService.Write("对主关键字进行特定数据类型转换的操作不成功。");
return false;
}
else
{
object result = m.Invoke(obj,aryObj);
return (bool)result;
}
}
catch(Exception e)
{
LogService.Write("public static bool Reflection(string ClassName, string MethodName, string[] DataTypes, object[] pk)");
LogService.Write("反射函数执行失败。ClassName:" + ClassName + "; MethodName:" + MethodName);
LogService.Write(e.Message);
return false;
}
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 将对象数组按照给定的数据类型进行转换(二期老版本)
/// </summary>
/// <param name="DataType">对象数组对应的数据类型数组</param>
/// <param name="pk">主关键字字段组成的数组</param>
/// **************************************************************************
/// BEIGIN
/// <returns>返回转化后的对象数组</returns>
public static object[] ConvertData(SqlConnection SqlCn, string[] DataType, object[] pk)
{
try
{
object[] obj = new object[DataType.Length + 1];
obj[0] = SqlCn;

for(int i=0; i<DataType.Length; i++)
{
if (DataType[i].ToLower() == "int") //整型
{
obj[i+1] = int.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "double") //双精度浮点型
{
obj[i+1] = double.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "datetime") //日期型
{
obj[i+1] = System.DateTime.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "float") //单精度浮点型
{
obj[i+1] = float.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "decimal") //十进制小数型
{
obj[i+1] = decimal.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "long") //长整型
{
obj[i+1] = long.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "short") //短整型
{
obj[i+1] = short.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "bool") //布尔型
{
obj[i+1] = bool.Parse(pk[i].ToString());
}
else //不处理
{
obj[i+1] = pk[i].ToString();
}
}
return obj;
}
catch(Exception e)
{
LogService.Write("public static void ConvertDataType(SqlConnection SqlCn, string[] DataType, object[] pk)");
LogService.Write(e.Message);
return null;
}

}
/// **************************************************************************
/// END
/// **************************************************************************





/// **************************************************************************
/// BEIGIN
/// <summary>
/// 将数据类型名称数组转化为数据类型数组(二期老版本)
/// </summary>
/// <param name="DataTypes">数据类型名称数组</param>
/// <returns></returns>
/// **************************************************************************
public static Type[] ConvertDataType(SqlConnection SqlCn, string[] DataTypes)
{
try
{
Type[] types = new Type[DataTypes.Length + 1];
types[0] = typeof(SqlConnection);
for(int i=0; i<DataTypes.Length; i++)
{
if(DataTypes[i]=="int")
{
types[i+1] = typeof(int);
}
else if(DataTypes[i]=="string")
{
types[i+1] = typeof(string);
}
else if(DataTypes[i]=="float")
{
types[i+1] = typeof(float);
}
else if(DataTypes[i]=="long")
{
types[i+1] = typeof(long);
}
else if(DataTypes[i]=="short")
{
types[i+1] = typeof(short);
}
else if(DataTypes[i]=="bool")
{
types[i+1] = typeof(bool);
}
else if(DataTypes[i]=="decimal")
{
types[i+1] = typeof(decimal);
}
else if(DataTypes[i]=="double")
{
types[i+1] = typeof(double);
}
else if(DataTypes[i]=="DateTime")
{
types[i+1] = typeof(DateTime);
}
else
{
return null;
}
}
return types;
}
catch(Exception e)
{
LogService.Write("public static Type[] ConvertDataType(SqlConnection SqlCn, string[] DataTypes)");
LogService.Write(e.Message);
return null;
}
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 根据不同的删除方法进行不同的调用,对选中的数据进行删除(三期新版本)
/// </summary>
/// <param name="thePage">调用此方法的页面对象</param>
/// <param name="theDG">存储数据的DataGrid控件对象</param>
/// <param name="sql">删除之后重新绑定数据时所用的SQL语句,用ViewState["sql"].ToString()作为参数即可</param>
/// <param name="SessionName">用于和服务器进行交互的Session名称,建议使用"Data"和"Data1"两者中的一个</param>
/// <param name="CheckBoxName">存储选中标志的CheckBox控件的ID</param>
/// <param name="DataTypes">主关键字列表的数据类型组成的字符型数组,一定要按删除方法的参数的先后顺序排列</param>
/// <param name="Pk">存储主关键字的Hidden控件对象名组成的字符型数组,一定要按删除方法的参数的先后顺序排列</param>
/// <param name="ClassName">定义删除方法的类名称(需要给出完整路径)</param>
/// <param name="MethodName">删除方法的名称</param>
/// <param name="ErrorMessage">出错信息文本</param>
/// <returns>布尔型返回值,成功执行返回true,发生错误返回false</returns>
/// **************************************************************************
public static bool DelSelectRecord( System.Web.UI.Page thePage,
System.Web.UI.WebControls.DataGrid theDG,
string sql,
string SessionName,
string CheckBoxName,
string[] DataTypes,
string[] Pk,
string ClassName,
string MethodName,
string ErrorMessage)
{
//获取当前的流程ID(FlowId)
string FlowId = "";

//打开数据库连接
SqlConnection SqlCn = new SqlConnection (com.unicafe.common.Configuration.GetDBConnectionString());
SqlCn.Open();
SqlCommand cmd = SqlCn.CreateCommand();

try
{
//开始事务
SqlTransaction SqlTrans = SqlCn.BeginTransaction();
cmd.Transaction = SqlTrans;

//声明存储主关键字的变量
object[] obj = new object[DataTypes.Length];

//对本页上DataGrid的所有行进行遍历
for (int i=0; i<theDG.Items.Count; i++)
{
//将当前行赋值给一个DataGridItem对象
DataGridItem _item = theDG.Items[i];

//判断当前行上的CheckBox控件赋值给一个CheckBox对象
CheckBox CheckFlag = (CheckBox)_item.FindControl(CheckBoxName);

//判断当前行上的复选框是否被选中,如果被选中则进行删除处理,否则不予处理
if(CheckFlag.Checked == true)
{
//获取关键字的值,逐个加入对象数组obj
for (int j=0; j<Pk.Length; j++)
{
obj[j] = ((System.Web.UI.HtmlControls.HtmlInputHidden)_item.FindControl(Pk[j].ToString())).Value; //取各项主关键字
}

//调用删除方法进行删除处理,如果没有成功删除则回滚事务并打开错误提示页面
if(Reflection(ClassName, MethodName, DataTypes, obj, cmd) == false)
{
SqlTrans.Rollback();

//打开错误信息提示页面
Prompt.PromptError(thePage, ErrorMessage);
return false;
}
}
}

//提交数据库修改
SqlTrans.Commit();

//重新绑定DataGrid控件
if(CommonService.BindDataGrid(thePage,sql,theDG,SessionName,true) == false)
{
//打开错误信息提示页面
Prompt.PromptError(thePage, "已经成功删除选定的数据,但在重新绑定数据时发生错误。");
return false;
}
else
{
//判断此记录是否在某工作流中
FlowId = thePage.Request.QueryString["flowid"];
//LogService.Write("现在要删除的流程ID:" + FlowId);
if (FlowId != null)
{
WorkflowMgr wMgr = new WorkflowMgr();
wMgr.DelMessage(FlowId);
thePage.Response.Write("<script>");
thePage.Response.Write("window.parent.refreshOpener();");
thePage.Response.Write("window.parent.close();");
thePage.Response.Write("</script>");
}
}
return true;
}
catch(Exception e)
{
//打开错误信息提示页面
Prompt.PromptError(thePage, ErrorMessage);
LogService.Write(e.Message);
return false;
}
finally
{
SqlCn.Close();
}
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 根据不同的情况调用不同的删除方法(三期新版本)
/// </summary>
/// <param name="ClassName">定义该删除方法的类名</param>
/// <param name="MethodName">删除方法名</param>
/// <param name="DataType">主关键字字段数据类型组成的数组</param>
/// <param name="pk">主关键字字段组成的数组</param>
/// <param name="SqlCmd">SqlCommand对象</param>
/// <returns>布尔型返回值,成功执行返回true,发生错误返回false</returns>
/// **************************************************************************
public static bool Reflection(string ClassName, string MethodName, string[] DataTypes, object[] pk, SqlCommand SqlCmd)
{
//删除SqlCommand对象的所有参数
SqlCmd.Parameters.Clear();

try
{
Assembly[] asm = AppDomain.CurrentDomain.GetAssemblies();
Type t=null;
int i=0;
do
{
t = asm[i].GetType(ClassName);
i++;
} while (t == null && i<asm.Length);

object obj = Activator.CreateInstance(t);

//将传入的数据类型字符串转化为数据类型数组
Type[] types = ConvertDataType(SqlCmd, DataTypes);
//根据方法名和数据类型数组获取方法
MethodInfo m = t.GetMethod(MethodName,types);
//根据数据类型转化数据
object[] aryObj = ConvertData(SqlCmd, DataTypes, pk);
//如果转化成功则调用查找到的方法执行
if (aryObj == null)
{
LogService.Write("public static bool reflection(string ClassName, string MethodName, string[] DataType, object[] pk)");
LogService.Write("对主关键字进行特定数据类型转换的操作不成功。");
return false;
}
else
{
object result = m.Invoke(obj,aryObj);
return (bool)result;
}
}
catch(Exception e)
{
LogService.Write("public static bool Reflection(string ClassName, string MethodName, string[] DataTypes, object[] pk)");
LogService.Write("反射函数执行失败。ClassName:" + ClassName + "; MethodName:" + MethodName);
LogService.Write(e.Message);
return false;
}
}
/// **************************************************************************
/// END
/// **************************************************************************



/// **************************************************************************
/// BEIGIN
/// <summary>
/// 将对象数组按照给定的数据类型进行转换(三期新版本)
/// </summary>
/// <param name="SqlCmd">SqlCommand对象</param>
/// <param name="DataType">对象数组对应的数据类型数组</param>
/// <param name="pk">主关键字字段组成的数组</param>
/// <returns>返回转化后的对象数组</returns>
/// **************************************************************************
public static object[] ConvertData(SqlCommand SqlCmd, string[] DataType, object[] pk)
{
try
{
object[] obj = new object[DataType.Length + 1];
obj[0] = SqlCmd;

for(int i=0; i<DataType.Length; i++)
{
if (DataType[i].ToLower() == "int") //整型
{
obj[i+1] = int.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "double") //双精度浮点型
{
obj[i+1] = double.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "datetime") //日期型
{
obj[i+1] = System.DateTime.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "float") //单精度浮点型
{
obj[i+1] = float.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "decimal") //十进制小数型
{
obj[i+1] = decimal.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "long") //长整型
{
obj[i+1] = long.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "short") //短整型
{
obj[i+1] = short.Parse(pk[i].ToString());
}
else if(DataType[i].ToLower() == "bool") //布尔型
{
obj[i+1] = bool.Parse(pk[i].ToString());
}
else //不处理
{
obj[i+1] = pk[i].ToString();
}
}
return obj;
}
catch(Exception e)
{
LogService.Write("public static void ConvertDataType(SqlConnection SqlCmd, string[] DataType, object[] pk)");
LogService.Write(e.Message);
return null;
}

}
/// **************************************************************************
/// END
/// **************************************************************************





/// **************************************************************************
/// BEIGIN
/// <summary>
/// 将数据类型名称数组转化为数据类型数组(三期新版本)
/// </summary>
/// <param name="SqlCmd">SqlCommand对象</param>
/// <param name="DataTypes">数据类型名称数组</param>
/// <returns></returns>
/// **************************************************************************
public static Type[] ConvertDataType(SqlCommand SqlCmd, string[] DataTypes)
{
try
{
Type[] types = new Type[DataTypes.Length + 1];
types[0] = typeof(SqlCommand);
for(int i=0; i<DataTypes.Length; i++)
{
if(DataTypes[i]=="int")
{
types[i+1] = typeof(int);
}
else if(DataTypes[i]=="string")
{
types[i+1] = typeof(string);
}
else if(DataTypes[i]=="float")
{
types[i+1] = typeof(float);
}
else if(DataTypes[i]=="long")
{
types[i+1] = typeof(long);
}
else if(DataTypes[i]=="short")
{
types[i+1] = typeof(short);
}
else if(DataTypes[i]=="bool")
{
types[i+1] = typeof(bool);
}
else if(DataTypes[i]=="decimal")
{
types[i+1] = typeof(decimal);
}
else if(DataTypes[i]=="double")
{
types[i+1] = typeof(double);
}
else if(DataTypes[i]=="DateTime")
{
types[i+1] = typeof(DateTime);
}
else
{
return null;
}
}
return types;
}
catch(Exception e)
{
LogService.Write("public static Type[] ConvertDataType(SqlCommand SqlCmd, string[] DataTypes)");
LogService.Write(e.Message);
return null;
}
}
/// **************************************************************************
/// END
/// **************************************************************************


//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
//以下是对子窗口的处理方法集
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 通过父页面的URL获得主关键字
/// </summary>
/// <param name="thePage">调用此方法的Web页面对象</param>
/// <returns>主关键字数组</returns>
/// **************************************************************************
public static string[] GetPks(System.Web.UI.Page thePage)
{
//获得父页面的完整URL并通过“|”进行分解
string[] pks = thePage.Request.QueryString["ParentURL"].Split('|');
//将分解后的字符串进行处理,获得主关键字数组
for (int i=0; i<pks.Length; i++)
{
pks[i] = pks[i].Substring(pks[i].LastIndexOf("=") + 1);
}
return pks;
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 通过页面的URL获得主关键字
/// </summary>
/// <param name="thePage">调用此方法的Web页面对象</param>
/// <returns>主关键字数组</returns>
/// **************************************************************************
public static string[] GetCurrentPks(System.Web.UI.Page thePage)
{
//把页面的完整URL通过“&”进行分解
string[] original_pks = thePage.Request.RawUrl.Split('&');
string[] pks = new string[original_pks.Length - 2];
//将分解后的字符串进行处理,获得主关键字数组
for (int i=2; i<original_pks.Length; i++)
{
pks[i-2] = original_pks[i].Substring(original_pks[i].LastIndexOf("=") + 1);
}
return pks;
}
/// **************************************************************************
/// END
/// **************************************************************************



/// **************************************************************************
/// BEIGIN
/// <summary>
/// 在弹出窗口中生成返回时父页面的完整URL
/// </summary>
/// <param name="thePage">弹出窗口的Web页面对象</param>
/// <returns>父页面的完整URL</returns>
/// **************************************************************************
public static string CreatReturnURL(System.Web.UI.Page thePage)
{
//获取父页面的当前页索引
string PageIndex = thePage.Request.QueryString["PageIndex"];
//获取父页面的URL
string ParentURL = thePage.Request.QueryString["ParentURL"];

//将父页面的URL进行还原
ParentURL = ParentURL.Replace("|","&");

//检查父页面的URL中是否含有页面信息,分别进行不同的生成处理
if(ParentURL.LastIndexOf("PageIndex") == -1)
{
string LinkChar;
if (ParentURL.IndexOf("?") != -1)
{
LinkChar = "&";
}
else
{
LinkChar = "?";
}
return(ParentURL + LinkChar + "PageIndex=" + PageIndex);
}
else
{
return(ParentURL.Substring(0,ParentURL.LastIndexOf("=") + 1) + PageIndex);
}
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 关闭窗口页面,返回父页面
/// </summary>
/// <param name="thePage">子页面的Page对象</param>
/// **************************************************************************
public static void Return(System.Web.UI.Page thePage)
{
string ReturnURL;
ReturnURL = CommonService.CreatReturnURL(thePage);
thePage.Response.Write("<script language=javascript>window.opener.location='" + ReturnURL + "';window.close();</script>");
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 返回特定的父页面
/// </summary>
/// <param name="thePage">子页面的Page对象</param>
/// <param name="ReturnURL">父页面的URL,如果参数为null,表示由系统来取得父页面的URL</param>
/// <param name="Flag">是否关闭子窗口的开关标记,true表示关闭子窗口,false表示不关闭子窗口</param>
/// **************************************************************************
public static void Return(System.Web.UI.Page thePage, string ReturnURL, bool Flag)
{
string script;
if(ReturnURL == null)
{
ReturnURL = CommonService.CreatReturnURL(thePage);
}
script = "<script language=javascript>window.opener.location='" + ReturnURL + "';";
if(Flag == true)
{
script = script + "window.close();";
}
script =script + "</script>";
thePage.Response.Write(script);
}
/// **************************************************************************
/// END
/// **************************************************************************


//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
//以下是对下拉列表框的处理方法集
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 根据查询语句对下拉列表框控件与数据记录集进行绑定<br/>
/// 注意事项:ValueField和TextField必须是SqlStatement查询结果集中的两个字段
/// </summary>
/// <param name="theDDL">DropDownList控件对象</param>
/// <param name="SqlStatement">检索数据的SQL语句</param>
/// <param name="ValueField">DropDownList的值域</param>
/// <param name="TextField">DropDownList的文本域</param>
/// <returns>布尔型返回值,执行成功返回true,执行失败返回false,并将错误信息写入错误日志</returns>
/// **************************************************************************
public static bool BindDropDownList( System.Web.UI.WebControls.DropDownList theDDL,
string SqlStatement,
string ValueField,
string TextField)
{
//声明并创建一个SqlConnection对象的实例
SqlConnection Connection = new SqlConnection (com.unicafe.common.Configuration.GetDBConnectionString());

try
{
//声明并创建一个SqlCommand对象的实例
System.Data.SqlClient.SqlCommand SqlCmd = Connection.CreateCommand();

//给SqlCommand对象指定到某个SQL语句
SqlCmd.CommandText = SqlStatement;

//打开数据库连接对象
Connection.Open();

//声明并使用SqlCommand的ExecuteReader方法创建一个SqlDataReader对象的实例
System.Data.SqlClient.SqlDataReader SqlDR = SqlCmd.ExecuteReader();

//将查询结果集与下拉列表框控件进行绑定
theDDL.DataSource = SqlDR;
theDDL.DataValueField = ValueField;
theDDL.DataTextField = TextField;
theDDL.DataBind();

//关闭数据库连接对象
Connection.Close();
return true;
}
catch(Exception e)
{
if(Connection.State.ToString() == "Open") Connection.Close();
LogService.Write ("BindDropDownList(System.Web.UI.WebControls.DropDownList theDDL,string SqlStatement,string ValueField,string TextField)");
LogService.Write ("在根据查询语句对下拉列表框控件与数据记录集进行绑定时发生错误。");
LogService.Write (e.Message);
return false;
}
}
/// **************************************************************************
/// END
/// **************************************************************************





/// **************************************************************************
/// BEIGIN
/// <summary>
/// 对DropDownList控件中某个特定的值进行定位
/// </summary>
/// <param name="theDDL">下拉列表控件对象(传递值)</param>
/// <param name="selectvalue">要定位的项的Value值(传递值)</param>
/// <returns>布尔型返回值,执行成功返回true,执行失败返回false,并将错误信息写入错误日志</returns>
/// **************************************************************************
public static bool LocateDropDownList(System.Web.UI.WebControls.DropDownList theDDL, string SelectValue)
{
try
{
for(int i=0; i<theDDL.Items.Count; i++)
{
if (theDDL.Items[i].Value == SelectValue)
{
theDDL.SelectedIndex = i;
return true;
}
}
LogService.Write ("LocateDropDownList(" + theDDL.ID + ", " + SelectValue +")");
LogService.Write ("没有在DropDownList中查找到所要定位的特定值。");
return false;
}
catch(Exception e)
{
LogService.Write ("LocateDropDownList(System.Web.UI.WebControls.DropDownList theDDL, string SelectValue)");
LogService.Write ("在对DropDownList中的特定值进行定位时发生异常。");
LogService.Write (e.Message);
return false;
}
}
/// **************************************************************************
/// END
/// **************************************************************************


//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------
//以下是数据库通用查询结果方法集
//---------------------------------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------------------------------


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 根据SqlCommand对象查询执行数据库查询并返回结果
/// </summary>
/// <param name="sql">执行数据库查询的查询结果</param>
/// <param name="i">为1时表示执行ExecuteNonQuery(),为2时表示执行ExecuteReader(),为3时表示执行ExecuteScalar(),其它情况返回null,发生异常也返回null</param>
/// <returns>查询结果</returns>
/// **************************************************************************
public static object ExecQuery(SqlCommand SqlCmd, int i)
{
object result;

try
{
//打开数据库连接对象
SqlCmd.Connection.Open();

if(i == 1)
{
//执行数据库查询,成功后返回true
SqlCmd.ExecuteNonQuery();
result = true;
}
else if(i == 2)
{
//声明并使用SqlCommand的ExecuteReader方法创建一个SqlDataReader对象的实例,返回结果集
System.Data.SqlClient.SqlDataReader SqlDR = SqlCmd.ExecuteReader();
result = SqlDR;
}
else if(i == 3)
{
//执行数据库查询返回查询结果
result = SqlCmd.ExecuteScalar();
}
else
{
result = null;
}
SqlCmd.Connection.Close();
return result;
}
catch(Exception e)
{
if(SqlCmd.Connection.State.ToString() == "Open") SqlCmd.Connection.Close();
LogService.Write ("ExecQuery(SqlCommand SqlCmd, int i)");
LogService.Write ("在执行数据库查询时发生错误。");
LogService.Write (e.Message);
return null;
}
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 根据SQL语句查询执行数据库查询并返回结果
/// </summary>
/// <param name="sql">执行数据库查询的查询结果</param>
/// <param name="i">为1时表示执行ExecuteNonQuery(),为2时表示执行ExecuteReader(),为3时表示执行ExecuteScalar(),其它情况返回null,发生异常也返回null</param>
/// <returns>查询结果</returns>
/// **************************************************************************
public static object ExecQuery(string sql, int i)
{
//声明并创建一个SqlConnection对象的实例
SqlConnection Connection = new SqlConnection (com.unicafe.common.Configuration.GetDBConnectionString());

//声明并创建一个SqlCommand对象的实例
System.Data.SqlClient.SqlCommand SqlCmd = Connection.CreateCommand();

//给SqlCommand对象指定到某个SQL语句
SqlCmd.CommandText = sql;

return ExecQuery(SqlCmd, i);
}
/// **************************************************************************
/// END
/// **************************************************************************


/// **************************************************************************
/// BEIGIN
/// <summary>
/// 根据带参数的SQL语句查询执行数据库查询并返回结果
/// </summary>
/// <param name="sql">执行数据库查询的查询结果</param>
/// <param name="i">为1时表示执行ExecuteNonQuery(),为2时表示执行ExecuteReader(),为3时表示执行ExecuteScalar(),其它情况返回null,发生异常也返回null</param>
/// <returns>查询结果</returns>
/// **************************************************************************
public static object ExecQuery(string sql, string[]ParaTypes, string[] ParaNames, object[] ParaValues, int i)
{
//声明并创建一个SqlConnection对象的实例
SqlConnection Connection = new SqlConnection (com.unicafe.common.Configuration.GetDBConnectionString());

//声明并创建一个SqlCommand对象的实例
System.Data.SqlClient.SqlCommand SqlCmd = Connection.CreateCommand();

//给SqlCommand对象指定到某个SQL语句
SqlCmd.CommandText = sql;
SqlCmd.Parameters.Clear();
for(int j=0; j<ParaNames.Length; i++)
{
SqlCmd.Parameters.Add(ParaNames[j], ParaValues[j]);
}

return ExecQuery(SqlCmd, i);
}
/// **************************************************************************
/// END
/// **************************************************************************

}
}

解释这段代码@IgnoreAuth @RequestMapping("/cal/{tableName}/{columnName}") public R cal(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) { Map<String, Object> params = new HashMap<String, Object>(); params.put("table", tableName); params.put("column", columnName); Map<String, Object> result = commonService.selectCal(params); return R.ok().put("data", result); } /** * 分组统计 */ @IgnoreAuth @RequestMapping("/group/{tableName}/{columnName}") public R group(@PathVariable("tableName") String tableName, @PathVariable("columnName") String columnName) { Map<String, Object> params = new HashMap<String, Object>(); params.put("table", tableName); params.put("column", columnName); List<Map<String, Object>> result = commonService.selectGroup(params); return R.ok().put("data", result); } /** * (按值统计) */ @IgnoreAuth @RequestMapping("/value/{tableName}/{xColumnName}/{yColumnName}") public R value(@PathVariable("tableName") String tableName, @PathVariable("yColumnName") String yColumnName, @PathVariable("xColumnName") String xColumnName) { Map<String, Object> params = new HashMap<String, Object>(); params.put("table", tableName); params.put("xColumn", xColumnName); params.put("yColumn", yColumnName); List<Map<String, Object>> result = commonService.selectValue(params); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); for(Map<String, Object> m : result) { for(String k : m.keySet()) { if(m.get(k) instanceof Date) { m.put(k, sdf.format((Date)m.get(k))); } } } return R.ok().put("data", result); } }
05-17
{ type: "searchSelect", placeholder: "签约机构", valueName: 'signOrganId', optionName: "label", searchItemName: "label", optionId: "key", searchApi:commonService.orgPageList({}).then(res=>{ const {retData}=res retData.map(item=>{ return {key: item.id, label: item.organName, value: item.id,} }) }) }, 分析一下此段代码的报错 汉语解释index.jsx:55 Uncaught TypeError: item.searchApi is not a function at searchQuery (index.jsx:55:1) at onFocus (index.jsx:129:1) at onContainerFocus (BaseSelect.js:326:1) at HTMLUnknownElement.callCallback (react-dom.development.js:188:1) at Object.invokeGuardedCallbackDev (react-dom.development.js:237:1) at invokeGuardedCallback (react-dom.development.js:292:1) at invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:306:1) at executeDispatch (react-dom.development.js:389:1) at executeDispatchesInOrder (react-dom.development.js:414:1) at executeDispatchesAndRelease (react-dom.development.js:3278:1) at executeDispatchesAndReleaseTopLevel (react-dom.development.js:3287:1) at forEachAccumulated (react-dom.development.js:3259:1) at runEventsInBatch (react-dom.development.js:3304:1) at runExtractedPluginEventsInBatch (react-dom.development.js:3514:1) at handleTopLevel (react-dom.development.js:3558:1) at batchedEventUpdates$1 (react-dom.development.js:21871:1) at batchedEventUpdates (react-dom.development.js:795:1) at dispatchEventForLegacyPluginEventSystem (react-dom.development.js:3568:1) at attemptToDispatchEvent (react-dom.development.js:4267:1) at dispatchEvent (react-dom.development.js:4189:1) at unstable_runWithPriority (scheduler.development.js:653:1) at runWithPriority$1 (react-dom.development.js:11039:1) at discreteUpdates$1 (react-dom.development.js:21887:1) at discreteUpdates (react-dom.development.js:806:1) at dispatchDiscreteEvent (react-dom.development.js:4168:1)
07-13
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值