public List <Chain.Model.Staff> DataTableToList(DataTable dt) { List <Chain.Model.Staff> modelList = new List <Chain.Model.Staff>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { for (int i = 0; i < rowsCount; i++) { Chain.Model.Staff model = new Chain.Model.Staff(); if (dt.Rows[i]["StaffID"] != null && dt.Rows[i]["StaffID"].ToString() != "") { model.StaffID = int.Parse(dt.Rows[i]["StaffID"].ToString()); } if (dt.Rows[i]["StaffNumber"] != null && dt.Rows[i]["StaffNumber"].ToString() != "") { model.StaffNumber = dt.Rows[i]["StaffNumber"].ToString(); } if (dt.Rows[i]["StaffName"] != null && dt.Rows[i]["StaffName"].ToString() != "") { model.StaffName = dt.Rows[i]["StaffName"].ToString(); } if (dt.Rows[i]["StaffSex"] != null && dt.Rows[i]["StaffSex"].ToString() != "") { if (dt.Rows[i]["StaffSex"].ToString() == "1" || dt.Rows[i]["StaffSex"].ToString().ToLower() == "true") { model.StaffSex = true; } else { model.StaffSex = false; } } if (dt.Rows[i]["StaffMobile"] != null && dt.Rows[i]["StaffMobile"].ToString() != "") { model.StaffMobile = dt.Rows[i]["StaffMobile"].ToString(); } if (dt.Rows[i]["StaffAddress"] != null && dt.Rows[i]["StaffAddress"].ToString() != "") { model.StaffAddress = dt.Rows[i]["StaffAddress"].ToString(); } if (dt.Rows[i]["StaffClassID"] != null && dt.Rows[i]["StaffClassID"].ToString() != "") { model.StaffClassID = int.Parse(dt.Rows[i]["StaffClassID"].ToString()); } if (dt.Rows[i]["StaffRemark"] != null && dt.Rows[i]["StaffRemark"].ToString() != "") { model.StaffRemark = dt.Rows[i]["StaffRemark"].ToString(); } modelList.Add(model); } } return(modelList); }
public int Update(Chain.Model.Staff model) { int result; if (this.dal.Exists(model.StaffID, model.StaffNumber)) { result = -1; } else { result = this.dal.Update(model); } return(result); }