using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ModrnPOS { public partial class MainForm : Telerik.WinControls.UI.RadTabbedForm { public MainForm(string type, Int64 Number) { InitializeComponent(); this.AllowAero = false; NUMNER = Number; TYPE = type; _Load(TYPE, NUMNER); } public MainForm() { InitializeComponent(); this.AllowAero = false; } public Int64 NUMNER { get; set; } public string TYPE { get; set; } Pations pation; public async void _Load(string typ, Int64 num) { var result = Task.Run(() => { Pations p = Loadpations(typ, num); return p; }); Pations PationsResult = await result; textBox1.Text=PationsResult.LastName; } private Pations Loadpations(string typ, Int64 num) { pation = new Pations(); SqlConnection sqlConnection = new SqlConnection(connStr); if (typ == "Code") { using (sqlConnection) { sqlConnection.Open(); using (SqlCommand cmd = new SqlCommand("select [patient id],first_name,middle_name,last_name,birthDay,note,address,phone,sex from patient where [patient id]=@ID", sqlConnection)) { cmd.Parameters.AddWithValue("@ID", num); using (var db = cmd.ExecuteReader()) { while (db.Read()) { pation.Id = db.GetInt32(0); pation.FirstName = db.GetString(1); pation.SecondName = db.GetString(2); pation.LastName = db.GetString(3); pation.birthDay = db.GetDateTime(4); pation.Note = db.GetString(5); pation.Address = db.GetString(6); pation.phone = db.GetString(7); pation.Gender = db.GetString(8); } db.Close(); } } } } if (typ == "Phone") { if (typ == "Phone") { using (sqlConnection) { sqlConnection.Open(); using (SqlCommand cmd = new SqlCommand("select [patient id],first_name,middle_name,last_name,birthDay,note,address,phone,sex from patient where phone=@PHONE", sqlConnection)) { cmd.Parameters.AddWithValue("@PHONE", num); using (var db = cmd.ExecuteReader()) { while (db.Read()) { pation.Id = db.GetInt32(0); pation.FirstName = db.GetString(1); pation.SecondName = db.GetString(2); pation.LastName = db.GetString(3); pation.birthDay = db.GetDateTime(4); pation.Note = db.GetString(5); pation.Address = db.GetString(6); pation.phone = db.GetString(7); pation.Gender = db.GetString(8); } db.Close(); } } } } } return pation; } } public class Pations { public int Id { get; set; } public string phone { get; set; } public string FirstName { get; set; } public string SecondName { get; set; } public string LastName { get; set; } public string FullName => $"{FirstName} {SecondName} {LastName}"; public string Phone { get; set; } public DateTime birthDay { get; set; } public string Address { get; set; } public string Gender { get; set; } public string Note { get; set; } } }