public NewOrder() { InitializeComponent(); DataContext = this; newClient = new Client(); newClient.AssignClientCode(); MyOrder = new OrderForm() { Client = newClient }; MyOrder.AssignOrderId(); MyOrder.OrderDate = DateTime.Now; }
public static async Task<Client> RetrieveByClientCode(string clientCode) { Client client = new Client(); string sqlCmdString = "Select * From dbo.clients Where client_code = @client_code"; Database myDb = new Database(); SqlCommand sqlCmd = new SqlCommand(sqlCmdString, myDb.Connection); SqlDataAdapter sqlAdapt = new SqlDataAdapter(sqlCmd); DataTable table = new DataTable(); await Task.Run(() => { try { myDb.OpenConnection(); sqlCmd.Parameters.Add(new SqlParameter("@client_code", clientCode)); sqlAdapt.Fill(table); foreach (DataRow row in table.Rows) { client = new Client() { ClientCode = (String)row["client_code"], ClientName = (String)row["client_name"], TinNo = (String)row["tin_no"], MainAddress = (String)row["main_address"], PrimaryContactName = (String)row["primary_contact_name"], PrimaryContact = (String)row["primary_contact"], PrimaryEmail = (String)row["primary_email"], IsPersist = true }; } } finally { sqlAdapt.Dispose(); table.Dispose(); myDb.CloseConnection(); } }); return client; }