public static bool UpdateStatisticsData(List <HouseholdABookBase.HouseholdABook> householdABookList, DateTime start, DateTime end, int userId) { using (NpgSqlDBManager dBManager = new NpgSqlDBManager()) { try { if (householdABookList.Count <= 0) { return(false); } int id = householdABookList[0].idStr == AppConst.INCOME ? AppConst.INCOME_VALUE : AppConst.SPENDING_VALUE; Dictionary <string, int> moneyParam = StatisticsType.GetMoneysParam(householdABookList, userId); if (moneyParam == null && moneyParam.Count < 0) { return(false); } dBManager.Open(); dBManager.BeginTran(); foreach (var moneyData in moneyParam) { if (moneyData.Value > 0) { string sql = "UPDATE public.\"StatisticsData\" " + "SET \"createDate\" = '" + DateTime.Now.ToString() + "', " + "\"money\" = " + moneyData.Value + " where \"data_id\" = " + id + " and \"Classification\" = '" + moneyData.Key + "'" + " and \"StartDate\" = '" + start + "' and \"EndDate\" = '" + end + "'" + " and \"userId\" = " + userId; dBManager.ExecuteNonQuery(sql); } } dBManager.CommitTran(); } catch (Exception e) { dBManager.RollBack(); dBManager.Close(); string s = e.Message; OriginMBox.MBoxErrorOK(AppConst.STATISTICS_MESSAGE2); return(false); } } return(true); }
public static bool InsertStatisticsData(List <HouseholdABookBase.HouseholdABook> householdABookList, DateTime start, DateTime end, int userId) { using (NpgSqlDBManager dBManager = new NpgSqlDBManager()) { try { if (householdABookList.Count <= 0) { return(false); } int id = householdABookList[0].idStr == AppConst.INCOME ? AppConst.INCOME_VALUE : AppConst.SPENDING_VALUE; Dictionary <string, int> moneyParam = StatisticsType.GetMoneysParam(householdABookList, userId); if (moneyParam == null && moneyParam.Count < 0) { return(false); } dBManager.Open(); dBManager.BeginTran(); foreach (var moneyData in moneyParam) { if (moneyData.Value > 0) { string sql = "INSERT INTO public.\"StatisticsData\" " + "VALUES(" + id + ", " + "'" + DateTime.Now + "', " + "'" + moneyData.Key + "', " + moneyData.Value + ", '" + start + "', '" + end + "', " + userId + ")"; dBManager.ExecuteNonQuery(sql); } } dBManager.CommitTran(); } catch (Exception e) { dBManager.RollBack(); dBManager.Close(); string s = e.Message; OriginMBox.MBoxErrorOK(AppConst.STATISTICS_MESSAGE2); return(false); } } return(true); }