Windows 8 Message Box Style WPF - c#

I'm tryin to create WIN8 Msgbox Style in WPF and follow this
tuts. The problem is the message box called from the Main window.
Could you please help me if I want the message box appears when I press a button
from the child window ?
This is ViewModel of my Main Window
using FirstFloor.ModernUI.Presentation;
using dLondre;
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using dLondre.Models;
using dLondre.ViewModels;
using System.Windows;
using Caliburn.Micro;
using dLondre.Interfaces;
namespace dLondre.ViewModels
{
[Export(typeof(IShell))]
public class MainWindowViewModel : Screen, IShell
{
private readonly IWindowManager _windowManager;
private int _overlayDependencies;
[ImportingConstructor]
public MainWindowViewModel(IWindowManager windowManager)
{
_windowManager = windowManager;
}
public bool IsOverlayVisible
{
get { return _overlayDependencies > 0; }
}
public void ShowOverlay()
{
_overlayDependencies++;
NotifyOfPropertyChange(() => IsOverlayVisible);
}
public void HideOverlay()
{
_overlayDependencies--;
NotifyOfPropertyChange(() => IsOverlayVisible);
}
// I want to do this in the child window
// |
// |
// v
public void DisplayMessageBox()
{
MessageBoxResult dix;
dix = _windowManager.ShowMetroMessageBox("message", "title", MessageBoxButton.OKCancel);
if (dix == MessageBoxResult.OK)
{
_windowManager.ShowMetroMessageBox("OK");
}
else
{
_windowManager.ShowMetroMessageBox("CANCEL");
}
}
}
}
This is ViewModels of my Child Window
using FirstFloor.ModernUI.Presentation;
using dLondre;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using dLondre.Models;
using dLondre.ViewModels;
using System.Windows;
using Caliburn.Micro;
namespace dLondre.ViewModels {
public class UserViewModel : NotifyPropertyChanged, IDataErrorInfo
{
#region Construction
public UserViewModel()
{
_user = new User { FirstName = "",
LastName="",
Gender = "",
BirthDate= DateTime.Today,
Address="",
City="",
ZipCode="",
Email="",
UserID="",
Password="",
Status="",
Deleted=false,
CreatedOn=DateTime.Today,
CreatedBy="",
UpdatedOn=DateTime.Today,
UpdatedBy="" };
}
#endregion
#region Members
User _user;
#endregion
#region Properties
public User User
{
get
{
return _user;
}
set
{
_user = value;
}
}
public string FirstName
{
get { return User.FirstName; }
set
{
if (User.FirstName != value)
{
User.FirstName = value;
OnPropertyChanged("FirstName");
}
}
}
public string LastName
{
get { return User.LastName; }
set
{
if (User.LastName != value)
{
User.LastName = value;
OnPropertyChanged("LastName");
}
}
}
public string Gender
{
get { return User.Gender; }
set
{
if (User.Gender != value)
{
User.Gender = value;
OnPropertyChanged("Gender");
}
}
}
public DateTime BirthDate
{
get { return User.BirthDate; }
set
{
if (User.BirthDate != value)
{
User.BirthDate = value;
OnPropertyChanged("BirthDate");
}
}
}
public string Address
{
get { return User.Address; }
set
{
if (User.Address != value)
{
User.Address = value;
OnPropertyChanged("Address");
}
}
}
public string City
{
get { return User.City; }
set
{
if (User.City != value)
{
User.City = value;
OnPropertyChanged("City");
}
}
}
public string ZipCode
{
get { return User.ZipCode; }
set
{
if (User.ZipCode != value)
{
User.ZipCode = value;
OnPropertyChanged("ZipCode");
}
}
}
public string Email
{
get { return User.Email; }
set
{
if (User.Email != value)
{
User.Email = value;
OnPropertyChanged("Email");
}
}
}
public string UserId
{
get { return User.UserID; }
set
{
if (User.UserID != value)
{
User.UserID = value;
OnPropertyChanged("UserId");
}
}
}
public string Password
{
get { return User.Password; }
set
{
if (User.Password != value)
{
User.Password = value;
OnPropertyChanged("Password");
}
}
}
public string Status
{
get { return User.Status; }
set
{
if (User.Status != value)
{
User.Status = value;
OnPropertyChanged("Status");
}
}
}
public bool Deleted
{
get { return User.Deleted; }
set
{
if (User.Deleted != value)
{
User.Deleted = value;
OnPropertyChanged("Deleted");
}
}
}
public DateTime CreatedOn
{
get { return User.CreatedOn; }
set
{
if (User.CreatedOn != value)
{
User.CreatedOn = value;
OnPropertyChanged("CreatedOn");
}
}
}
public string CreatedBy
{
get { return User.CreatedBy; }
set
{
if (User.CreatedBy != value)
{
User.CreatedBy = value;
OnPropertyChanged("CreatedBy");
}
}
}
public DateTime UpdatedOn
{
get { return User.UpdatedOn; }
set
{
if (User.UpdatedOn != value)
{
User.UpdatedOn = value;
OnPropertyChanged("CreatedOn");
}
}
}
public string UpdatedBy
{
get { return User.UpdatedBy; }
set
{
if (User.UpdatedBy != value)
{
User.UpdatedBy = value;
OnPropertyChanged("UpdatedBy");
}
}
}
#endregion
public string Error
{
get { return null; }
}
public string this[string columnName]
{
get
{
if (columnName == "FirstName")
{
return string.IsNullOrEmpty(User.FirstName) ? "Required value" : null;
}
if (columnName == "LastName")
{
return string.IsNullOrEmpty(User.LastName) ? "Required value" : null;
}
if (columnName == "Email")
{
return string.IsNullOrEmpty(User.Email) ? "Required value" : null;
}
if (columnName == "UserId")
{
return string.IsNullOrEmpty(User.UserID) ? "Required value" : null;
}
return null;
}
}
private readonly IWindowManager _windowManager;
// Here comes the trouble
// |
// |
// v
public void DisplayMessageBox()
{
_windowManager.ShowMetroMessageBox("Are you sure you want to delete...", "Confirm Delete",
MessageBoxButton.YesNo);
}
}
}
This is my sampleproject

