public List<Maticsoft.Model.Ms.EntryForm> DataTableToList(DataTable dt) { List<Maticsoft.Model.Ms.EntryForm> list = new List<Maticsoft.Model.Ms.EntryForm>(); int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { Maticsoft.Model.Ms.EntryForm item = new Maticsoft.Model.Ms.EntryForm(); if ((dt.Rows[i]["Id"] != null) && (dt.Rows[i]["Id"].ToString() != "")) { item.Id = int.Parse(dt.Rows[i]["Id"].ToString()); } if ((dt.Rows[i]["UserName"] != null) && (dt.Rows[i]["UserName"].ToString() != "")) { item.UserName = dt.Rows[i]["UserName"].ToString(); } if ((dt.Rows[i]["Age"] != null) && (dt.Rows[i]["Age"].ToString() != "")) { item.Age = new int?(int.Parse(dt.Rows[i]["Age"].ToString())); } if ((dt.Rows[i]["Email"] != null) && (dt.Rows[i]["Email"].ToString() != "")) { item.Email = dt.Rows[i]["Email"].ToString(); } if ((dt.Rows[i]["TelPhone"] != null) && (dt.Rows[i]["TelPhone"].ToString() != "")) { item.TelPhone = dt.Rows[i]["TelPhone"].ToString(); } if ((dt.Rows[i]["Phone"] != null) && (dt.Rows[i]["Phone"].ToString() != "")) { item.Phone = dt.Rows[i]["Phone"].ToString(); } if ((dt.Rows[i]["QQ"] != null) && (dt.Rows[i]["QQ"].ToString() != "")) { item.QQ = dt.Rows[i]["QQ"].ToString(); } if ((dt.Rows[i]["MSN"] != null) && (dt.Rows[i]["MSN"].ToString() != "")) { item.MSN = dt.Rows[i]["MSN"].ToString(); } if ((dt.Rows[i]["HouseAddress"] != null) && (dt.Rows[i]["HouseAddress"].ToString() != "")) { item.HouseAddress = dt.Rows[i]["HouseAddress"].ToString(); } if ((dt.Rows[i]["CompanyAddress"] != null) && (dt.Rows[i]["CompanyAddress"].ToString() != "")) { item.CompanyAddress = dt.Rows[i]["CompanyAddress"].ToString(); } if ((dt.Rows[i]["RegionId"] != null) && (dt.Rows[i]["RegionId"].ToString() != "")) { item.RegionId = new int?(int.Parse(dt.Rows[i]["RegionId"].ToString())); } if ((dt.Rows[i]["Sex"] != null) && (dt.Rows[i]["Sex"].ToString() != "")) { item.Sex = dt.Rows[i]["Sex"].ToString(); } if ((dt.Rows[i]["Description"] != null) && (dt.Rows[i]["Description"].ToString() != "")) { item.Description = dt.Rows[i]["Description"].ToString(); } if ((dt.Rows[i]["remark"] != null) && (dt.Rows[i]["remark"].ToString() != "")) { item.Remark = dt.Rows[i]["remark"].ToString(); } if ((dt.Rows[i]["State"] != null) && (dt.Rows[i]["State"].ToString() != "")) { item.State = new int?(int.Parse(dt.Rows[i]["State"].ToString())); } list.Add(item); } } return list; }
protected void btnSave_Click(object sender, EventArgs e) { string str = this.txtUserName.Text.Trim(); string str2 = this.txtRemark.Text.Trim(); if (string.IsNullOrWhiteSpace(str)) { MessageBox.ShowFailTip(this, MsEntryForm.ErrorNameNotNull); } else if (str2.Length > 300) { MessageBox.ShowFailTip(this, MsEntryForm.ErrorRemarkoverlength); } else { Maticsoft.Model.Ms.EntryForm model = new Maticsoft.Model.Ms.EntryForm { UserName = this.txtUserName.Text.Trim(), Age = new int?(int.Parse(this.dropAge.SelectedValue)), Email = this.txtEmail.Text.Trim(), TelPhone = this.txtTelPhone.Text.Trim(), Phone = this.txtPhone.Text.Trim(), QQ = this.txtQQ.Text.Trim(), MSN = this.txtMSN.Text.Trim(), HouseAddress = this.txtHouseAddress.Text.Trim(), CompanyAddress = this.txtCompanyAddress.Text.Trim(), RegionId = new int?(Convert.ToInt32(this.dropProvince.Area_iID)), Sex = this.dropSex.SelectedValue, Description = this.txtDescription.Text.Trim(), Remark = str2, State = new int?(int.Parse(this.dropState.SelectedValue)) }; Maticsoft.BLL.Ms.EntryForm form2 = new Maticsoft.BLL.Ms.EntryForm(); if (form2.Add(model) > 0) { this.btnCancle.Enabled = false; this.btnSave.Enabled = false; MessageBox.ShowSuccessTip(this, Site.TooltipSaveOK, "list.aspx"); } } }