c# find number of occurance of substring in string
Regex.Matches(inputstring, substring).Count
Achievement provides the only real pleasure in life
Regex.Matches(inputstring, substring).Count
Posted by
Unknown
at
6:32 pm
0
comments
add the following code into the constructor of the method Configuration:
if (System.Diagnostics.Debugger.IsAttached == false)
{
System.Diagnostics.Debugger.Launch();
}
Posted by
SF
at
11:56 pm
0
comments
when setup datetime display format in javascript it displays datetime value incorrectly, the following are what I have done to ensure my datetime value is displayed correctly
in my javascript I have
@Html.TextBoxFor(model => model.PaidDateTimeLocal, new { Value = Model.PaidDateTimeLocal.ToString("yyyy/MM/dd HH:mm"), @class = "dtpicker" })
Posted by
SF
at
8:28 am
0
comments
In my MVC 5 Code First project I decided to put my domain tables under the out of box ApplicationDbContext
Posted by
SF
at
9:49 pm
0
comments
in my case I have my own dbcontext called MyContext.
1. in the child class MyModel add:
public ApplicationUser User { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity().HasRequired(MyModel => MyModel.User);
base.OnModelCreating(modelBuilder);
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity().HasRequired(MyModel => MyModel.User);
base.OnModelCreating(modelBuilder);
}
CONSTRAINT [FK_dbo.UserProfiles_dbo.AspNetUsers_User_Id] FOREIGN KEY ([User_Id]) REFERENCES [dbo].[AspNetUsers] ([Id])
Posted by
SF
at
6:30 pm
0
comments
Visual Studio 2015 Community MVC project could not open .cshtml views after installed github update.
Lucky found the solution here
Step 1: remove everything under this folder
C:\Users\abc\AppData\Local\Microsoft\VisualStudio\14.0\ComponentModelCache
Step 2: reopen VS
Posted by
SF
at
10:14 pm
0
comments
TSQL: find out which table a constraint belongs to
SELECT OBJECT_NAME(o.parent_object_id) FROM sys.objects o WHERE o.name = 'ConstraintABC' AND o.parent_object_id <> 0
Posted by
SF
at
3:48 pm
0
comments
this solution worked for me (https://productforums.google.com/d/msg/chrome/ZE4c98nklAw/47xvIIz8zN8J) 1. run cmd as administrator 2. type in "netsh winsock reset" 3. restart pc
Posted by
SF
at
9:04 am
0
comments
//Set up a viewmodel MyViewModel to contain the following
[DisplayName("Available Products")]
public IList AvailableProducts { get; set; }
public IList SelectedProducts { get; set; }
public PostedProducts PostedProducts { get; set; }
//The definition of ProductDropdownItemViewModel and PostedProducts are:
public class PostedProducts
{
public int[] ProductIds { get; set; }
}
public class ProductDropdownItemViewModel
{
public int Id { get; set; }
public string Name { get; set; }
}
//In your controller method populate the above viewmodel
e.g.
MyViewModel.AvailableProducts = db.Products
.Select(p => new ProductDropdownItemViewModel
{
Id = p.Id,
Name = p.Name
}).ToList();
//In your view display the checkbox list this way
e.g. the postback method name is Edit
@model MyViewModel
@using (Html.BeginForm("Edit", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.CheckBoxListFor(x => x.PostedProducts.ProductIds,
x => x.AvailableProducts,
x => x.Id,
x => x.Name,
x => x.SelectedProducts,
MvcCheckBoxList.Model.Position.Vertical)
}
//In your postback method Edit use the following code to retrieve your selected items
public ActionResult Edit(PostedProducts postedProducts)
{
foreach (var id in postedProducts.ProductIds)
{
//do whatever you like with the selected product id
}
}
Posted by
SF
at
10:50 pm
0
comments
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[table1]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[table1]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](150) NOT NULL, CONSTRAINT [PK_abc] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] END go
Posted by
SF
at
6:53 pm
0
comments
public void ReadExcel(HttpPostedFileBase file, string currentUserName)
{
DataTable tbContainer = new DataTable();
string strConn = XlsConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + file.FileName +";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'";
string sheetName = "sheet1";
FileInfo fileInfo = new FileInfo(file.FileName);
OleDbConnection cnnxls = new OleDbConnection(strConn);
OleDbDataAdapter oda = new OleDbDataAdapter(string.Format("select * from [{0}$]", sheetName), cnnxls);
DataSet ds = new DataSet();
oda.Fill(tbContainer);
var newParcelTubeExport = new ParcelTubeExport();
//your code to utilize the data
}
Posted by
SF
at
6:39 pm
0
comments
function round(value, decimals) {
return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
}
Posted by
SF
at
8:33 pm
0
comments
$(function () {
$('.decimal10n2').keyup(function () {
if (!$(this).val().match(/./gi) || !$(this).val().match(/[0-9]+/g)) {
$(this).val("");
}
else if ($(this).val().split('.').length - 1 > 1)
{
this.value = $(this).val().slice(0, -1);
}
else if ($(this).val().indexOf('.') != -1) {
if($(this).val().split(".")[0].length > 10)
{
if (isNaN(parseFloat(this.value))) return;
this.value = $(this).val().split(".")[0].slice(0,-1);
}
else if ($(this).val().split(".")[1].length > 2) {
if (isNaN(parseFloat(this.value))) return;
this.value = parseFloat(this.value).toFixed(2);
}
}
return this;
});
});
Posted by
SF
at
8:32 pm
0
comments
$(document).ready(function () {
$(".navbar-sub-opener").click(function (evt) {
//close submenu when click away - part 2
evt.stopPropagation();
//hide all submenus
$(".navbar-sub").hide();
//only open the one that's immediate inside the clicked parent menu item
$(this).next($(".navbar-sub")).show();
});
//close submenu when click away - part 1
$('html').click(function () {
$(".navbar-sub").hide();
});
});
Posted by
SF
at
10:58 pm
0
comments
jQuery.fn.center = function () {
this.css("position", "fixed");
this.css("top", ($(window).height() / 2) - (this.outerHeight() / 2));
this.css("left", ($(window).width() / 2) - (this.outerWidth() / 2));
return this;
}
Posted by
SF
at
12:55 am
0
comments
required javascript:
$(document).ready(function () {
$(".popupformContainer").dialog({
height: 600,
width: 300,
autoOpen: false,
modal: true,
open: function (event, ui) {
$(this).load("/controllername/actionname", { "parameter": $(this).data("parametervalue") }, function (html) {
});
},
close: function (event, ui) {
event.preventDefault();
alert("closing");
},
buttons: {
text: "提交", click: function (event) {
event.preventDefault();
$.validator.unobtrusive.parse("#PopupForm");
$("#PopupForm").validate();
if ($("#PopupForm").valid()) {
$("#PopupForm").submit();
}
else {
event.preventDefault();
alert("invalid");
}
}
}
});
$(".btnOpenPopupForm").click(function () {
$(".popupformContainer").data("parameter", $(this).attr("value")).dialog("open");
});
});
in the parent view you need the button to open popup with class "btnOpenPopupForm" and an empty div with class "popupformContainer" for hosting the popup
Posted by
SF
at
3:41 am
0
comments
update student
set isOdd = 1, isEven = 0
where exammark % 2 =1
Posted by
SF
at
1:54 am
0
comments
return Redirect(Request.UrlReferrer.ToString());
Posted by
SF
at
12:14 am
0
comments
make sure the form declaration in the view has all necessary attributes, e.g.
Posted by
SF
at
5:26 pm
0
comments