Surely if you copy the following code into your child view model then you can call it from there?
private readonly IWindowManager _windowManager;
public void DisplayMessageBox()
{
_windowManager.ShowMetroMessageBox("Are you sure you want to delete...", "Confirm
Delete", MessageBoxButton.YesNo);
}

Related

Problem getting a string from a Combobox into a class variable [C#]

The button function, should take whatever text is in the combo box and place it within sleeper.traintype
private void Btn_Apply_Click(object sender, RoutedEventArgs e)
{
try
{
sleeper.trainType = CmbBox_TrainType.Text;
if (CmbBox_TrainType.Text == "Sleeper")
{
// instantiate the sleeper train
sleeper.trainType = CmbBox_TrainType.Text;
}
}
My sleeper train class (inheriting from overall train class)
public class Sleeper : Train
{
private string _intermediate, _intermediate1, _intermediate2, _intermediate3;
private bool _cabin;
public string intermediate
{
get
{
return _intermediate;
}
set
{
_intermediate = value;
}
}
public string intermediate1
{
get
{
return _intermediate1;
}
set
{
_intermediate1 = value;
}
}
public string intermediate2
{
get
{
return _intermediate2;
}
set
{
_intermediate2 = value;
}
}
public string intermediate3
{
get
{
return _intermediate3;
}
set
{
_intermediate3 = value;
}
}
The train class:
public class Train
{
private string _trainID, _departureDay, _departureStation, _destinationStation, _departureTime, _trainType;
private bool _firstClass;
public string timePunctuation = ":";
public string dayPunctuation = "/";
public string trainID
{
get
{
return _trainID;
}
set
{
// check if the vlaue has letters & numbers and that the length is correct
if(value.Length == 4 && Regex.IsMatch(value, "[A-Z][0-9]"))
{
_trainID = value;
}
else
{
throw new FormatException("That train ID is not valid! (Example: AA11)");
}
}
}
public string departureDay
{
get
{
return _departureDay;
}
set
{
if(value.Length == 0)
{
throw new FormatException("You need to choose a departure day!");
} else
{
_departureDay = value;
}
}
}
public string departureTime
{
get
{
return _departureTime;
}
set
{
if(value.Length != 5 || value.Contains(timePunctuation) == false)
{
throw new FormatException("The time must be in this format: (11:11 or 03:22)");
} else
{
_departureTime = value;
}
}
}
public string departureStation
{
get
{
return _departureStation;
}
set
{
if(value.Length == 0)
{
throw new FormatException("You must enter a departure station!");
} else
{
_departureStation = value;
}
}
}
public string destinationStation
{
get
{
return _destinationStation;
}
set
{
if(value.Length == 0)
{
throw new FormatException("You must enter a destination!");
} else
{
_departureStation = value;
}
}
}
public string trainType
{
get
{
return _trainType;
}
set
{
value = _trainType;
}
}
}
I'm using a combobox with three options "Sleeper", "Stopping" and "Express". When using breakpoints next to sleeper.trainType = CmbBox_TrainType.Text; it creates my class but states that my sleeper.trainType variable is null. But it says that
CmbBox_TrainType = "Sleeper"
Instantiate sleeper at the start with Sleeper sleeper = new Sleeper();
but have also tried to put it in the if and just before sleeper.trainType = CmbBox_TrainType.Text;

Using ServerManager to list virtual directories separated by type

I'm using ServerManager (Microsoft.Web.Administration.dll) to create an Application to manage my web servers, All of my server are running IIS 7 and above. Majority of the site is complete, i can manage servers, sites, FTP, SSL etc.
Here is my issue,
I am able to create virtual directories and applications, but having an issue with listing them separately when viewing the site information as you can do in IIS. I am able to list the all together as Virtual Directories by just getting item.VirtualDirectories[0].PhysicalPath but would like to show Applications in one column and basic virtual directories in the second column. I'm sure i need to be looking for if root application path is siteid, or if it has an AppPool somehow but having a hard time figuring how. Any help would be appreciated.
My Code:
SiteVirtualDirectory.cs
private string anonymousUsername;
private string anonymousUserPassword;
private string contentPath;
private bool enableWritePermissions;
private bool enableParentPaths;
private bool enableDirectoryBrowsing;
private bool enableAnonymousAccess;
private bool enableWindowsAuthentication;
private bool enableBasicAuthentication;
private bool enableDynamicCompression;
private bool enableStaticCompression;
private string defaultDocs;
private string httpRedirect;
private HttpError[] httpErrors;
private HttpErrorsMode errorMode;
private HttpErrorsExistingResponse existingResponse;
private MimeMap[] mimeMaps;
private HttpHeader[] httpHeaders;
private bool aspInstalled;
private string aspNetInstalled;
private string phpInstalled;
private bool perlInstalled;
private bool pythonInstalled;
private bool coldfusionInstalled;
private bool cgiBinInstalled;
private string applicationPool;
private bool dedicatedApplicationPool;
private string parentSiteName;
private bool redirectExactUrl;
private bool redirectDirectoryBelow;
private bool redirectPermanent;
private bool sharePointInstalled;
private bool iis7;
private string consoleUrl;
private string php5VersionsInstalled;
public string AnonymousUsername
{
get { return anonymousUsername; }
set { anonymousUsername = value; }
}
public string AnonymousUserPassword
{
get { return anonymousUserPassword; }
set { anonymousUserPassword = value; }
}
public string ContentPath
{
get { return contentPath; }
set { contentPath = value; }
}
public string HttpRedirect
{
get { return httpRedirect; }
set { httpRedirect = value; }
}
public string DefaultDocs
{
get { return defaultDocs; }
set { defaultDocs = value; }
}
public MimeMap[] MimeMaps
{
get { return mimeMaps; }
set { mimeMaps = value; }
}
public HttpError[] HttpErrors
{
get { return httpErrors; }
set { httpErrors = value; }
}
public HttpErrorsMode ErrorMode
{
get { return errorMode; }
set { errorMode = value; }
}
public HttpErrorsExistingResponse ExistingResponse
{
get { return existingResponse; }
set { existingResponse = value; }
}
public string ApplicationPool
{
get { return this.applicationPool; }
set { this.applicationPool = value; }
}
public bool EnableParentPaths
{
get { return this.enableParentPaths; }
set { this.enableParentPaths = value; }
}
public HttpHeader[] HttpHeaders
{
get { return this.httpHeaders; }
set { this.httpHeaders = value; }
}
public bool EnableWritePermissions
{
get { return this.enableWritePermissions; }
set { this.enableWritePermissions = value; }
}
public bool EnableDirectoryBrowsing
{
get { return this.enableDirectoryBrowsing; }
set { this.enableDirectoryBrowsing = value; }
}
public bool EnableAnonymousAccess
{
get { return this.enableAnonymousAccess; }
set { this.enableAnonymousAccess = value; }
}
public bool EnableWindowsAuthentication
{
get { return this.enableWindowsAuthentication; }
set { this.enableWindowsAuthentication = value; }
}
public bool EnableBasicAuthentication
{
get { return this.enableBasicAuthentication; }
set { this.enableBasicAuthentication = value; }
}
public bool EnableDynamicCompression
{
get { return this.enableDynamicCompression; }
set { this.enableDynamicCompression = value; }
}
public bool EnableStaticCompression
{
get { return this.enableStaticCompression; }
set { this.enableStaticCompression = value; }
}
public bool AspInstalled
{
get { return this.aspInstalled; }
set { this.aspInstalled = value; }
}
public string AspNetInstalled
{
get { return this.aspNetInstalled; }
set { this.aspNetInstalled = value; }
}
public string PhpInstalled
{
get { return this.phpInstalled; }
set { this.phpInstalled = value; }
}
public bool PerlInstalled
{
get { return this.perlInstalled; }
set { this.perlInstalled = value; }
}
public bool PythonInstalled
{
get { return this.pythonInstalled; }
set { this.pythonInstalled = value; }
}
public bool ColdFusionInstalled
{
get { return this.coldfusionInstalled; }
set { this.coldfusionInstalled = value; }
}
public bool DedicatedApplicationPool
{
get { return this.dedicatedApplicationPool; }
set { this.dedicatedApplicationPool = value; }
}
public string ParentSiteName
{
get { return this.parentSiteName; }
set { this.parentSiteName = value; }
}
public bool RedirectExactUrl
{
get { return this.redirectExactUrl; }
set { this.redirectExactUrl = value; }
}
public bool RedirectDirectoryBelow
{
get { return this.redirectDirectoryBelow; }
set { this.redirectDirectoryBelow = value; }
}
public bool RedirectPermanent
{
get { return this.redirectPermanent; }
set { this.redirectPermanent = value; }
}
public bool CgiBinInstalled
{
get { return this.cgiBinInstalled; }
set { this.cgiBinInstalled = value; }
}
public bool SharePointInstalled
{
get { return this.sharePointInstalled; }
set { this.sharePointInstalled = value; }
}
public bool IIs7
{
get { return this.iis7; }
set { this.iis7 = value; }
}
public string ConsoleUrl
{
get { return consoleUrl; }
set { consoleUrl = value; }
}
public string Php5VersionsInstalled
{
get { return php5VersionsInstalled; }
set { php5VersionsInstalled = value; }
}
[XmlIgnore]
public string VirtualPath
{
get
{
// virtual path is rooted
if (String.IsNullOrEmpty(ParentSiteName))
return "/"; //
else if (!Name.StartsWith("/"))
return "/" + Name;
//
return Name;
}
}
[XmlIgnore]
public string FullQualifiedPath
{
get
{
if (String.IsNullOrEmpty(ParentSiteName))
return Name;
else if (Name.StartsWith("/"))
return ParentSiteName + Name;
else
return ParentSiteName + "/" + Name;
}
}
Get Virtual Directories:
public class GetVirtualDirectories(ServerManager iismanager, string siteId)
{
if (!SiteExists(iismanager, siteId))
return new SiteVirtualDirectory[] { };
var vdirs = new List<SiteVirtualDirectory>();
var iisObject = iismanager.Sites[siteId];
//
foreach (var item in iisObject.Applications)
{
// do not list root Virtual Directory
if (item.Path == "/")
continue;
//
vdirs.Add(new SiteVirtualDirectory
{
Name = ConfigurationUtility.GetNonQualifiedVirtualPath(item.Path),
ContentPath = item.VirtualDirectories[0].PhysicalPath
});
}
//
return vdirs.ToArray();
}

objectcontext instance is not null but its disposed even if i declare it and give it same value

i know that this question have asked many times but i havent find any answer that can help me
the problem is
the-objectcontext-instance-has-been-disposed-and-can-no-longer-be-used-for-operations-that-require-a-connection
after i declare copy of entity object that have linked to other entity with 1 to many relation
this is the class
using System;
using System.Linq;
using School.Component;
using System.Windows.Input;
using DataAccess;
using System.Collections.ObjectModel;
using DataAccess.Repository;
using Microsoft.Practices.Prism.Commands;
using System.Collections.Generic;
namespace School.WpfApp.ViewModels
{
public class LevelsPerYearNewVM : ViewModelBase
{
SchAvaiLevelsPerYear _CurrentLevelsPerYear;
SchAvaiLevelsPerYear _old;
private bool _isnew = false;
bool _IsEnabled = false;
StudyYearRepository _Repository = new StudyYearRepository();
SchoolSettingRepository _SRepository = new SchoolSettingRepository();
ObservableCollection<StageLevel> _AllStageLevel;
StageLevel _SelectrdStageLevel;
ObservableCollection<SchAvaiLevelsPerYear> _allSchAvaiLevelsPerYear;
ObservableCollection<CoursesLevelsPerStYear> _AllCoursesLevelsPerStYear;
private string errorMasseg;
public LevelsPerYearNewVM(SchAvaiLevelsPerYear f, ObservableCollection<SchAvaiLevelsPerYear> _list)
: base()
{
_old = (f);
CurrentLevelsPerYear = new SchAvaiLevelsPerYear()
{
Avalible = f.Avalible,
CoursCount = f.CoursCount,
YearID = f.YearID,
ID = f.ID,
SchoolID = f.SchoolID,
UserID = f.UserID,
StageLevelID = f.StageLevelID,
};
InitVars();
CreateCommands();
ErrorMasseg = "";
if (_CurrentLevelsPerYear.ID > 0)
{
this.Title = "تعديل بيانات المستوى الدراسي";
}
else
{ this.Title = "اضافة مستوى دراسي"; IsEnabled = true; _isnew = true; }
_allSchAvaiLevelsPerYear = _list;
}
protected override async void InitVars()
{
AllStageLevel = await _SRepository.GetAllStageLevelsIncludeCourses();
if(!isnew)
AllCoursesLevelsPerStYear = await _SRepository.GetAllAllCoursesLevelsPerStYearBySchAvaiLevelsPerYearID( _CurrentLevelsPerYear.ID);
}
protected override void CreateCommands()
{
SaveCommand = new RelayCommand(o =>
{
Save();
}
, o => Valdite());
CanselCommand = new DelegateCommand(() =>
{
if (Closed != null)
{
_CurrentLevelsPerYear = null;
Closed(_CurrentLevelsPerYear);
}
}
, () => true);
}
private void Save()
{
SchAvaiLevelsPerYear a = null;
string masseg = "";
if (Valdite())
{
a = _allSchAvaiLevelsPerYear.FirstOrDefault(i => i.ID != CurrentLevelsPerYear.ID && i.StageLevelID == _CurrentLevelsPerYear.StageLevelID);
if (a == null)
{
_CurrentLevelsPerYear.CoursCount = _AllCoursesLevelsPerStYear.Where(cc=>cc.Avalible).Count();
_CurrentLevelsPerYear.UserID = Session.SessionData.CurrentUser.UserID;
_CurrentLevelsPerYear.ID = _Repository.SaveSchAvaiLevelsPerYear(_CurrentLevelsPerYear);
CoursesLevelsPerStYear v;
foreach (CoursesLevelsPerStYear c in _AllCoursesLevelsPerStYear)
{
if (_isnew)
c.SALByYearID = _CurrentLevelsPerYear.ID;
c.UserID = Session.SessionData.CurrentUser.UserID;
v = (CoursesLevelsPerStYear)MyDataAccessTools.Clone<CoursesLevelsPerStYear>(c);
c.ID= _Repository.SaveCoursesLevelsPerStYearDirctliy(v);
}
///// the error massage aaper her when i use break point to know what are the changes that have been done
_CurrentLevelsPerYear.CoursesLevelsPerStYears = _AllCoursesLevelsPerStYear
//////
/////
}
else
masseg = "يوجد مستوى دراسي مماثل";
}
if (string.IsNullOrWhiteSpace(masseg))
Closed(a);
else
ErrorMasseg = masseg;
}
private bool Valdite()
{
bool result = false;
if (_CurrentLevelsPerYear != null && _CurrentLevelsPerYear.StageLevelID>0 )
result = true;
return result;
}
public override void Reset()
{
}
public SchAvaiLevelsPerYear CurrentLevelsPerYear
{
get { return _CurrentLevelsPerYear; }
set
{
if (_CurrentLevelsPerYear != value)
{
_CurrentLevelsPerYear = value;
NotifyPropertyChanged("CurrentLevelsPerYear");
}
}
}
public ObservableCollection<StageLevel> AllStageLevel
{
get { return _AllStageLevel; }
set
{
if (_AllStageLevel != value)
{
_AllStageLevel = value;
NotifyPropertyChanged("AllStageLevel");
}
}
}
public StageLevel SelectrdStageLevel
{
get { return _SelectrdStageLevel; }
set
{
if (_SelectrdStageLevel != value)
{
_SelectrdStageLevel = value;
NotifyPropertyChanged("SelectrdStageLevel");
if (_isnew)
{
ObservableCollection<CoursesLevelsPerStYear> allcby = new ObservableCollection<CoursesLevelsPerStYear>();
CoursesLevelsPerStYear cby;
foreach (CoursesByLevel cbl in _SelectrdStageLevel.CoursesByLevels)
{
cby = new CoursesLevelsPerStYear() {StartDate = Session.SessionData.CurrentYear.StartDate, Avalible =true
, CoursByLevelID = cbl.ID , CoursesByLevel= cbl, UserID = Session.SessionData.CurrentUser.UserID,
MaxLecturePerWeak = cbl.MaxLecturePerWeak,MinLecturePerWeak = cbl.MinLecturePerWeak,
SchAvaiLevelsPerYear = _CurrentLevelsPerYear
};
allcby.Add(cby);
}
AllCoursesLevelsPerStYear = allcby;
}
}
}
}
public ObservableCollection<CoursesLevelsPerStYear> AllCoursesLevelsPerStYear
{
get { return _AllCoursesLevelsPerStYear; }
set
{
if (_AllCoursesLevelsPerStYear != value)
{
_AllCoursesLevelsPerStYear = value;
NotifyPropertyChanged("AllCoursesLevelsPerStYear");
}
}
}
public bool IsEnabled
{
get { return _IsEnabled; }
set
{
if (_IsEnabled != value)
{
_IsEnabled = value;
NotifyPropertyChanged("IsEnabled");
}
}
}
public string ErrorMasseg
{
get { return errorMasseg; }
private set
{
if (value != errorMasseg)
{
errorMasseg = value;
NotifyPropertyChanged("ErrorMasseg");
}
}
}
public event Action<SchAvaiLevelsPerYear> Closed;
public ICommand SaveCommand
{
private set;
get;
}
public DelegateCommand CanselCommand
{
private set;
get;
}
}
}
this the entity
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DataAccess
{
using System;
using System.Collections.ObjectModel;
public partial class SchAvaiLevelsPerYear : BaseModel
{
public SchAvaiLevelsPerYear()
{
this.CoursesLevelsPerStYears = new ObservableCollection<CoursesLevelsPerStYear>();
this.StduyYearLevelFrogs = new ObservableCollection<StduyYearLevelFrog>();
}
private int _iD;
public int ID
{
get { return _iD; }
set { SetProperty(ref _iD, value); }
}
private int _yearID;
public int YearID
{
get { return _yearID; }
set { SetProperty(ref _yearID, value); }
}
private int _stageLevelID;
public int StageLevelID
{
get { return _stageLevelID; }
set { SetProperty(ref _stageLevelID, value); }
}
private int _schoolID;
public int SchoolID
{
get { return _schoolID; }
set { SetProperty(ref _schoolID, value); }
}
private bool _avalible;
public bool Avalible
{
get { return _avalible; }
set { SetProperty(ref _avalible, value); }
}
private int _coursCount;
public int CoursCount
{
get { return _coursCount; }
set { SetProperty(ref _coursCount, value); }
}
private byte[] _timestamp;
public byte[] Timestamp
{
get { return _timestamp; }
set { SetProperty(ref _timestamp, value); }
}
private int _userID;
public int UserID
{
get { return _userID; }
set { SetProperty(ref _userID, value); }
}
public virtual Branch Branch { get; set; }
public virtual ObservableCollection<CoursesLevelsPerStYear> CoursesLevelsPerStYears { get; set; }
public virtual StageLevel StageLevel { get; set; }
public virtual StudyYear StudyYear { get; set; }
public virtual ObservableCollection<StduyYearLevelFrog> StduyYearLevelFrogs { get; set; }
}
}
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DataAccess
{
using System;
using System.Collections.ObjectModel;
public partial class CoursesLevelsPerStYear : BaseModel
{
public CoursesLevelsPerStYear()
{
this.CourseGroups = new ObservableCollection<CourseGroup>();
this.Teachers = new ObservableCollection<Teacher>();
}
private int _iD;
public int ID
{
get { return _iD; }
set { SetProperty(ref _iD, value); }
}
private int _coursByLevelID;
public int CoursByLevelID
{
get { return _coursByLevelID; }
set { SetProperty(ref _coursByLevelID, value); }
}
private int _sALByYearID;
public int SALByYearID
{
get { return _sALByYearID; }
set { SetProperty(ref _sALByYearID, value); }
}
private int _maxLecturePerWeak;
public int MaxLecturePerWeak
{
get { return _maxLecturePerWeak; }
set { SetProperty(ref _maxLecturePerWeak, value); }
}
private int _minLecturePerWeak;
public int MinLecturePerWeak
{
get { return _minLecturePerWeak; }
set { SetProperty(ref _minLecturePerWeak, value); }
}
private bool _haveGroup;
public bool HaveGroup
{
get { return _haveGroup; }
set { SetProperty(ref _haveGroup, value); }
}
private bool _avalible;
public bool Avalible
{
get { return _avalible; }
set { SetProperty(ref _avalible, value); }
}
private Nullable<int> _holeID;
public Nullable<int> HoleID
{
get { return _holeID; }
set { SetProperty(ref _holeID, value); }
}
private bool _hasHole;
public bool HasHole
{
get { return _hasHole; }
set { SetProperty(ref _hasHole, value); }
}
private System.DateTime _startDate;
public System.DateTime StartDate
{
get { return _startDate; }
set { SetProperty(ref _startDate, value); }
}
private Nullable<System.DateTime> _stopDate;
public Nullable<System.DateTime> StopDate
{
get { return _stopDate; }
set { SetProperty(ref _stopDate, value); }
}
private byte[] _timestamp;
public byte[] Timestamp
{
get { return _timestamp; }
set { SetProperty(ref _timestamp, value); }
}
private int _userID;
public int UserID
{
get { return _userID; }
set { SetProperty(ref _userID, value); }
}
public virtual ObservableCollection<CourseGroup> CourseGroups { get; set; }
public virtual CoursesByLevel CoursesByLevel { get; set; }
public virtual Hole Hole { get; set; }
public virtual SchAvaiLevelsPerYear SchAvaiLevelsPerYear { get; set; }
public virtual ObservableCollection<Teacher> Teachers { get; set; }
}
}
namespace DataAccess
{
partial class CoursesLevelsPerStYear : BaseModel
{
private bool _CanEdit;
public bool CanEdit
{
get { return _CanEdit; }
set
{
SetProperty(ref _CanEdit, value);
}
}
private bool _EditMode;
public bool EditMode
{
get { return _EditMode; }
set
{
SetProperty(ref _EditMode, value);
}
}
string _EditButtonVisibility = "";
public string EditButtonVisibility
{
get
{
return _EditButtonVisibility;
}
set { SetProperty(ref _EditButtonVisibility, value); }
}
}
}
this only relation that Have problem like this . yes i have forget to mention that i change the DBContext of the entity framework using this and this
and i am using entity framework 6.2
excuse my english i am not a good english writer .

ExtensionDataObject showing up in service reference

I'm writing a WCF service and the ExtensionDataObject shows up in my Reference.cs file of the service reference even though I don't have it defined in my data class.
I know what the ExtensionDataObject is for, but do not want to use it.
I don't know why it's showing up... Can somebody tell me how to not include it in my service reference? Additionally, there is an OptionalFieldAttribute which is declared in my service reference which again is not part of my data class. How can I remove this as well?
Here is the generated service reference declaration on my client:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="User", Namespace="http://www.Ryder.com/SOA/DataContracts/2014/02/17")]
[System.SerializableAttribute()]
public partial class User : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
[System.NonSerializedAttribute()]
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string PasswordField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Ryder.ShopProcessService.Outbound.ShopProcessService.Permissions PermissionsField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private string UserIDField;
[System.Runtime.Serialization.OptionalFieldAttribute()]
private Ryder.ShopProcessService.Outbound.ShopProcessService.UserTypeEnum UserTypeField;
[global::System.ComponentModel.BrowsableAttribute(false)]
public System.Runtime.Serialization.ExtensionDataObject ExtensionData {
get {
return this.extensionDataField;
}
set {
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string Password {
get {
return this.PasswordField;
}
set {
if ((object.ReferenceEquals(this.PasswordField, value) != true)) {
this.PasswordField = value;
this.RaisePropertyChanged("Password");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Ryder.ShopProcessService.Outbound.ShopProcessService.Permissions Permissions {
get {
return this.PermissionsField;
}
set {
if ((object.ReferenceEquals(this.PermissionsField, value) != true)) {
this.PermissionsField = value;
this.RaisePropertyChanged("Permissions");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public string UserID {
get {
return this.UserIDField;
}
set {
if ((object.ReferenceEquals(this.UserIDField, value) != true)) {
this.UserIDField = value;
this.RaisePropertyChanged("UserID");
}
}
}
[System.Runtime.Serialization.DataMemberAttribute()]
public Ryder.ShopProcessService.Outbound.ShopProcessService.UserTypeEnum UserType {
get {
return this.UserTypeField;
}
set {
if ((this.UserTypeField.Equals(value) != true)) {
this.UserTypeField = value;
this.RaisePropertyChanged("UserType");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
Here is the corresponding class declaration in my service project: Note that I just changed the namespace to "abc" for privacy...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.ServiceModel;
namespace abc.Enterprise.DataTransferObjects
{
[Serializable, DataContract(Name = "User", Namespace = "http://www.abc.com/SOA/DataContracts/2014/02/17")]
public class User
{
private UserTypeEnum userType;
private string userID;
private string password;
private Permissions permissions;
public User()
{
}
[DataMember(Name = "UserType")]
public UserTypeEnum UserType
{
get
{
return userType;
}
set
{
userType = value;
}
}
[DataMember(Name = "UserID")]
public string UserID
{
get
{
return userID;
}
set
{
userID = value;
}
}
[DataMember(Name = "Password")]
public string Password
{
get
{
return password;
}
set
{
password = value;
}
}
[DataMember(Name = "Permissions")]
public Permissions Permissions
{
get
{
return permissions;
}
set
{
permissions = value;
}
}
}
}

Display right datamember in the datagridview by using Bindinglist

Goal:
Display Encapsulate field from Player
Problem:
Want to display datamember_id, _name and _bust in class mainform only by using bindingList
Was it suppose to use syntax [] above the encapsulate field?
Class MainForm
dataGridViewPlayers.AutoGenerateColumns=true;
dataGridViewPlayers.AutoSizeColumnsMode=DataGridViewAutoSizeColumnsMode.Fill;
bindingSourcePlayers.Clear();
bindingSourcePlayers.DataSource = _myGameManager.Players;
Class GameManager:
public BindingList<Player> Players
{
get
{
for (int i = 0; i < _myPlayerGUI_list.Count; i++)
{
_player.Add(new Player(_myPlayerGUI_list[i].Player));
}
return _player;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CardGameClassLibrary;
namespace CardGameLib
{
public class Player
{
private int _id;
private string _name;
private Hand _myHand;
private int _win;
private int _lost;
private bool _madeMove = false;
private bool _bust = false;
public int Id
{
get { return _id; }
set { _id = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public Hand MyHand
{
get { return _myHand; }
set { _myHand = value; }
}
public int Win
{
get { return _win; }
set { _win = value; }
}
public int Lost
{
get { return _lost; }
set { _lost = value; }
}
public bool MadeMove
{
get { return _madeMove; }
set { _madeMove = value; }
}
public bool Bust
{
get { return _bust; }
set { _bust = value; }
}
public Player(int pId)
{
_id = pId;
_myHand = new Hand();
}
public Player(Player pPlayer)
{
_id = pPlayer.Id;
//_name = pPlayer.Name;
_name = "adsf";
}
public Player()
{
}
}
}
You can use Browsable() attribute to prevent specific properties from being shown in the DataGridView when usin BindingList.
Example: if you want to hide MadeMove:
[Browsable(false)]
public bool MadeMove
{
get { return _madeMove; }
set { _madeMove = value; }
}

Categories