public DataTable GetData(int period, string report_guid, string tomcat, string login, string passw, DateTime from, DateTime to) { DataTable tableRes = GetTable(); //1 неделя var res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "GuestNum" }, from.AddDays(-34), to.AddDays(-28)); var table = new List <Dictionary <string, object> >(); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator).ToString()); } } foreach (var a in res.data) { try { var t = new Dictionary <string, object>(); t.Add("Week", "1"); t.Add("Department", a["Department"]); t.Add("Guests", decimal.Parse(a["GuestNum"])); t.Add("GuestsAnalysis", 0); table.Add(t); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //2 неделя res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "GuestNum" }, from.AddDays(-27), to.AddDays(-21)); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", ","); } } foreach (var a in res.data) { try { var t = new Dictionary <string, object>(); t.Add("Week", "2"); t.Add("Department", a["Department"]); t.Add("Guests", decimal.Parse(a["GuestNum"])); var GuestsLastWeek = table.FirstOrDefault(b => b["Week"].ToString() == "1" && b["Department"].ToString() == a["Department"])["Guests"]; t.Add("GuestsAnalysis", ((decimal)GuestsLastWeek > 0 ? (decimal.Parse(a["GuestNum"]) * 100 / (decimal)GuestsLastWeek - 100) : 0)); table.Add(t); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //3 неделя res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "GuestNum" }, from.AddDays(-20), to.AddDays(-14)); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", ","); } } foreach (var a in res.data) { try { var t = new Dictionary <string, object>(); t.Add("Week", "3"); t.Add("Department", a["Department"]); t.Add("Guests", decimal.Parse(a["GuestNum"])); var GuestsLastWeek = table.FirstOrDefault(b => b["Week"].ToString() == "2" && b["Department"].ToString() == a["Department"])["Guests"]; t.Add("GuestsAnalysis", ((decimal)GuestsLastWeek > 0 ? (decimal.Parse(a["GuestNum"]) * 100 / (decimal)GuestsLastWeek - 100) : 0)); table.Add(t); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //4 неделя res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "GuestNum" }, from.AddDays(-13), to.AddDays(-7)); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", ","); } } foreach (var a in res.data) { try { var t = new Dictionary <string, object>(); t.Add("Week", "4"); t.Add("Department", a["Department"]); t.Add("Guests", decimal.Parse(a["GuestNum"])); var GuestsLastWeek = table.FirstOrDefault(b => b["Week"].ToString() == "3" && b["Department"].ToString() == a["Department"])["Guests"]; t.Add("GuestsAnalysis", ((decimal)GuestsLastWeek > 0 ? (decimal.Parse(a["GuestNum"]) * 100 / (decimal)GuestsLastWeek - 100) : 0)); table.Add(t); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //5 неделя res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "GuestNum" }, from.AddDays(-6), to); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", ","); } } foreach (var a in res.data) { try { var t = new Dictionary <string, object>(); t.Add("Week", "5"); t.Add("Department", a["Department"]); t.Add("Guests", decimal.Parse(a["GuestNum"])); var GuestsLastWeek = table.FirstOrDefault(b => b["Week"].ToString() == "4" && b["Department"].ToString() == a["Department"])["Guests"]; t.Add("GuestsAnalysis", ((decimal)GuestsLastWeek > 0 ? (decimal.Parse(a["GuestNum"]) * 100 / (decimal)GuestsLastWeek - 100) : 0)); table.Add(t); } catch (Exception ex) { Console.WriteLine(ex.Message); } } try { foreach (var line in table) { var data = line.Select(a => a.Value).Select(a => (object)a).ToArray(); tableRes.Rows.Add(data); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(tableRes); }
public DataTable GetData(int period, string report_guid, string tomcat, string login, string passw, DateTime from, DateTime to) { DataTable tableRes = GetTable(); //текущая неделя var res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "GuestNum", "DishDiscountSumInt", "UniqOrderId" }, from.AddDays(-6), to); var table = new List <Dictionary <string, object> >(); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator).ToString()); } } if (res.data.Count == 0) { try { var t = table.FirstOrDefault(); if (t != null) { t.Add("Guests", 0); t.Add("Средний чек", 0); } } catch (Exception ex) { //Логгируем ошибку и идем дальше! Console.WriteLine(ex.Message); } } foreach (var a in res.data) { try { var t = new Dictionary <string, object>(); t.Add("Ресторан", a["Department"]); t.Add("Guests", decimal.Parse(a["GuestNum"])); t.Add("Средний чек", (decimal.Parse(a["DishDiscountSumInt"]) / decimal.Parse(a["UniqOrderId"]))); table.Add(t); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //текущие 4 недели res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "GuestNum", "DishDiscountSumInt", "UniqOrderId" }, from.AddDays(-27), to); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", ","); } } if (res.data.Count == 0) { try { var t = table.FirstOrDefault(); if (t != null) { t.Add("GuestsFourWeeks", 0); t.Add("Средний чек за 4 недели", 0); } } catch (Exception ex) { //Логгируем ошибку и идем дальше! Console.WriteLine(ex.Message); } } foreach (var a in res.data) { try { var t = table.FirstOrDefault(b => b["Ресторан"].ToString() == a["Department"]); if (t != null) { t.Add("GuestsFourWeeks", decimal.Parse(a["GuestNum"])); t.Add("Средний чек за 4 недели", (decimal.Parse(a["DishDiscountSumInt"]) / decimal.Parse(a["UniqOrderId"]))); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } //предыдущая неделя res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "GuestNum", "DishDiscountSumInt", "UniqOrderId" }, from.AddDays(-13), to.AddDays(-7)); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", ","); } } if (res.data.Count == 0) { try { var t = table.FirstOrDefault(); if (t != null) { t.Add("GuestsLastWeek", 0); t.Add("Средний чек к прошлой неделе", 0); t.Add("Отношение гостей. Одна неделя", 0); t.Add("Отношение чеков. Одна неделя", 0); } } catch (Exception ex) { //Логгируем ошибку и идем дальше! Console.WriteLine(ex.Message); } } foreach (var a in res.data) { try { var t = table.FirstOrDefault(b => b["Ресторан"].ToString() == a["Department"]); if (t != null) { t.Add("GuestsLastWeek", decimal.Parse(a["GuestNum"])); t.Add("Средний чек к прошлой неделе", (decimal.Parse(a["DishDiscountSumInt"]) / decimal.Parse(a["UniqOrderId"]))); t.Add("Отношение гостей. Одна неделя", (decimal)t["GuestsLastWeek"] > 0 ? ((decimal)t["Guests"] * 100 / (decimal)t["GuestsLastWeek"] - 100) : 0); t.Add("Отношение чеков. Одна неделя", (decimal)t["Средний чек к прошлой неделе"] > 0 ? ((decimal)t["Средний чек"] * 100 / (decimal)t["Средний чек к прошлой неделе"] - 100) : 0); } } catch (Exception ex) { //Логгируем ошибку и идем дальше! Console.WriteLine(ex.Message); } } //предыдущие 4 недели res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "GuestNum", "DishDiscountSumInt", "UniqOrderId" }, from.AddDays(-55), to.AddDays(-28)); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", ","); } } if (res.data.Count == 0) { try { var t = table.FirstOrDefault(); if (t != null) { t.Add("GuestsLastFourWeeks", 0); t.Add("Средний чек к прошлым 4 неделям", 0); t.Add("Отношение гостей. Четыре недели", 0); t.Add("Отношение чеков. Четыре недели", 0); } } catch (Exception ex) { //Логгируем ошибку и идем дальше! Console.WriteLine(ex.Message); } } foreach (var a in res.data) { try { var t = table.FirstOrDefault(b => b["Ресторан"].ToString() == a["Department"]); if (t != null) { t.Add("GuestsLastFourWeek", decimal.Parse(a["GuestNum"])); t.Add("Средний чек к прошлым 4 неделям", (decimal.Parse(a["DishDiscountSumInt"]) / decimal.Parse(a["UniqOrderId"]))); t.Add("Отношение гостей. Четыре недели", (decimal)t["GuestsLastFourWeek"] > 0 ? ((decimal)t["GuestsFourWeeks"] * 100 / (decimal)t["GuestsLastFourWeek"] - 100) : 0); t.Add("Отношение чеков. Четыре недели", (decimal)t["Средний чек к прошлым 4 неделям"] > 0 ? ((decimal)t["Средний чек за 4 недели"] * 100 / (decimal)t["Средний чек к прошлым 4 неделям"] - 100) : 0); } } catch (Exception ex) { //Логгируем ошибку и идем дальше! Console.WriteLine(ex.Message); } } try { foreach (var line in table) { var data = line.Select(a => a.Value).Select(a => (object)a).ToArray(); tableRes.Rows.Add(data); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(tableRes); }
public DataTable GetData(int period, string report_guid, string tomcat, string login, string passw, DateTime from, DateTime to) { DataTable tableRes = GetTable(); //1 неделя var res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "DishDiscountSumInt", "UniqOrderId" }, from.AddDays(-34), to.AddDays(-28)); var table = new List <Dictionary <string, object> >(); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator).ToString()); } } foreach (var a in res.data) { try { var t = new Dictionary <string, object>(); t.Add("Week", "1"); t.Add("List", a["Department"]); t.Add("AvgCheck", (decimal.Parse(a["DishDiscountSumInt"]) / decimal.Parse(a["UniqOrderId"]))); table.Add(t); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //2 неделя res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "DishDiscountSumInt", "UniqOrderId" }, from.AddDays(-27), to.AddDays(-21)); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", ","); } } foreach (var a in res.data) { try { var t = new Dictionary <string, object>(); t.Add("Week", "2"); t.Add("List", a["Department"]); t.Add("AvgCheck", (decimal.Parse(a["DishDiscountSumInt"]) / decimal.Parse(a["UniqOrderId"]))); table.Add(t); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //3 неделя res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "DishDiscountSumInt", "UniqOrderId" }, from.AddDays(-20), to.AddDays(-14)); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", ","); } } foreach (var a in res.data) { try { var t = new Dictionary <string, object>(); t.Add("Week", "3"); t.Add("List", a["Department"]); t.Add("AvgCheck", (decimal.Parse(a["DishDiscountSumInt"]) / decimal.Parse(a["UniqOrderId"]))); table.Add(t); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //4 неделя res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "DishDiscountSumInt", "UniqOrderId" }, from.AddDays(-13), to.AddDays(-7)); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", ","); } } foreach (var a in res.data) { try { var t = new Dictionary <string, object>(); t.Add("Week", "4"); t.Add("List", a["Department"]); t.Add("AvgCheck", (decimal.Parse(a["DishDiscountSumInt"]) / decimal.Parse(a["UniqOrderId"]))); table.Add(t); } catch (Exception ex) { Console.WriteLine(ex.Message); } } //5 неделя res = OrdersApi.Olap(tomcat, login, passw, new string[] { "Department" }, new string[] { "DishDiscountSumInt", "UniqOrderId" }, from.AddDays(-6), to); foreach (var line in res.data) { for (int i = 0; i < line.Count; ++i) { line[line.Keys.ToList()[i]] = line[line.Keys.ToList()[i]].Replace(".", ","); } } foreach (var a in res.data) { try { var t = new Dictionary <string, object>(); t.Add("Week", "5"); t.Add("List", a["Department"]); t.Add("AvgCheck", (decimal.Parse(a["DishDiscountSumInt"]) / decimal.Parse(a["UniqOrderId"]))); table.Add(t); } catch (Exception ex) { Console.WriteLine(ex.Message); } } try { foreach (var line in table) { var data = line.Select(a => a.Value).Select(a => (object)a).ToArray(); tableRes.Rows.Add(data); } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(tableRes); }