001.
using
System;
002.
using
System.Collections.Generic;
003.
using
System.Collections.ObjectModel;
004.
using
System.Linq;
005.
using
System.Text;
006.
using
System.Windows;
007.
using
System.Windows.Controls;
008.
using
System.Windows.Data;
009.
using
System.Windows.Documents;
010.
using
System.Windows.Input;
011.
using
System.Windows.Media;
012.
using
System.Windows.Media.Imaging;
013.
using
System.Windows.Navigation;
014.
using
System.Windows.Shapes;
015.
using
Microsoft.Windows.Controls;
016.
using
Drewsn32Biz.DataBase;
017.
using
Microsoft.Windows.Controls.Primitives;
018.
using
System.Reflection;
019.
using
System.ComponentModel;
020.
using
System.Windows.Controls.Primitives;
021.
using
System.Data;
022.
namespace
Drewsn32Biz
023.
{
024.
/// <summary>
025.
/// Interaction logic for MainWindow.xaml
026.
/// </summary>
027.
public
partial
class
MainWindow : Window
028.
{
029.
DataBase.dbDrewsn32BizDataContext db =
new
DataBase.dbDrewsn32BizDataContext();
030.
string
[] tempdata =
new
string
[4];
031.
public
MainWindow()
032.
{
033.
InitializeComponent();
034.
IsvProductList.Drop +=
new
DragEventHandler(IsvProductList_Drop);
035.
dgvProductList.MouseMove +=
new
MouseEventHandler(dgvProductList_MouseMove);
036.
037.
}
038.
private
void
Grid_Loaded(
object
sender, RoutedEventArgs e)
039.
{
040.
var cs = from c
in
db.UserNames
041.
select
new
042.
{
043.
UserID = c.UserName1,
044.
Password = c.Password,
045.
IsNormal = c.IsNormal,
046.
HumanID = c.HID
047.
};
048.
if
(cs.Count() > 0)
049.
{
050.
dgvProductList.ItemsSource = cs.ToList();
051.
GridView gv =
new
GridView();
052.
GridViewColumn gvc =
new
GridViewColumn();
053.
gvc.Header =
"UserID"
;
054.
gvc.Width = Double.NaN;
055.
gv.Columns.Add(gvc);
056.
GridViewColumn gvc1 =
new
GridViewColumn();
057.
gvc1.Header =
"Password"
;
058.
gvc1.Width = Double.NaN;
059.
gv.Columns.Add(gvc1);
060.
GridViewColumn gvc2 =
new
GridViewColumn();
061.
gvc2.Header =
"IsNormal"
;
062.
gvc2.Width = Double.NaN;
063.
gv.Columns.Add(gvc2);
064.
GridViewColumn gvc3 =
new
GridViewColumn();
065.
gvc3.Header =
"HumanID"
;
066.
gvc3.Width = Double.NaN;
067.
gv.Columns.Add(gvc3);
068.
069.
IsvProductList.View = gv;
070.
071.
072.
073.
}
074.
else
075.
{
076.
dgvProductList.ItemsSource =
null
;
077.
}
078.
}
079.
080.
private
void
IsvProductList_Drop(
object
sender, DragEventArgs e)
081.
{
082.
tempdata = (
string
[])(e.Data.GetData(DataFormats.Text,
true
));
083.
ListViewItem lvi = (ListViewItem)IsvProductList.ItemContainerGenerator.ContainerFromItem(tempdata);
084.
IsvProductList.Items.Add(lvi);
085.
Array.Clear(tempdata, 0, tempdata.Length);
086.
}
087.
private
void
ShowLogin()
088.
{
089.
this
.Hide();
090.
Login log =
new
Login();
091.
log.Owner =
this
;
092.
log.ShowDialog();
093.
094.
if
(log.DialogResult.HasValue && log.DialogResult.Value)
095.
{
096.
this
.Show();
097.
return
;
098.
}
099.
else
100.
{
101.
this
.Close();
102.
}
103.
}
104.
private
void
dgvProductList_MouseMove(
object
sender, MouseEventArgs e)
105.
{
106.
#region Algorithum Check Row
107.
DependencyObject dep = (DependencyObject)e.OriginalSource;
108.
while
((dep !=
null
) && !(dep
is
DataGridCell) && !(dep
is
DataGridColumnHeader))
109.
{
110.
dep = VisualTreeHelper.GetParent(dep);
111.
}
112.
113.
if
(dep ==
null
)
114.
return
;
115.
if
(dep
is
DataGridCell)
116.
{
117.
118.
while
((dep !=
null
) && !(dep
is
DataGridRow))
119.
{
120.
dep = VisualTreeHelper.GetParent(dep);
121.
}
122.
if
(dep ==
null
)
123.
return
;
124.
try
125.
{
126.
int
count = 0;
127.
string
data =
""
;
128.
foreach
(var dataGridCellInfo
in
dgvProductList.SelectedCells)
129.
{
130.
PropertyInfo pi = dataGridCellInfo.Item.GetType().GetProperty(Convert.ToString(dataGridCellInfo.Column.Header));
131.
var temp = Convert.ToString(pi.GetValue(dataGridCellInfo.Item,
null
));
132.
data += temp;
133.
tempdata[count] = Convert.ToString(temp);
134.
count += +1;
135.
}
136.
textBox2.Text = data;
137.
t1.Text = tempdata[0].ToString();
138.
t2.Text = tempdata[1].ToString();
139.
t3.Text = tempdata[2].ToString();
140.
t4.Text = tempdata[3].ToString();
141.
142.
}
143.
catch
(Exception)
144.
{
145.
return
;
146.
}
147.
}
148.
#endregion
149.
if
(e.LeftButton == MouseButtonState.Pressed)
150.
{
151.
DragDropEffects dds;
152.
DataObject AnyData;
153.
AnyData =
new
DataObject();
154.
AnyData.SetData(DataFormats.Text, tempdata);
155.
dds = DragDrop.DoDragDrop(dgvProductList, AnyData, DragDropEffects.Copy);
156.
}
157.
}
158.
}
159.
}