how to update a datagridview on a Parent form from a Child Form C# - sql-server

I'm quite a new C# programmer,it has been a month that ive started using C#, so far so good i might say, but im curently dealing with a simple situation , but i still dont get it to work , there is the scenario :
I've 2 forms a Parent and a Child , the parent contains a Xtragrid control and a button which opens the second form and load the textBoxes in the second form with values , the second has a button to update the values in case of any changes . but i still dont get it to work , I've the following error :
MUST DECLARE A SCALAR VARIABLE at #ID
I understood the cause of the probleme but i just cant fix it ,ive have done some researches to sort myself out but i still didnt manage to make it work
the last line
da.updatecommand.parameters.addwithvalues("ID#",ds.tables["tblLesseeYW"].Rows[LesseeYW.Position][0];
I have done it but it is not working( LesseeYW which is my binding source object but it doesnt exit in the current context nor the dataset which is understandable
: there is the code need help pleaese
// This the class ive created to retrieve all Columns from the SQl server data base
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace YoungWoman
{
public static class GetRowData
{
public static int LesseeId;
public static byte LesseePic;
public static string LesseeName;
public static string LesseeLastName;
public static string PassportNo;
public static string IDNo;
public static DateTime BirthDate;
public static string Gender;
public static string Country;
public static string City;
public static string Province;
public static string LesseePostalCode;
public static string MobileNo;
public static string HomePhoneNo;
public static string TutorName;
public static string TutorLastName;
public static string AddressTutor;
public static string AddressLessee;
public static string TutorPhoneNo;
public static string TutorEmail;
}
}
// the parent form
namespace YoungWoman
{
public partial class Lessee2 : UserControl
{
DataSet ds = new DataSet();
DataView dv ;
SqlDataAdapter daLessee = new SqlDataAdapter();
SqlDataAdapter daReservation = new SqlDataAdapter();
BindingSource LesseeYW = new BindingSource();
BindingSource ReservationCenterYW = new BindingSource();
SqlConnection conne = SqlCoonectionSEtup.GetConnection;
// the button that opens the Child Form
private void EditLesseeFrm_Click(object sender, EventArgs e)
{
Lesseefrm Lessee = new Lesseefrm(Utils.Formtype.edit, 1);
Lessee.LesseeEventHandler += new EventHandler(RefreshLesseeGrid);
GetRowData.LesseeId = Convert.ToInt32(gridView1.GetRowCellValue (gridView1.FocusedRowHandle, "LesseeId"));
GetRowData.LesseeName = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LesseeName"));
GetRowData.LesseeLastName = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"LesseeLastName"));
GetRowData.PassportNo = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle,"PassportNo"));
GetRowData.Gender = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Gender"));
GetRowData.Province = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Province"));
GetRowData.BirthDate = Convert.ToDateTime(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "BirthDate"));
GetRowData.City = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "City"));
GetRowData.Country = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Country"));
GetRowData.MobileNo = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MobileNo"));
GetRowData.HomePhoneNo = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "HomePhoneNo"));
GetRowData.IDNo = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "IDNo"));
GetRowData.AddressLessee = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "AddressLessee"));
GetRowData.AddressTutor = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "AddressTutor"));
GetRowData.LesseePostalCode = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LesseePostalCode"));
GetRowData.TutorName = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TutorName"));
GetRowData.TutorLastName = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TutorLastName"));
GetRowData.TutorPhoneNo = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TutorPhoneNo"));
GetRowData.TutorEmail = Convert.ToString(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TutorEmail"));
Lessee.ShowDialog();
}
( // Child LOad_form if form type == Edit )
if (formtype == Formtype.edit && Lesseeid > 0)
{
LesseeIdtextEdit.Enabled = false;
ClearBtnlayoutControlItem26.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
SaveBtn.Text = "&Edit";
SaveBtn.Image = Resources.brush_16;
this.Text = string.Format(" Edit Lessee Information - YW Residence ");
LesseeIdtextEdit.Text = Convert.ToInt32(GetRowData.LesseeId).ToString();
txtName.Text = GetRowData.LesseeName;
txtLAstname.Text = GetRowData.LesseeLastName;
txtPassport.Text = GetRowData.PassportNo;
txtID.Text = GetRowData.IDNo;
GendercomboBoxEdit.SelectedItem = GetRowData.Gender;
DobdateEdit.DateTime = GetRowData.BirthDate;
CountrycomboBoxEdit.SelectedItem = GetRowData.Country;
txtProvince.Text = GetRowData.Province;
txtCity.Text = GetRowData.City;
txtPostalCode.Text = GetRowData.LesseePostalCode;
LesseememoEdit1.Text = GetRowData.AddressLessee;
txtMobile.Text = GetRowData.MobileNo;
txtHomePhone.Text = GetRowData.HomePhoneNo;
txtTutorName.Text = GetRowData.TutorName;
txttutorLastname.Text = GetRowData.TutorLastName;
tutorAddresstxt.Text = GetRowData.AddressTutor;
txtTutorMobile.Text = GetRowData.TutorPhoneNo;
txtEmail.Text = GetRowData.TutorEmail;
}
public event System.EventHandler LesseeEventHandler;
private void SaveBtn_Click(object sender, EventArgs e)
if (formtype == Formtype.edit && Lesseeid > 0)
{
MemoryStream ms = new MemoryStream();
PicBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] Pic_arr = new byte[ms.Length];
ms.Position = 0;
ms.Read(Pic_arr, 0, Pic_arr.Length);
try
{
da.UpdateCommand = new SqlCommand(" UPDATE LesseeYW SET LesseePic = #image , LesseeName = #Name, LesseeLastName = #Last , PassportNo = #pass,IDNo = #Number, BirthDate =#birth ,Gender = #gender , Country =#country,LesseePostalCode = #Postal,City = #city , Province = #province,MobileNo = #Mobile,HomePhoneNo = #phone,TutorName = #tutor,TutorLastName=#Tlast,AddressTutor = #line1,AddressLessee=#line2,TutorPhoneNo = #Tphone,TutorEmail =#Temail WHERE LesseeId = #ID ", conne);
da.UpdateCommand.Parameters.AddWithValue("#image", Pic_arr);
da.UpdateCommand.Parameters.AddWithValue("#Name", txtName.Text);
da.UpdateCommand.Parameters.AddWithValue("#Last", txtLAstname.Text);
da.UpdateCommand.Parameters.AddWithValue("#pass", txtPassport.Text);
da.UpdateCommand.Parameters.AddWithValue("#Number", txtID.Text);
da.UpdateCommand.Parameters.AddWithValue("#birth", DobdateEdit.DateTime);
da.UpdateCommand.Parameters.AddWithValue("#gender", GendercomboBoxEdit.SelectedItem.ToString());
da.UpdateCommand.Parameters.AddWithValue("#country", CountrycomboBoxEdit.SelectedItem.ToString());
da.UpdateCommand.Parameters.AddWithValue("#Postal", txtPostalCode.Text);
da.UpdateCommand.Parameters.AddWithValue("#city", txtCity.Text);
da.UpdateCommand.Parameters.AddWithValue("#province", txtProvince.Text);
da.UpdateCommand.Parameters.AddWithValue("#Mobile", txtMobile.Text);
da.UpdateCommand.Parameters.AddWithValue("#phone", txtHomePhone.Text);
da.UpdateCommand.Parameters.AddWithValue("#tutor", txtTutorName.Text);
da.UpdateCommand.Parameters.AddWithValue("#Tlast", txttutorLastname.Text);
da.UpdateCommand.Parameters.AddWithValue("#line1", tutorAddresstxt.Text);
da.UpdateCommand.Parameters.AddWithValue("#line2", LesseememoEdit1.Text);
da.UpdateCommand.Parameters.AddWithValue("#Tphone", txtTutorMobile.Text);
da.UpdateCommand.Parameters.AddWithValue("#Temail", txtEmail.Text);
//da.UpdateCommand.Parameters.AddWithValue("#ID"
da.UpdateCommand.ExecuteNonQuery();
conne.Close();
MessageBox.Show("Lessee Details Updated ", "Confirmation", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message);
}
}

