private void btnSave_Click(object sender, EventArgs e) { if (this.txtName.Text.Trim().IsNullOrWhiteSpace()) { MessageBox.Show("名称不能为空,请输入"); this.txtName.Focus(); return; } //if (this.txtParentSerialbum.Text == null) //{ // MessageBox.Show("上及编码不能为空"); // this.txtParentSerialbum.Focus(); // return; //} //if (FacilityType.FindAllByName(this.txtName.Text) != null) //{ // MessageBox.Show("名称已经存在"); // this.txtName.Focus(); // return; //} if (this.facilityTypeSerialnum != null) { try { // 更新 var facilityType = new FacilityType { Serialnum = this.facilityTypeSerialnum, //Serialnum = facilityType.AutoSerialnum, Name = this.txtName.Text.Trim(), ParentSerialnum = this.txtParentSerialbum.Text, //Version = Convert.ToInt32(this.txtVersion.Text), //CreateTime = this.dtCreateTime.Value, UpdateTime = DateTime.Now, //PhotoUrl = this.pbPhotoUrl.Image.ToString(), Introduce = this.txtIntroduce.Text, //Upload =Convert.ToBoolean(this.cbUpload.SelectedValue), //Upload=this.rbtUpLoad.Checked, Remark = this.txtRemark.Text.Trim(), CreateType = this.txtCreateType.Text.Trim() }; FacilityType.Update(facilityType); } catch (Exception ex) { XTrace.WriteException(ex); MessageBox.Show("更新失败"); } } else { try { // 保存 var facilityType = new FacilityType { //Serialnum = this.txtSerialnum.Text, Name = this.txtName.Text.Trim(), ParentSerialnum = this.txtParentSerialbum.Text, //Version = Convert.ToInt32(this.txtVersion.Text), //CreateTime = this.dtCreateTime.Value, UpdateTime = DateTime.Now, //PhotoUrl = this.pbPhotoUrl.Image.ToString(), Introduce = this.txtIntroduce.Text, //Upload = Convert.ToBoolean(this.cbUpload.SelectedValue), //Upload = this.rbtUpLoad.Checked, Remark = this.txtRemark.Text.Trim(), CreateType = this.txtCreateType.Text.Trim() }; FacilityType.Save(facilityType); } catch (Exception ex) { XTrace.WriteException(ex); MessageBox.Show("保存失败"); } } this.InitFacilityTypeListView(); }