Exemplo n.º 1
0
        private static void AnnualReport(NetworkStream stream, byte[] inputData, string clientIp)
        {
            var subsidiary   = NetManager.ToString(inputData);
            var annualReport = new QuaterDataSerialize();

            if (!Directory.Exists(Folder + "/" + subsidiary))
            {
                var message = $"Данных для \"{subsidiary}\" не обнаружено.";
                NetManager.Send(stream, NetManager.ToBytes(message));
                Console.WriteLine("{0}: {1}", clientIp, message);
            }
            else
            {
                var quaters = string.Empty;

                foreach (var item in new DirectoryInfo(Folder + "/" + subsidiary).GetFiles())
                {
                    quaters += ", " + Path.GetFileNameWithoutExtension(item.Name);

                    var quater = new QuaterDataSerialize();
                    var vs     = File.ReadAllBytes(Folder + "/" + subsidiary + "/" + item.Name);

                    annualReport.AddData(quater.Deserialize(vs));
                }

                quaters = quaters.Substring(1, quaters.Length - 1);

                var message = $"Отчет построен по данным за{quaters}.";
                NetManager.Send(stream, NetManager.ToBytes(message));
                Console.WriteLine("{0}: {1}", clientIp, message);
            }

            NetManager.Send(stream, annualReport.Serialize());
        }
Exemplo n.º 2
0
        private static void QuaterDataSave(NetworkStream stream, byte[] inputData, string clientIp)
        {
            try
            {
                QuaterDataSerialize quaterData = new QuaterDataSerialize();
                quaterData = quaterData.Deserialize(inputData);

                if (!Directory.Exists(Folder + "/" + quaterData.Subsidiary))
                {
                    Directory.CreateDirectory(Folder + "/" + quaterData.Subsidiary);
                }

                File.WriteAllBytes(Folder + "/" + quaterData.Subsidiary + "/" + quaterData.Quater + ".dat", inputData);
                var message = $"Получены данные \"{quaterData.Subsidiary}\" за {quaterData.Quater} квартал.";
                NetManager.Send(stream, NetManager.ToBytes(message));
                Console.WriteLine("{0}: {1}", clientIp, message);
            }
            catch (Exception ex)
            {
                ExceptManager.Write(ex);
            }
        }
        internal void AddData(QuaterDataSerialize quater)
        {
            if (Tables == null)
            {
                Tables     = quater.Tables;
                Titles     = quater.Titles;
                Subsidiary = quater.Subsidiary;
            }
            else
            {
                for (var i = 0; i < Tables[0].Rows.Count; i++)
                {
                    for (var j = 1; j < 3; j++)
                    {
                        Tables[0].Rows[i][j] = Convert.ToDouble(Tables[0].Rows[i][j]) + Convert.ToDouble(quater.Tables[0].Rows[i][j]);
                    }
                }

                for (var j = 0; j < 2; j++)
                {
                    Tables[1].Rows[0][j] = Convert.ToDouble(Tables[1].Rows[0][j]) + Convert.ToDouble(quater.Tables[1].Rows[0][j]);
                }

                for (var i = 0; i < Tables[2].Rows.Count; i++)
                {
                    for (var j = 1; j < 3; j++)
                    {
                        Tables[2].Rows[i][j] = Convert.ToDouble(Tables[2].Rows[i][j]) + Convert.ToDouble(quater.Tables[2].Rows[i][j]);
                    }
                }

                for (var i = 0; i < Tables[3].Rows.Count; i++)
                {
                    for (var j = 1; j < 4; j++)
                    {
                        Tables[3].Rows[i][j] = Convert.ToDouble(Tables[3].Rows[i][j]) + Convert.ToDouble(quater.Tables[3].Rows[i][j]);
                    }
                }

                for (var j = 2; j < 4; j++)
                {
                    Tables[4].Rows[0][j] = Convert.ToDouble(Tables[4].Rows[0][j]) + Convert.ToDouble(quater.Tables[4].Rows[0][j]);
                }

                Tables[5].Rows[0][0] = Convert.ToDouble(Tables[5].Rows[0][0]) + Convert.ToDouble(quater.Tables[5].Rows[0][0]);

                Tables[6].Rows[0][0] = Convert.ToDouble(Tables[6].Rows[0][0]) + Convert.ToDouble(quater.Tables[6].Rows[0][0]);

                for (var i = 0; i < Tables[7].Rows.Count; i++)
                {
                    for (var j = 1; j < 3; j++)
                    {
                        Tables[7].Rows[i][j] = Convert.ToDouble(Tables[7].Rows[i][j]) + Convert.ToDouble(quater.Tables[7].Rows[i][j]);
                    }
                }

                for (var j = 0; j < 2; j++)
                {
                    Tables[8].Rows[0][j] = Convert.ToDouble(Tables[8].Rows[0][j]) + Convert.ToDouble(quater.Tables[8].Rows[0][j]);
                }

                for (var j = 0; j < 2; j++)
                {
                    Tables[9].Rows[0][j] = Convert.ToDouble(Tables[9].Rows[0][j]) + Convert.ToDouble(quater.Tables[9].Rows[0][j]);
                }
            }
        }