at first you should program more objective. Dont declare all variables of your class as public static. You should make them private. To get acces you have to declare Properties.
Like this:
private string name;
public string Name
{
get {return name;}
set {name = value;}
}
if you have an ID you can easily make it read-only and noone from "outside" can modify it but everyone can read.
private int leeseId;
public int LeeseID
{
get{return leeseId;}
}
So you use "getter/setter" to offer your class properties. Further not all your variables should named leese... Just name it id,name,city,pic etc. In your form you create an Object from your class. You can name this object Leese.
private Leese leese = new Leese();
leese.id = ???
leese.name = ???
Much more readable.
da.updatecommand.parameters.addwithvalues("ID#",ds.tables["tblLesseeYW"].Rows[LesseeYW.Position][0];
You wrote "ID#" but it should be "#ID". And if you build your class as i descripe at top you can use property:
da.updatecommand.parameters.addwithvalues("#ID", leese.Id);
i hope that help you.

Related

Windows Forms Custom DataGridView

I am not very experienced with Windows Forms and am not pretty sure how I should tackle with this task the best way possible. I have a class which looks like this:
public class VariableMapping
{
private string variableName;
private string variableText;
private string variableSelector;
public VariableMapping(string variableName, string variableText, string variableSelector)
{
this.VariableName = variableName;
this.VariableText = variableText;
this.VariableSelector = variableSelector;
}
public string VariableName
{
get { return this.variableName; }
set { this.variableName = value; }
}
public string VariableText
{
get { return this.variableText; }
set { this.variableText = value; }
}
public string VariableSelector
{
get { return this.variableSelector; }
set { this.variableSelector = value; }
}
}
I want to create a DataGridView which should be bound to a number of elements of type VariableMapping in a list. However, I want only 1 of the properties(VariableText) of every instance to be shown in the DataGridView but I want to be able to address the whole object through the DataGrid when I need to. I also need to add 2 more custom columns: a ComboBox with predefined values and a NumberBox.
It might seem a really simple task but I'm trully unexperienced in WinForms and couldn't find a solution I can use already. Thank you!
Edit: I am trying something like this but it doesn't seem to work properly:
public partial class MappingTable : Form
{
private DataGridView dataGridView1 = new DataGridView();
public MappingTable(List<VariableMapping> variableMappings)
{
InitializeComponent();
var colors = new List<string>() { "#color_k1", "#color_k2", "#color_s1" };
dataGridView1.AutoGenerateColumns = false;
dataGridView1.AutoSize = true;
dataGridView1.DataSource = variableMappings;
DataGridViewColumn titleColumn = new DataGridViewColumn();
titleColumn.DataPropertyName = "VariableText";
titleColumn.HeaderText = "Variable";
titleColumn.Name = "Variable*";
dataGridView1.Columns.Add(titleColumn);
DataGridViewComboBoxColumn colorsColumn = new DataGridViewComboBoxColumn();
colorsColumn.DataSource = colors;
colorsColumn.HeaderText = "Color";
dataGridView1.Columns.Add(colorsColumn);
DataGridViewTextBoxColumn opacityColumn = new DataGridViewTextBoxColumn();
opacityColumn.HeaderText = "Opacity";
dataGridView1.Columns.Add(opacityColumn);
this.Controls.Add(dataGridView1);
this.AutoSize = true;
}
}

How to bind a combo box datasource to a form/listbox in windows forms?

I would like to get the form as datasource when i click combo box. How could i achieve this. Please give suggestion.
I've created a PopupComboBox class which inherits from the standard Windows Forms ComboBox. It has a Title property that you can set which will be used on the popup window when the combo is clicked.
public class PopupComboBox : ComboBox
{
private string title;
public string Title
{
get { return this.title; }
set { this.title = value; }
}
public PopupComboBox() : base()
{
}
public PopupComboBox (string title)
: base()
{
this.title = title;
}
protected override void OnMouseClick(MouseEventArgs e)
{
base.OnMouseClick(e);
// Show the popup form
var popup = new SelectItemForm(this.title, this);
var result = popup.ShowDialog(this);
if (result == DialogResult.OK)
{
// Select this item in the ComboBox
SelectedIndex = this.FindStringExact(popup.SelectedDisplay);
}
}
}
When you click on the combo, a popup form will come up (source code below for SelectItemForm). It uses the DataSource, ValueMember and DisplayMember of the parent PopupComboBox to populate a ListView with the list of items from the combo. When you click on OK, it will save the selected item in the SelectedValue and SelectedDisplay properties so that we can select that item in the ComboBox when the form closes.
public partial class SelectItemForm : Form
{
public object SelectedValue { get; private set; }
public string SelectedDisplay { get; private set; }
public SelectItemForm(string title, PopupComboBox parent)
:base()
{
InitializeComponent();
this.Text = title;
// Add items to the list
foreach (var item in parent.Items)
{
// Get the display and value member properties for this combo box
// and use them for the Code/Name columns in the popup form
var props = item.GetType().GetProperties();
var code = props.Where(p => p.Name == parent.ValueMember).Single().GetValue(item);
var name = props.Where(p => p.Name == parent.DisplayMember).Single().GetValue(item);
listView.Items.Add(new ListViewItem(
new string[] { code.ToString(), name.ToString() }));
}
}
private void btnOk_Click(object sender, EventArgs e)
{
if (listView.SelectedItems != null && listView.SelectedItems.Count > 0)
{
SelectedValue = listView.SelectedItems[0].Text;
SelectedDisplay = listView.SelectedItems[0].SubItems[1].Text;
DialogResult = DialogResult.OK;
}
else
{
MessageBox.Show(this, "Select an item first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
}
}
Here is the designer part of the form, where you can see what properties I've changed for the ListView to look like it does:
partial class SelectItemForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.listView = new System.Windows.Forms.ListView();
this.btnOk = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.Code = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.Value = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.SuspendLayout();
//
// listView
//
this.listView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.listView.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.Code,
this.Value});
this.listView.FullRowSelect = true;
this.listView.GridLines = true;
this.listView.Location = new System.Drawing.Point(3, 3);
this.listView.MultiSelect = false;
this.listView.Name = "listView";
this.listView.Size = new System.Drawing.Size(432, 170);
this.listView.TabIndex = 0;
this.listView.UseCompatibleStateImageBehavior = false;
this.listView.View = System.Windows.Forms.View.Details;
//
// btnOk
//
this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnOk.Location = new System.Drawing.Point(272, 179);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 23);
this.btnOk.TabIndex = 1;
this.btnOk.Text = "OK";
this.btnOk.UseVisualStyleBackColor = true;
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.Location = new System.Drawing.Point(353, 179);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 2;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// Code
//
this.Code.Text = "Code";
this.Code.Width = 108;
//
// Value
//
this.Value.Text = "Name";
this.Value.Width = 296;
//
// SelectItemForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(440, 214);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.btnOk);
this.Controls.Add(this.listView);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "SelectItemForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Title";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListView listView;
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.ColumnHeader Code;
private System.Windows.Forms.ColumnHeader Value;
}
I've also created a small test form where you can test out the functionality of the PopupComboBox, using a small list of products. You'll need to add a PopupComboBox to the form in the designer, and call it comboPopup.
public partial class TestForm : Form
{
public class Product
{
public string Code { get; set; }
public string Name { get; set; }
}
public TestForm()
{
InitializeComponent();
}
private void TestForm_Load(object sender, EventArgs e)
{
var products = new List<Product>();
products.Add(new Product { Code = "0001", Name = "Coca Cola" });
products.Add(new Product { Code = "0002", Name = "Mountain Dew" });
products.Add(new Product { Code = "0003", Name = "Sprite Zero" });
comboPopup.DataSource = products;
comboPopup.DisplayMember = "Name";
comboPopup.ValueMember = "Code";
}
}

