예제 #1
0
        public Result(string hostid, XMLBilling billing)
        {
            feePercent = (decimal)billing.FeePercent;
            text       = "*Биллинг схема хоста № " + hostid + " *";
            text      += (billing.Default) ? " `(используется дефолтная схема)`" : "";

            attachments = new List <Attachments>();
        }
예제 #2
0
        public static async Task <string> ReadDataAsync(string text, XMLBilling billing)
        {
            int hostid;

            if (!int.TryParse(text, out hostid))
            {
                return("Идентификатор хоста должен быть числом");
            }

            string connectionString = @"Data Source=DESKTOP-54SB01U;Initial Catalog=Radario;Integrated Security=True";

            string strBilling        = "";
            string selBilFromCompany = "SELECT FeePercent, BillingSchemeId FROM [Company] WHERE id=@hostid";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();

                SqlCommand   command     = new SqlCommand(selBilFromCompany, connection);
                SqlParameter hostidParam = new SqlParameter("@hostid", hostid);
                command.Parameters.Add(hostidParam);

                SqlDataReader reader = await command.ExecuteReaderAsync();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        billing.FeePercent = reader.GetValue(0);
                        if (!reader.IsDBNull(reader.GetOrdinal("BillingSchemeId")))
                        {
                            billing.BillingSchemeId = reader.GetValue(1);;
                        }
                    }

                    reader.Close();
                }
                else
                {
                    return("Такого хоста нет в базе, или что-то пошло не так.");
                }

                if (billing.BillingSchemeId == null)
                {
                    strBilling      = "SELECT data FROM [BillingScheme] WHERE id=1";
                    billing.Default = true;
                }
                else
                {
                    strBilling      = "SELECT data FROM [BillingScheme] WHERE GUID='" + billing.BillingSchemeId + "'";
                    billing.Default = false;
                }

                command = new SqlCommand(strBilling, connection);


                reader = await command.ExecuteReaderAsync();

                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        billing.data = reader.GetValue(0);
                    }
                }

                reader.Close();
            }

            return(billing.data.ToString());
        }