C# winform check every 30 mins for log in session

In the Solution Explorer right-click the project and select Properties. Go to the “Settings” tab and create a “SettingInterval”. Make the type “int” for the SettingInterval.

public frmMain()
{
InitializeComponent();
timer1.Tick += Timer1_Tick;
timer1.Interval = 1000;
}
private void Timer1_Tick(object sender, EventArgs e)
{
TimeSpan ts = Expires – DateTime.Now;
if (ts.TotalSeconds < 10)
if (Warning)
{
Warning = false; // this must be before the MessageBox
btnLogIn.BackColor = Color.Orange;
MessageBox.Show(“You have 30 seconds left!”);
}

}

I have a button which will trigger the timer.

private void btnLogIn_Click(object sender, EventArgs e)
{
int NewInterval = 30; //30 min……AccessToken expired in 30 min
Properties.Settings.Default.SettingInterval = NewInterval;
Expires = DateTime.Now.AddMinutes(NewInterval);
Warning = true;
timer1.Start();

}

By simplemsexchange Posted in C#, VB.NET

The type ‘System.Data.Entity.DbContext’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘EntityFramework 2

  1. Go to Tools » NuGet Package Manager » Manage NuGet Packages For Solution.
  2. Ensure that Browse is selected and type “entityframework” into the search box. and install the entity framework

Check if its exist in package.config <package id=”EntityFramework” version=”6.2.0″ targetFramework=”net461″ /> exist

Data Access Layer

1.

da1.PNG

2. Delete Class.cs

3.

da2

4.

da3

5. select DB, table and views you want to add.

6. Add reference to this project from WEB API Service project

7. Add a Web API 2 Controller – Empty

8. Add DataAccess reference inside the controller: using DataAccess;

 

By simplemsexchange Posted in AOT

Winform – Override textbox to show sample text and clear on click

Winform watermark text on textbox:

 

public string initTextClient = “Client”;
public bool editedClient;

public SelectMatterClient()
{
InitializeComponent();

txtClient.Text = initTextClient;
txtClient.ForeColor = Color.Gray;

}

 

private void txtClient_KeyPress(object sender, KeyPressEventArgs e)
{
editedClient = !char.IsControl(e.KeyChar);
}

private void txtClient_Enter(object sender, EventArgs e)
{
if (!editedClient)
{
txtClient.Clear();
txtClient.ForeColor = Color.Black;
}
}

private void txtClient_Leave(object sender, EventArgs e)
{
if (!editedClient)
{
txtClient.Text = initTextClient;
txtClient.ForeColor = Color.Gray;
}
}Capture

WPF C# Make ListBox items have a different value than item text

In XAML :

<ListBox x:Name=”lstboxCabinet” HorizontalAlignment=”Center” Height=”156″ Margin=”58,68,530,0″ VerticalAlignment=”Top” Width=”426″
DisplayMemberPath=”Text”
ItemsSource=”{Binding}”
SelectedValuePath=”id”
/>

 

 

 

In C#

 

Define Custom Class:

public class ListBoxValueText
{
public string Value { get; set; }
public string Text { get; set; }
}

 

Populate the Listbox:

 

DataTable dataTable = ******Your Database Table which contains data*****

lstboxCabinet.Items.Clear();
List<ListBoxValueText> data = new List<ListBoxValueText>();
foreach (DataRow row in dataTable.Rows)
{
data.Add(new ListBoxValueText() { Value = row[“id”].ToString(), Text = row[“name”].ToString() });
}
lstboxCabinet.DataContext = data;

 

Callback Assigned selected value to a string:

 

string selectedCabinet = (lstboxCabinet.SelectedItem as ListBoxValueText).Value;

Angular PIPES

Transform data before display. For example, lower case to upper case, date formatting etc.

Built in pipes include lowercase, uppercase, decimal, date, percent, currency etc

To read more about angular built-in pipesTo read more about angular built-in pipesPipe URLDate https://angular.io/api/common/DatePipeDecimal https://angular.io/api/common/DecimalPipeCurrency https://angular.io/api/common/CurrencyPipePercent https://angular.io/api/common/PercentPipe

Change loading (Spinning) splash icon for VS2015 angular 2 project

By Default, when I load angular project, this what I see at the beginning when I run the application:

 

a26

 

I would like to change it something look like:

a27.PNG

 

