private void PopulateDatagrid(int ctrID) { using (MedaEntitiesDb context = new MedaEntitiesDb()) { if (String.IsNullOrWhiteSpace(txtSearch.Text)) { dgInstitution.ItemsSource = context.vwInstitutions.Where(n => n.ctrID == ctrID).ToList(); } else { GetSearchResult(); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { using (MedaEntitiesDb context = new MedaEntitiesDb()) { cmbCountry.ItemsSource = context.tblCountries.ToList(); cmbCountry.DisplayMemberPath = "ctrName"; cmbCountry.SelectedValuePath = "ctrID"; cmbCountry.SelectedIndex = 2; PopulateDatagrid(Int32.Parse(cmbCountry.SelectedValue.ToString())); //Type obj = Type.GetType("vwInstitutionCroatia"); //var q1 = Activator.CreateInstance(Type.GetType("WpfMedaSlovenija.vwInstitutionCroatia")); //var listQ1 = new List<typeof("WpfMedaSlovenija.vwInstitutionCroatia")>; } }
private void btnNew_Click(object sender, RoutedEventArgs e) { vwInstitution newInstitution = new vwInstitution(); newInstitution.ctrID = (int)cmbCountry.SelectedValue; NewInstitution ni = new NewInstitution { objInstitution = newInstitution }; ni.ShowDialog(); if (ni.result) { PopulateDatagrid(Int32.Parse(cmbCountry.SelectedValue.ToString())); MedaEntitiesDb mdb = new MedaEntitiesDb(); dgInstitution.SelectedItem = mdb.vwInstitutions.FirstOrDefault(n => n.insID == ni.index); mdb.Dispose(); } }
public static int AddHeadoffice(object _headoffice, int ctrID) { try { if (_headoffice != null) { using (MedaEntitiesDb mdb = new MedaEntitiesDb()) { switch (ctrID) { case 1: mdb.tblHeadofficeSerbias.Add((tblHeadofficeSerbia)_headoffice); mdb.SaveChanges(); return(mdb.tblHeadofficeSerbias.Max(n => n.hdoID)); case 3: mdb.tblHeadofficeCroatias.Add((tblHeadofficeCroatia)_headoffice); mdb.SaveChanges(); return(mdb.tblHeadofficeCroatias.Max(n => n.hdoID)); case 4: mdb.tblHeadofficeSlovenias.Add((tblHeadofficeSlovenia)_headoffice); mdb.SaveChanges(); return(mdb.tblHeadofficeSlovenias.Max(n => n.hdoID)); default: return(0); } } } else { return(0); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(0); } }
// var range = context.vwInstitutionCroatias.Where(n => n.insName.Contains("brod")).ToList(); // Type elementType = Type.GetType("WpfMedaSlovenija.vwInstitutionCroatia"); // Type listType = typeof(List<>).MakeGenericType(new Type[] { elementType }); // object query4 = Activator.CreateInstance(listType); // listType.InvokeMember("AddRange", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, query4, new object[] { range //}); // //PropertyInfo p = listType.GetProperty("AddRange"); // var l = context.vwInstitutionCroatias.ToList(); ////p.SetValue(query4, range,null); //var query1 = new List<vwInstitutionCroatia>(); //// //Type tableType = Type.GetType("WpfMedaSlovenija.MedaEntitiesDb"); //var tbl = Activator.CreateInstance(tableType); //// //Type typeContext = Type.GetType("WpfMedaSlovenija"); //PropertyInfo p = typeContext.GetProperty("vwInstitutionCroatias"); //var param = System.Linq.Expressions.Expression.Parameter(Type.GetType("WpfMedaSlovenija.vwInstitutionCroatia")); //var condition = System.Linq.Expressions.Expression.Lambda<Func<vwInstitutionCroatia, bool>>( // System.Linq.Expressions.Expression.Equal( // System.Linq.Expressions.Expression.Property(param, "insName"), // System.Linq.Expressions.Expression.Constant(s, typeof(string)) // ), // param); //var condition1 = System.Linq.Expressions.Expression.Lambda<Func<vwInstitutionCroatia, bool>>( // System.Linq.Expressions.Expression.Call( // System.Linq.Expressions.Expression.Constant(s), // typeof(ICollection<Boolean>).GetMethod("Contains"), // System.Linq.Expressions.Expression.Property(param, "insName")) // , param); //var item1 = context.vwInstitutionCroatias.Where(condition1); //var item = context.vwInstitutionCroatias.SingleOrDefault(condition); private void GetSearchResult() { string textSearch = txtSearch.Text; int counter = 0; using (MedaEntitiesDb context = new MedaEntitiesDb()) { if (String.IsNullOrWhiteSpace(txtSearch.Text)) { dgInstitution.ItemsSource = null; PopulateDatagrid(Int32.Parse(cmbCountry.SelectedValue.ToString())); return; } List <vwInstitution> query1 = new List <vwInstitution>(); if (textSearch.Contains("@")) { string[] arraySearch = textSearch.Split('@'); foreach (string s in arraySearch) { System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(s); switch (counter) { case 0: if (s.Length > 0) { query1.AddRange(context.vwInstitutions.Where(n => n.ctrID == (int)cmbCountry.SelectedValue).Where(n => SqlFunctions.PatIndex(s, n.insName) > 0).ToList()); } break; case 1: if (s.Length > 0) { query1.AddRange(context.vwInstitutions.Where(n => n.ctrID == (int)cmbCountry.SelectedValue).Where(n => SqlFunctions.PatIndex(s, n.ctyName) > 0).ToList()); } break; case 2: if (s.Length > 0) { query1.AddRange(context.vwInstitutions.Where(n => n.ctrID == (int)cmbCountry.SelectedValue).Where(n => SqlFunctions.PatIndex(s, n.insAddress) > 0).ToList()); } break; case 3: if (s.Length > 0) { query1.AddRange(context.vwInstitutions.Where(n => n.ctrID == (int)cmbCountry.SelectedValue).Where(n => SqlFunctions.PatIndex(s, n.hdoName) > 0).ToList()); } break; default: break; } counter++; } dgInstitution.ItemsSource = null; dgInstitution.ItemsSource = query1.ToList(); } else { if (textSearch.Length > 0) { query1.AddRange(context.vwInstitutions.Where(n => n.ctrID == (int)cmbCountry.SelectedValue).Where(n => SqlFunctions.PatIndex(txtSearch.Text, n.insName) > 0).ToList()); query1.AddRange(context.vwInstitutions.Where(n => n.ctrID == (int)cmbCountry.SelectedValue).Where(n => SqlFunctions.PatIndex(txtSearch.Text, n.ctyName) > 0).ToList()); query1.AddRange(context.vwInstitutions.Where(n => n.ctrID == (int)cmbCountry.SelectedValue).Where(n => SqlFunctions.PatIndex(txtSearch.Text, n.insAddress) > 0).ToList()); query1.AddRange(context.vwInstitutions.Where(n => n.ctrID == (int)cmbCountry.SelectedValue).Where(n => SqlFunctions.PatIndex(txtSearch.Text, n.hdoName) > 0).ToList()); dgInstitution.ItemsSource = null; dgInstitution.ItemsSource = query1.Distinct().ToList(); } } } }
private void dgInstitution_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.F) { txtSearch.Focus(); return; } string className = null; switch (cmbCountry.SelectedValue.ToString()) { case "1": className = "vwInstitutionSerbia"; break; case "3": className = "vwInstitutionCroatia"; break; case "4": className = "vwInstitutionSlovenia"; break; default: break; } if ((e.Key == Key.LeftCtrl && e.Key == Key.C) || (e.Key == Key.LeftShift || e.Key == Key.RightShift)) { StringBuilder s = new StringBuilder(); Type t = Type.GetType("WpfMedaSlovenija." + className); var row = Activator.CreateInstance(Type.GetType("WpfMedaSlovenija." + className)); //vwInstution row = new vwInstution(); if (dgInstitution.SelectedIndex > -1) { //row = (vwInstution)dgInstitution.SelectedItem; row = dgInstitution.SelectedItem; List <PropertyInfo> listProperties = t.GetProperties().ToList(); s.Append(row.GetType().GetProperty("insID").GetValue(row, null) + "\t"); s.Append(row.GetType().GetProperty("insName").GetValue(row) + "\t"); s.Append(row.GetType().GetProperty("ctyName").GetValue(row) + "\t"); s.Append(row.GetType().GetProperty("insAddress").GetValue(row)); //s.Append(t.GetProperty("hdoName").GetValue(row)); //s.Append(row.insID + "\t"); //s.Append(row.insName + "\t"); //s.Append(row.ctyName + "\t"); //s.Append(row.insAddress + "\t"); //s.Append(row.hdoName); } Clipboard.SetText(s.ToString()); } if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.N)) { //Type t = Type.GetType("WpfMedaSlovenija." + className); //var selectedInstitution = Activator.CreateInstance(Type.GetType("WpfMedaSlovenija." + className)); NewInstitution ni = new NewInstitution(); if (dgInstitution.SelectedIndex > -1) { vwInstitution vwi = (vwInstitution)dgInstitution.SelectedItem; ni.objInstitution.insName = vwi.insName; ni.objInstitution.insAddress = vwi.insAddress; ni.objInstitution.ctyID = vwi.ctyID; ni.objInstitution.ctyName = vwi.ctyName; ni.objInstitution.isbID = vwi.isbID; ni.objInstitution.isbName = vwi.isbName; ni.objInstitution.itpID = vwi.itpID; ni.objInstitution.itpName = vwi.itpName; ni.objInstitution.hdoID = vwi.hdoID; ni.objInstitution.hdoName = vwi.hdoName; ni.objInstitution.ctrID = vwi.ctrID; } ni.ShowDialog(); if (ni.result) { PopulateDatagrid(Int32.Parse(cmbCountry.SelectedValue.ToString())); MedaEntitiesDb mdb = new MedaEntitiesDb(); dgInstitution.SelectedItem = mdb.vwInstitutions.FirstOrDefault(n => n.insID == ni.index); mdb.Dispose(); } } if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.E)) { //Type t = Type.GetType("WpfMedaSlovenija." + className); //var selectedInstitution = Activator.CreateInstance(Type.GetType("WpfMedaSlovenija." + className)); NewInstitution ni = new NewInstitution(); if (dgInstitution.SelectedIndex > -1) { ni.objInstitution = (vwInstitution)dgInstitution.SelectedItem; } ni.ShowDialog(); if (ni.result) { PopulateDatagrid(Int32.Parse(cmbCountry.SelectedValue.ToString())); MedaEntitiesDb mdb = new MedaEntitiesDb(); dgInstitution.SelectedItem = mdb.vwInstitutions.FirstOrDefault(n => n.insID == ni.index); mdb.Dispose(); } } }
public static int EditHeadoffice(object _headoffice, int ctrID) { try { string className = null; switch (ctrID) { case 1: className = "tblHeadofficeSerbia"; _headoffice = (tblHeadofficeSerbia)_headoffice; break; case 3: className = "tblHeadofficeCroatia"; _headoffice = (tblHeadofficeCroatia)_headoffice; break; case 4: className = "tblHeadofficeSlovenia"; _headoffice = (tblHeadofficeSlovenia)_headoffice; break; default: break; } if (_headoffice != null) { using (MedaEntitiesDb mdb = new MedaEntitiesDb()) { Type t = Type.GetType("WpfMedaSlovenija." + className); dynamic hd = Cast(_headoffice, t); object _Headoffice = Activator.CreateInstance(Type.GetType("WpfMedaSlovenija." + className)); //tblHeadoffice _Headoffice = mdb.tblHeadoffice.FirstOrDefault(n => n.hdoID == _headoffice.hdoID); if (_Headoffice != null) { t.GetProperty("hdoName").SetValue(null, hd.hdoName); t.GetProperty("staID").SetValue(null, hd.staID); // _Headoffice.hdoName = _headoffice.hdoName; //_Headoffice.staID = _headoffice.staID; mdb.SaveChanges(); return(hd.hdoID); } else { return(0); } } } else { return(0); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(0); } }
public static int SaveInstitution(object _institution, int ctrID) { try { string className = null; switch (ctrID) { case 1: className = "tblInstitutionSerbia"; //_headoffice = (tblHeadofficeCroatia)_headoffice; break; case 3: className = "tblInstitutionCroatia"; //_headoffice = (tblHeadofficeCroatia)_headoffice; break; case 4: className = "tblInstitutionSlovenia"; //_headoffice = (tblHeadofficeSlovenia)_headoffice; break; default: break; } if (_institution != null) { using (MedaEntitiesDb mdb = new MedaEntitiesDb()) { Type t = Type.GetType("WpfMedaSlovenija." + className); dynamic ins = Cast(_institution, t); //object _Institution = Activator.CreateInstance(Type.GetType("WpfMedaSlovenija." + className)); //_Institution = ins; //mdb.SaveChanges(); //return ins.insID; if (ins.insID == 0) { //add switch (ctrID) { case 1: mdb.tblInstitutionSerbias.Add(ins); mdb.SaveChanges(); return(mdb.tblInstitutionSerbias.Max(n => n.insID)); case 3: mdb.tblInstitutionCroatias.Add(ins); mdb.SaveChanges(); return(mdb.tblInstitutionCroatias.Max(n => n.insID)); case 4: mdb.tblInstitutionSlovenias.Add(ins); mdb.SaveChanges(); return(mdb.tblInstitutionSlovenias.Max(n => n.insID)); default: return(0); } } else { //edit int i = ins.insID; switch (ctrID) { case 1: tblInstitutionSerbia insSerbia = mdb.tblInstitutionSerbias.Where(n => n.insID == i).FirstOrDefault(); insSerbia.insName = ins.insName; insSerbia.insAddress = ins.insAddress; insSerbia.isbID = ins.isbID; insSerbia.ctyID = ins.ctyID; insSerbia.hdoID = ins.hdoID; mdb.SaveChanges(); return(insSerbia.insID); case 3: tblInstitutionCroatia insCoraita = mdb.tblInstitutionCroatias.Where(n => n.insID == i).FirstOrDefault(); insCoraita.insName = ins.insName; insCoraita.insAddress = ins.insAddress; insCoraita.isbID = ins.isbID; insCoraita.ctyID = ins.ctyID; insCoraita.hdoID = ins.hdoID; mdb.SaveChanges(); return(insCoraita.insID); case 4: tblInstitutionSlovenia insSlovenia = mdb.tblInstitutionSlovenias.Where(n => n.insID == i).FirstOrDefault(); insSlovenia.insName = ins.insName; insSlovenia.insAddress = ins.insAddress; insSlovenia.isbID = ins.isbID; insSlovenia.ctyID = ins.ctyID; insSlovenia.hdoID = ins.hdoID; mdb.SaveChanges(); return(insSlovenia.insID); default: return(0); } } } } else { return(0); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(0); } }