MainPage.xaml
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Horizontal">
<sdk:DataGrid Name="grid" Margin="10" AutoGenerateColumns="False">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Name" Binding="{Binding Name}" />
<sdk:DataGridTextColumn Header="Age" Binding="{Binding Age}" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<StackPanel>
<sdk:DataGrid Name="gBooks" Margin="10" AutoGenerateColumns="False" DataContext="{Binding SelectedItem, ElementName=grid}" ItemsSource="{Binding Books}">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Title" Binding="{Binding Title}" />
<sdk:DataGridTextColumn Header="Code" Binding="{Binding Code}" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<StackPanel DataContext="{Binding SelectedItem, ElementName=grid}" Orientation="Horizontal">
<TextBlock Text="{Binding Name}" />
<CheckBox IsChecked="{Binding isMale}" />
</StackPanel>
</StackPanel>
</StackPanel>
</Grid>
CodeBehind:
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
grid.ItemsSource = GridData.GetData();
}
}
public class GridData
{
public string Name { get; set; }
public int Age { get; set; }
public bool isMale { get; set; }
public IEnumerable<Book> Books { get; set; }
public class Book
{
public string Title { get; set; }
public string Code { get; set; }
};
public static ObservableCollection<GridData> GetData()
{
ObservableCollection<GridData> data = new ObservableCollection<GridData>
{
new GridData { Name = "John Doe", Age = 30, isMale = true,
Books = new List<Book> {
new Book {Title = "suits", Code = "123"},
new Book {Title = "Condors 1", Code = "113"}
}
},
new GridData { Name = "Jane Doe", Age = 32, isMale = false },
new GridData { Name = "Jason Smith", Age = 54, isMale = true },
new GridData { Name = "Kayli Jayne", Age = 25, isMale = false}
};
return data;
}
}
Saturday, July 28, 2012
Saturday, July 21, 2012
windows azure user
create login username with password = 'password'; (on master)
create user username for login username; (on database)
exec sp_addrolemember 'db_owner', 'username'
create user username for login username; (on database)
exec sp_addrolemember 'db_owner', 'username'
Saturday, July 14, 2012
Longest Increasing Sequence C#
static public int LongestIncreasingSeq(int[] s) {
int[] l = new int[s.Length]; // DP table for max length[i]
int[] p = new int[s.Length]; // DP table for predeccesor[i]
int max = int.MinValue;
l[0] = 1;
for (int i=0; i<s.Length; i++)
p[i] = -1;
for (int i = 1; i < s.Length; i++)
{
l[i] = 1;
for (int j = 0; j < i; j++)
{
if (s[j] < s[i] && l[j] + 1 > l[i])
{
l[i] = l[j] + 1;
p[i] = j;
if (l[i] > max)
max = l[i];
}
}
}
return max;
}
Linear Partition in C#
static public void partition(int[] s, int n, int k) {
Console.Write("{");
Utils.printArray(s);
Console.WriteLine("}");
int MAXN = s.Length;
int MAXK = 3;
int[,] m = new int[MAXN, MAXK]; // DP table for values.
int[,] d = new int[MAXN, MAXK]; // DP table for dividers.
int[] p = new int[MAXN]; // prefix sums array.
int cost;
p[0] = s[0];
for (int i = 1; i < n; i++) p[i] = p[i - 1] + s[i];
for (int i = 0; i < n; i++) m[i, 0] = p[i];
for (int j = 0; j < k; j++) m[0, j] = s[0];
for (int i = 1; i < n; i++)
for (int j = 1; j < k; j++)
{
m[i, j] = int.MaxValue;
for (int x = 0; x <= (i - 1); x++)
{
cost = Math.Max(m[x, j - 1], p[i] - p[x]);
if (m[i, j] > cost)
{
m[i, j] = cost;
d[i, j] = x + 1;
}
}
}
Console.Write("{");
reconstruct_particion(s, d, n, k);
Console.Write("} ");
}
private static void reconstruct_particion(int[] s, int[,] d, int n, int k)
{
if (k == 1)
{
print_books(s, 0, n);
}
else
{
reconstruct_particion(s, d, d[n - 1, k - 1], k - 1);
print_books(s, d[n - 1, k - 1], n);
}
}
private static void print_books(int[] s, int start, int end)
{
Console.Write("{");
for (int i = start; i < end; i++)
Console.Write(" {0} ", s[i]);
Console.Write("} ");
}
Subscribe to:
Posts (Atom)