Browse Source

Вот как то так, и никак иначе

Лешка 4 months ago
parent
commit
a8af9e247a
3 changed files with 7 additions and 149 deletions
  1. 1 0
      BlazorApp-empty1/Connect.cs
  2. 0 97
      BlazorApp-empty1/GetListInfo.cs
  3. 6 52
      BlazorApp-empty1/page/MainPage.razor

+ 1 - 0
BlazorApp-empty1/Connect.cs

@@ -0,0 +1 @@
+

+ 0 - 97
BlazorApp-empty1/GetListInfo.cs

@@ -1,97 +0,0 @@
-/*
-using Microsoft.Data.SqlClient;
-using System.Data;
-
-namespace WebApplication1
-{
-    public class GetListInfo
-    {
-        public static List<string> GetRegion()
-        {
-            Connection.SqlConnection.Open();
-            SqlCommand sqlCommand = new SqlCommand("select NameRegion from Region", Connection.SqlConnection);
-
-            List<string> list = new List<string>();
-            SqlDataReader reader = sqlCommand.ExecuteReader();
-            while (reader.Read())
-            {
-                list.Add(reader.GetString(0));
-            }
-            Connection.SqlConnection.Close();
-            reader.Close();
-            return list;
-        }
-        public static List<string> GetReciplentMessage()
-        {
-            Connection.SqlConnection.Open();
-            SqlCommand sqlCommand = new SqlCommand("select RecipientMessage from RecipientMessage", Connection.SqlConnection);
-            List<string> list = new List<string>();
-            SqlDataReader reader = sqlCommand.ExecuteReader();
-            while (reader.Read())
-            {
-                list.Add(reader.GetString(0));
-            }
-            Connection.SqlConnection.Close();
-            reader.Close();
-            return list;
-
-        }
-       
-        public static bool UserUpdate(string email, string Area, string city, string street, string housenymber, string HouseBody, string appartament, string surname, string name, string patronomic, string phone, string socialstatus)
-        {
-            Connection.SqlConnection.Open();
-            SqlCommand cmd = new SqlCommand($"insert into [User] values ('{email}','{Area}','{city}','{street}','{housenymber}','{HouseBody}','{appartament}','{surname}','{name}','{patronomic}','{phone}','{socialstatus}')", Connection.SqlConnection);
-            if (cmd.ExecuteNonQuery() > 0)
-            {
-                Connection.SqlConnection.Close();
-                return true;
-            }
-            else
-            {
-                Connection.SqlConnection.Close();
-                return false;
-            }
-
-        }
-        public static bool FileUpdate(byte[] file, string filetype)
-        {
-            if(file == null )
-            {
-                return true;
-            }
-           
-                Connection.SqlConnection.Open();
-                var cmd = new SqlCommand("INSERT INTO [File] ([File], FileType) VALUES (@file, @filetype)", Connection.SqlConnection);
-                
-                    cmd.Parameters.Add("@file", SqlDbType.VarBinary).Value = file;
-                    cmd.Parameters.Add("@filetype", SqlDbType.VarChar).Value = filetype;
-
-                    if (cmd.ExecuteNonQuery() > 0)
-                    {
-                        Connection.SqlConnection.Close() ;
-                        return true;
-                    }
-                    else
-                    {
-                        Connection.SqlConnection.Close();
-                        return false;
-                    }
-                
-            
-        }
-        public static bool AppealUpdate(string region, string index, string RecipientMessage, string text)
-        {
-            Connection.SqlConnection.Open();
-            SqlCommand cmd = new SqlCommand($"insert into [Appeal] values ((select Region.idRegion from Region where NameRegion = '{region}'),'{index}',(select IdRecipientMessage from RecipientMessage where RecipientMessage = '{RecipientMessage}' ),'{text}',(SELECT MAX([File].IdFile) FROM [File]),(SELECT MAX(id_user) from [User]))",Connection.SqlConnection);
-            cmd.ExecuteScalar();
-                Connection.SqlConnection.Close();
-                return true;
-            
-            
-                
-            
-        }
-
-    }
-}
-*/

+ 6 - 52
BlazorApp-empty1/page/MainPage.razor

@@ -549,55 +549,8 @@
                                             <div class="col-sm-12">
                                                 <div class="form-upload-file ">
 
-                                                    <InputFile id="photo" OnChange="HandleFileUpload" />
-                                                    @code {
-                                                        private async Task HandleFileUpload(InputFileChangeEventArgs e)
-                                                        {
-                                                            var file = e.File;
-                                                            if (file != null)
-                                                            {
-                                                                using (var memoryStream = new MemoryStream())
-                                                                {
-                                                                    await file.OpenReadStream().CopyToAsync(memoryStream);
-                                                                    byte[] fileBytes = memoryStream.ToArray();
-
-                                                                    // Отправка файла на сервер
-                                                                    await SendFileToServer(fileBytes, file.Name);
-                                                                }
-                                                            }
-
-
-
-
-
-
-                                                        }
-                                                        private async Task SendFileToServer(byte[] fileBytes, string fileName)
-                                                        {
-                                                        // Замените URL на адрес вашего API
-                                                            var url = "https://localhost:7152/WeatherForecast/FileUpdate";
-
-                                                            using (var formData = new MultipartFormDataContent())
-                                                            {
-                                                                formData.Add(new ByteArrayContent(fileBytes), "file", fileName);
-
-                                                                using (var client = new HttpClient())
-                                                                {
-                                                                    var response = await client.PostAsync(url, formData);
-
-                                                                    if (response.IsSuccessStatusCode)
-                                                                    {
-                                                                    // Обработка успешного ответа
-                                                                    }
-                                                                    else
-                                                                    {
-                                                                    // Обработка ошибки при загрузке файла
-                                                                    }
-                                                                    
-                                                                }
-                                                            }
-                                                        }
-                                                    }
+                                                    <InputFile id="photo"  />
+                                                   
                                                     <div id="files" class="files"></div>
 
                                                     <p class="light-text">
@@ -636,10 +589,10 @@
 
                                                 @code
                                                 {
-                                                    bool checboxx;
+                                                    bool checboxx = false;
                                                     StreamContent fileStream;
-                                                    private string emailuser;
-                                                    private string emailrepid;
+                                                    private string emailuser = "";
+                                                    private string emailrepid = "";
                                                     string region = "Нижегородская область";
                                                     byte[] file11;
                                                     string index;
@@ -661,6 +614,7 @@
                                                     {
 
                                                         Regex regex = new Regex(@"^[_a-z0-9-\+-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$");
+                                                        
                                                         if (regex.IsMatch(emailuser) == false)
                                                         {
                                                             Messagabutton = "Обращение не отправлено,проверте правильность заполенения почты";