public List<BillSecForClientsInfo> Call_GetBillSecForClients(DateTime start, string clients) { List<BillSecForClientsInfo> result = new List<BillSecForClientsInfo>(); using (MySqlConnection objConn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["CallTrackingDBContext"].ConnectionString)) { objConn.Open(); MySqlCommand objComGetBillSecForClients = new MySqlCommand(); objComGetBillSecForClients.Connection = objConn; objComGetBillSecForClients.CommandType = CommandType.StoredProcedure; objComGetBillSecForClients.CommandText = "GetBillSecForClients"; objComGetBillSecForClients.Parameters.Add("@curentdate", MySqlDbType.DateTime).Value = start.Date; objComGetBillSecForClients.Parameters.Add("@clients", MySqlDbType.VarChar).Value = clients; MySqlDataReader reader = objComGetBillSecForClients.ExecuteReader(); if (reader.HasRows) { int CurentClientId = 0; DateTime CurentDate = new DateTime(); int PrevClientId = 0; DateTime PrevDate = new DateTime(); BillSecForClientsInfo Curent_BillSecForClientsInfo = new BillSecForClientsInfo(); bool isfirstelement = true; while (reader.Read()) { CurentDate = reader.GetDateTime(0); CurentClientId = reader.GetInt32(2); if ((CurentDate == PrevDate) && (CurentClientId == PrevClientId))// заполняем список стоимости по кодам, если тот же самый клиент и та же дата { Curent_BillSecForClientsInfo.codes_billsec.Add(new billsec_count_for_code() { code = reader.GetInt32(3), billsec = reader.GetInt32(1) }); } else//если новый клиент и новая дата { if (!isfirstelement)//если это не первый создаваемый обьект BillSecForClientsInfo { result.Add(Curent_BillSecForClientsInfo); } Curent_BillSecForClientsInfo = new BillSecForClientsInfo() { date = reader.GetDateTime(0), ClientId = reader.GetInt32(2) }; Curent_BillSecForClientsInfo.codes_billsec = new List<billsec_count_for_code>(); Curent_BillSecForClientsInfo.codes_billsec.Add(new billsec_count_for_code() { code = reader.GetInt32(3), billsec = reader.GetInt32(1) }); PrevDate = CurentDate; PrevClientId = CurentClientId; isfirstelement = false; } } result.Add(Curent_BillSecForClientsInfo);//добавляем в список последний созданный обьект } objConn.Close(); } return result; }
public List <BillSecForClientsInfo> Call_GetBillSecForClients(DateTime start, string clients) { List <BillSecForClientsInfo> result = new List <BillSecForClientsInfo>(); using (MySqlConnection objConn = new MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["CallTrackingDBContext"].ConnectionString)) { objConn.Open(); MySqlCommand objComGetBillSecForClients = new MySqlCommand(); objComGetBillSecForClients.Connection = objConn; objComGetBillSecForClients.CommandType = CommandType.StoredProcedure; objComGetBillSecForClients.CommandText = "GetBillSecForClients"; objComGetBillSecForClients.Parameters.Add("@curentdate", MySqlDbType.DateTime).Value = start.Date; objComGetBillSecForClients.Parameters.Add("@clients", MySqlDbType.VarChar).Value = clients; MySqlDataReader reader = objComGetBillSecForClients.ExecuteReader(); if (reader.HasRows) { int CurentClientId = 0; DateTime CurentDate = new DateTime(); int PrevClientId = 0; DateTime PrevDate = new DateTime(); BillSecForClientsInfo Curent_BillSecForClientsInfo = new BillSecForClientsInfo(); bool isfirstelement = true; while (reader.Read()) { CurentDate = reader.GetDateTime(0); CurentClientId = reader.GetInt32(2); if ((CurentDate == PrevDate) && (CurentClientId == PrevClientId))// заполняем список стоимости по кодам, если тот же самый клиент и та же дата { Curent_BillSecForClientsInfo.codes_billsec.Add(new billsec_count_for_code() { code = reader.GetInt32(3), billsec = reader.GetInt32(1) }); } else//если новый клиент и новая дата { if (!isfirstelement)//если это не первый создаваемый обьект BillSecForClientsInfo { result.Add(Curent_BillSecForClientsInfo); } Curent_BillSecForClientsInfo = new BillSecForClientsInfo() { date = reader.GetDateTime(0), ClientId = reader.GetInt32(2) }; Curent_BillSecForClientsInfo.codes_billsec = new List <billsec_count_for_code>(); Curent_BillSecForClientsInfo.codes_billsec.Add(new billsec_count_for_code() { code = reader.GetInt32(3), billsec = reader.GetInt32(1) }); PrevDate = CurentDate; PrevClientId = CurentClientId; isfirstelement = false; } } result.Add(Curent_BillSecForClientsInfo);//добавляем в список последний созданный обьект } objConn.Close(); } return(result); }