Passing checkedlistbox.checked items cast as a List<BuiltInCategory> from a Form instance to a Revit class function

I am not having any issues making calls from the form instance to the Revit class. It's when I try to assign a List to the Revit class's function categoryList(), that I get a variable doesn't exist in the context error. I tried prefixing a reference to the instance of the form class "Form UF = new Form;" This doesn't work.
//The Revit Class
public Result Execute(ExternalCommandData commandData, ref string message,....)
{
User_Form UF = new User_Form(commandData);
UF.ShowDialog();
public List<BuiltInCategory> categoryList(Document doc, int intSwitch)
{
//list built in categories for built in filter_1
builtInCats_List = new List<BuiltInCategory>();
switch (intSwitch)
{
case (1):
...
case (3):
...
case (4):
{
builtInCats_List = newStateCb1;
return builtInCats_List;
}
default:
{
builtInCats_List = newStateCb1;
return builtInCats_List;
}
}
}
using Form = System.Windows.Forms.Form;
using WS = ModelAuditor_2014.WorksetSorter_2014;
using ModelAuditor_2014;
using System.Threading;
//The Form
namespace ModelAuditor_2014
{
public partial class User_Form : Form
{
//Constructor
WorksetSorter_2014 WS = new WorksetSorter_2014();
//Revit references
public Autodesk.Revit.UI.UIApplication rvtUiApp;
public Autodesk.Revit.UI.UIDocument rvtUiDoc;
public Autodesk.Revit.ApplicationServices.Application rvtApp;
//Global Variables
public List<BuiltInCategory> Filter01_CategoryList;
public List<BuiltInCategory> Filter02_CategoryList;
public int intSwitch;
public List<BuiltInCategory> newStateCb1;
public User_Form(ExternalCommandData commandData)
{
//Revit references
rvtUiApp = commandData.Application;
rvtUiDoc = rvtUiApp.ActiveUIDocument;
rvtApp = rvtUiApp.Application;
InitializeComponent();
}
public void User_Form_Load(object sender, EventArgs e)
{
//use rvtDoc = Doc
Autodesk.Revit.DB.Document rvtDoc = .....
//CheckedListBox for filter01
checkedListBox1.DataSource = WS.categoryList(rvtDoc, intSwitch = 1);
Filter01_CategoryList = new List<BuiltInCategory>();
Filter01_CategoryList = WS.RetrieveSchema(rvtDoc, false);
foreach (BuiltInCategory ChkedB1 in Filter01_CategoryList)
{
for (int i = 0; i < checkedListBox1.Items.Count; i++)
{
if (checkedListBox1.Items[i].ToString() == ChkedB1.ToString())
{
checkedListBox1.SetItemChecked(i, true);
}
}
}
public List<BuiltInCategory> returnNewStateCB1()
{
newStateCb1 = checkedListBox1.CheckedItems.Cast
<BuiltInCategory>().ToList<BuiltInCategory>();
return newStateCb1;
}
I passed the list from the win form to another public function in the revit app, I was able to access the list returned by this function.

Using Entity framework I want to add data to a text box

Using Entity framework I want to add data to a text box. I have done this before using a connection string and myReader. But new to EF.
private void displayCust()
{
using (Entities c = new Entities())
{
cbUsers.ItemsSource = c.customer.ToList();
}
}
To display:
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
using (Entities c = new Entities())
{
string sFirst = c.customer.ToString();
txtFirst.Text = sFirst;
}
}
Let's say you customer object looks like this:
public class Customer
{
public int ID { get; set; }
public string Name {get;set}
}
You can get the name of the first row in your database like this:
using (Entities c = new Entities())
{
string sFirst = c.customer.FirstOrDefault().Name.ToString();
txtFirst.Text = sFirst;
}
Or the customer name with a certain ID:
using (Entities c = new Entities())
{
string sFirst = c.customer.FirstOrDefault(x => x.ID == 2).Name.ToString();
txtFirst.Text = sFirst;
}

Get textbox value

If I start my form, write something in my textbox and then try to get the textbox value, then I get null. How can I get the textbox value? If I add a button and try to get the value, then it works. But I'm trying to do it without the button. I am using a WPF form. This is my code:
public partial class _2band : Page
{
public _2band()
{
InitializeComponent();
UpdateLayout();
RFIDI();
vardasBox1.Text = "";
dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
}
// MainWondow mainas = new MainWondow();
DB db = new DB();
string pavad;
string vardas;
int status;
string s = "";
string s0 = "";
RfidApi Api = new RfidApi();
private System.Windows.Threading.DispatcherTimer dispatcherTimer;
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
Api.nuskaitymas(out s0);
if (s0 != null)
{
s = s0;
vardas = vardasBox1.Text;
}
}

Resources