Solution:

Add the following css code in the skyle.css file in here:

a28.PNG

 

 

/* Absolute Center Spinner */
.loading {
position: fixed;
z-index: 999;
height: 2em;
width: 2em;
overflow: show;
margin: auto;
top: 0;
left: 0;
bottom: 0;
right: 0;
}

/* Transparent Overlay */
.loading:before {
content: ”;
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0,0,0,0.3);
}

/* :not(:required) hides these rules from IE9 and below */
.loading:not(:required) {
/* hide “loading…” text */
font: 0/0 a;
color: transparent;
text-shadow: none;
background-color: transparent;
border: 0;
}

.loading:not(:required):after {
content: ”;
display: block;
font-size: 10px;
width: 1em;
height: 1em;
margin-top: -0.5em;
-webkit-animation: spinner 1500ms infinite linear;
-moz-animation: spinner 1500ms infinite linear;
-ms-animation: spinner 1500ms infinite linear;
-o-animation: spinner 1500ms infinite linear;
animation: spinner 1500ms infinite linear;
border-radius: 0.5em;
-webkit-box-shadow: rgba(0, 0, 0, 0.75) 1.5em 0 0 0, rgba(0, 0, 0, 0.75) 1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) 0 1.5em 0 0, rgba(0, 0, 0, 0.75) -1.1em 1.1em 0 0, rgba(0, 0, 0, 0.5) -1.5em 0 0 0, rgba(0, 0, 0, 0.5) -1.1em -1.1em 0 0, rgba(0, 0, 0, 0.75) 0 -1.5em 0 0, rgba(0, 0, 0, 0.75) 1.1em -1.1em 0 0;
box-shadow: rgba(0, 0, 0, 0.75) 1.5em 0 0 0, rgba(0, 0, 0, 0.75) 1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) 0 1.5em 0 0, rgba(0, 0, 0, 0.75) -1.1em 1.1em 0 0, rgba(0, 0, 0, 0.75) -1.5em 0 0 0, rgba(0, 0, 0, 0.75) -1.1em -1.1em 0 0, rgba(0, 0, 0, 0.75) 0 -1.5em 0 0, rgba(0, 0, 0, 0.75) 1.1em -1.1em 0 0;
}

/* Animation */

@-webkit-keyframes spinner {
0% {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-ms-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}

100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}

@-moz-keyframes spinner {
0% {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-ms-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}

100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}

@-o-keyframes spinner {
0% {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-ms-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}

100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}

@keyframes spinner {
0% {
-webkit-transform: rotate(0deg);
-moz-transform: rotate(0deg);
-ms-transform: rotate(0deg);
-o-transform: rotate(0deg);
transform: rotate(0deg);
}

100% {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-ms-transform: rotate(360deg);
-o-transform: rotate(360deg);
transform: rotate(360deg);
}
}

 

Change the code in index.html file with following code:

a29

 

Loading

 

Don’t forget to Delete your cookies in IE browser to see the effect of this change.

Select backlog navigation levels for your team in Visual Studio Team Service

 

  1. From your team’s backlog page, click the gear icon (gear icon) to open the common configuration team settings.
    Backlog board, open team settings
  2. Click the Backlogs tab and check the boxes of those backlog levels you want your team to manage.

    Team Services, web portal, team settings dialog, Backlogs tab

  3. To see the changes, open or refresh your team’s backlog web page.

Reff: https://www.visualstudio.com/en-us/docs/work/customize/select-backlog-navigation-levels

VS2013 An exception occurred while initializing the database

I’m doing a code first Entity database

{“An exception occurred while initializing the database. See the InnerException for details.”}

It was working fine, but I decided to delete the physical database to see it recreate it, but it just fails every time.

I get the error

Cannot attach the file ‘C:\ASP\OdeToFood\OdeToFood\App_Data\OdeToFoodDb.mdf’ as database ‘OdeToFoodDb’.”}

Its code first so I don’t understand why its not recreating the database.

 

 

So deleting the file from Visual Studio was a dumb idea.

SQL still has it registered.

Fire up MS Sql Management Tool, connect to the server in my case

(localdb)\v11.0

You will see the database, still exists, delete it, you will get an error. The file doesn’t exist. Refresh and its gone from SQL. Now run your code again and all is good.

So delete the DB from the management tool not visual studio