我正在使用JqueryCalendar插件,我可以总结所有事件的总小时数,但不能在月视图中总结单个日期。任何建议。
答案 0 :(得分:0)
终于找到了计算总数的方法
由于我不得不将此项目转换为MVC3,因此我做了一些改动。
程序更改:proc_JQCalendar_listCalendarByRange,已将查询修改为按启动时间排序,因此总计将按天连接。
public static Dictionary listCalendarByRange(string sd,string ed) {
// Convert unitx timestamp to DateTime
DateTime dtSd = fn.ConvertFromUnixTimestamp(Convert.ToDouble(sd));
DateTime dtEd = fn.ConvertFromUnixTimestamp(Convert.ToDouble(ed));
Dictionary<string, object> ret = new Dictionary<string, object>();
string sStp = "proc_JQCalendar_listCalendarByRange";
int sqlReturn = 0;
DataTable dtResults = new DataTable();
SqlConnection oSqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlServer"].ConnectionString);
SqlCommand oSqlCmd = new SqlCommand(sStp, oSqlCon);
SqlDataAdapter oSqlDa = new SqlDataAdapter(oSqlCmd);
try
{
oSqlCmd.CommandType = CommandType.StoredProcedure;
oSqlCmd.CommandTimeout = 900;
SqlParameter paramStartTime = new SqlParameter("@starttime", SqlDbType.DateTime);
SqlParameter paramEndTime = new SqlParameter("@endtime", SqlDbType.DateTime);
// Assign values to parameters
paramStartTime.Value = dtSd;
paramEndTime.Value = dtEd;
// Add the parameters to oSqlCmd object
oSqlCmd.Parameters.Add(paramStartTime);
oSqlCmd.Parameters.Add(paramEndTime);
// Open SQL connection and execute it
oSqlCon.Open();
sqlReturn = oSqlDa.Fill(dtResults);
List<object> evtList = new List<object>();
Decimal totalExpense = 0;
Decimal newtotalExpense = 0;
Decimal newDateExpense = 0;
DateTime dStart=DateTime.MinValue;
DateTime dCheck = DateTime.MinValue;
int flag = 0;
int count = dtResults.Rows.Count;
Decimal whole = 0;
for (int i = 0; i < count ; i++)
{
DataRow row = dtResults.Rows[i];
//foreach (DataRow row in dtResults.Rows)
//{
DateTime dtST = DateTime.Parse(row["StartTime"].ToString());
DateTime dtET = DateTime.Parse(row["EndTime"].ToString());
if (flag == 0)
{
dStart = dtST;
}
else
{
dCheck = dtST;
}
int total = 0;
string sAde = row["IsAllDayEvent"].ToString();
object[] EvtData = new object[13];
EvtData[0] = (int)row["id"];
EvtData[1] = row["Subject"].ToString();
EvtData[2] = dtST.ToString("MM/dd/yyyy HH:mm");
EvtData[3] = dtET.ToString("MM/dd/yyyy HH:mm");
EvtData[4] = Convert.ToInt16(sAde);
EvtData[5] = 0;
EvtData[6] = 0;
EvtData[7] = row["Color"].ToString();
EvtData[8] = 1;
// EvtData[9] = row["Location"].ToString();
EvtData[10] = string.Empty;
EvtData[11] = row["Amount"].ToString();
evtList.Add(EvtData);
// evtList.AsReadOnly();
if (i != count - 1)
{
DataRow rowNext = dtResults.Rows[i + 1];
if (row["StartTime"].ToString() == rowNext["StartTime"].ToString())
{
Decimal granT, granT2;
granT = Convert.ToDecimal(row["Amount"]);
granT2 = Convert.ToDecimal(rowNext["Amount"]);
if (whole == 0)
{
whole += granT + granT2;
}
else
{
whole += granT2;
}
}
else
{
Decimal granTnew = Convert.ToDecimal(row["Amount"]);
if (whole != 0)
{
EvtData = objectFucntions(row, dtST, dtET, sAde, (whole));
}
else
{
EvtData = objectFucntions(row, dtST, dtET, sAde, (granTnew));
}
evtList.Add(EvtData);
whole = 0;
}
}
else
{
Decimal granTnew=Convert.ToDecimal(row["Amount"]);
whole += granTnew;
EvtData = objectFucntions(row, dtST, dtET, sAde, whole);
evtList.Add(EvtData);
whole = 0;
}
////if (EvtData[11] == null) { EvtData[11] = 0; }
//if (dCheck == dStart)
//{
// totalExpense = Convert.ToDecimal(EvtData[11]) + Convert.ToDecimal(newtotalExpense);
// newtotalExpense = totalExpense;
// newDateExpense = 0;
//}
//else
//{
// newDateExpense = 0;
// if (flag > 0)
// {
// object[] EvtD = new object[4];
// EvtD[0] = EvtData[2];
// EvtD[1] = EvtData[3];
// EvtD[2] = newtotalExpense;
// evtList.Add(EvtD);
// newtotalExpense = 0;
// }
// newDateExpense = Convert.ToDecimal(EvtData[11]) + Convert.ToDecimal(newDateExpense);
// newtotalExpense = newDateExpense;
//}
dCheck = dStart;
flag += 1;
}
ret.Add("events", evtList);
ret.Add("issort", true);
ret.Add("start", dtSd.ToString("MM/dd/yyyy HH:mm"));
ret.Add("end", dtEd.ToString("MM/dd/yyyy HH:mm"));
ret.Add("error", null);
}
catch (Exception ex)
{
ret.Add("error", "list calendar by range failed: " + ex.Message);
//ret["error"] = "list calendar by range failed: " + ex.Message;
}
finally
{
if (oSqlCon.State == ConnectionState.Open)
oSqlCon.Close();
}
return ret;
}
一个功能:
public static Object [] objectFucntions(DataRow row,DateTime dtST,DateTime dtET,String sAde,Decimal total) {
object[] EvtData = new object[13];
EvtData[0] = (int)row["id"];
EvtData[1] = total;
EvtData[2] = dtST.ToString("MM/dd/yyyy HH:mm");
EvtData[3] = dtET.ToString("MM/dd/yyyy HH:mm");
EvtData[4] = Convert.ToInt16(sAde);
EvtData[5] = 0;
EvtData[6] = 0;
EvtData[7] = 3;
EvtData[8] = 1;
// EvtData[9] = row["Location"].ToString();
EvtData[10] = string.Empty;
EvtData[11] = row["Amount"].ToString();
return EvtData;
}
PS:这与我的数据库有关。