项目练习
作者:
本次任务完成时间:
开发工具与关键技术:
一、完成模块功能:功能实现
双击一条数据绑定在修改页面对数据进行修改:
- 相关业务表和关系
三、经典代码
服务器代码:
public DataSet UserControl_LoadedSelectManpowerAnalysis()
{
SqlParameter[] SQLCMDpas =
{
new SqlParameter("@Type", SqlDbType.Char),
};
SQLCMDpas[0].Value = "UserControl_LoadedSelectManpowerAnalysis";
DataTable myDataTable = myDALMethod.QueryDataTable("Frm_ManpowerAnalysis",SQLCMDpas);
DataSet myDataSet = new DataSet();
myDataSet.Tables.Add(myDataTable);
return myDataSet;
}
客户端代码:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
#region 绑定下拉框查询 11
#region 绑定性别
DataTable dtgender = myClient.InsertManpowerAnalysis_Loaded_SelectSex().Tables[0];
cbo_gender.ItemsSource = dtgender.DefaultView;
cbo_gender.DisplayMemberPath = "Sex_name";
cbo_gender.SelectedValuePath = "Sex_id";
#endregion
#region 绑定籍贯
DataTable dtNativePlace = myClient.InsertManpowerAnalysis_Loaded_SelectNativePlace().Tables[0];
cbo_NativePlace.ItemsSource = dtNativePlace.DefaultView;
cbo_NativePlace.DisplayMemberPath = "NativePlace_name";
cbo_NativePlace.SelectedValuePath = "NativePlace_id";
#endregion
#region 绑定工种
DataTable dtCraft = myClient.InsertManpowerAnalysis_Loaded_SelectCraft().Tables[0];
cbo_JobType.ItemsSource = dtCraft.DefaultView;
cbo_JobType.DisplayMemberPath = "Craft_name";
cbo_JobType.SelectedValuePath = "Craft_id";
#endregion
#region 绑定民族
DataTable dtNation = myClient.InsertManpowerAnalysis_Loaded_SelectNation().Tables[0];
cbo_Nation.ItemsSource = dtNation.DefaultView;
cbo_Nation.DisplayMemberPath = "Nation_name";
cbo_Nation.SelectedValuePath = "Nation_id";
#endregion
#endregion
#region 跨页面传输数据
txt_CardNumber.Text = DGVR.Row["CardNumber"].ToString().Trim();
txt_WorkNuber.Text = DGVR.Row["JobNumber"].ToString().Trim();
cbo_Department.SelectedValue = Convert.ToInt32(DGVR.Row["DepartmentID"]);
dtp_BornDate.Text = (DGVR.Row["BornDate"]).ToString();
cbo_Position.SelectedValue = Convert.ToInt32(DGVR.Row["PositionID"]);
cbo_gender.SelectedValue = Convert.ToInt32(DGVR.Row["as_Sex_ID"]);
cbo_Rank.SelectedValue = Convert.ToInt32(DGVR.Row["rankID"]);
cbo_WageType.SelectedValue = Convert.ToInt32(DGVR.Row["as_PaidType_ID"]);
dtp_Employment.Text = (DGVR.Row["HireDate"]).ToString().Trim();
txt_UserDate1.Text = DGVR.Row["TryDate"].ToString().Trim();
if (DGVR.Row["NomustCard"].ToString() == "1")
{
chk_MustCard.IsChecked = true;
}
cbo_EducationBackground.SelectedValue = Convert.ToInt32(DGVR.Row["as_EducationBackground_ID"]);
cbo_MaritalState.SelectedValue = Convert.ToInt32(DGVR.Row["as_Marriage_ID"]);
cbo_NativePlace.SelectedValue = Convert.ToInt32(DGVR.Row["as_NativePlace_ID"]);
cbo_Nation.SelectedValue = Convert.ToInt32(DGVR.Row["as_Nation_ID"]);
cbo_JobType.SelectedValue = Convert.ToInt32(DGVR.Row["as_Craft_ID"]);
txt_FamilyAdress.Text = DGVR.Row["Adress"].ToString().Trim();
txt_Remark.Text = DGVR.Row["Remark"].ToString().Trim();
txt_Load.Text = DGVR.Row["Picture"].ToString().Trim();
#region 显示图片
strOldLuJing = (DGVR.Row["Picture"]).ToString();
myPictureByte = myClient.UserControl_Loaded_SelectPhoro(strOldLuJing);
if (myPictureByte != null)
{
try
{
BitmapImage bi = new BitmapImage();
bi.BeginInit();
//增加这一行(指定位图像如何利用内存缓存=在加载时将整个图像缓存到内存中。对图像数据的所有请求内存存储区进行填充。)
bi.CacheOption = BitmapCacheOption.OnLoad;
bi.UriSource = new Uri(myPictureByte);
bi.EndInit();
//获取内存图片
img_photo.Source = bi;
}
catch (Exception)
{
img_photo.Source = null;
}
}
#endregion
#endregion
#region 加载页面数据
int StaffID = Convert.ToInt32(DGVR.Row["StaffID"]);
if (StaffID > 0)
{
//调职记录
DataTable dt = myClient.UserControl_Loaded_SelectTransferRecord().Tables[0];
dgTranser.ItemsSource = dt.DefaultView;
//家庭关系
DataTable dtFamily = myClient.UserControl_Loaded_SelectManpowerFamilyRelation().Tables[0];
dgAccount.ItemsSource = dtFamily.DefaultView;
//学习经历
DataTable dtStudy = myClient.UserControl_Loaded_SelectManpowerStudyExperience().Tables[0];
dgStudy.ItemsSource = dtStudy.DefaultView;
else
{
MessageBox.Show("暂时还没有记录呢!");
}
#endregion
}