/// <summary> /// 会员 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnSave(object sender, MouseEventArgs e) { string error = string.Empty; if (!this.IsValid(ref error)) { MessageBox.Show(error, "注册会员"); return; } Member member = new Member(); member.ShopId = this.txtShopId.Text.Trim(); member.Password = MD5Util.GetMd5String(this.txtPassword.Text.Trim()); member.CreateDate = this.txtCreateDate.Text.Trim(); member.Level = this.txtLevel.Text.Trim(); member.Status = this.txtStatus.Text.Trim(); member.Number = this.txtNumber.Text.Trim(); if (rbSexTypeMan.Checked) { member.SexType = SexType.Man; } else { member.SexType = SexType.Women; } member.Name = this.txtName.Text.Trim(); member.Email = this.txtEmail.Text.Trim(); member.BirthDate = new DateTime(int.Parse(this.txtBirthDateYear.Text), int.Parse(this.txtBirthDateMonth.Text), int.Parse(this.txtBirthDateDay.Text)); member.Occupation = this.txtOccupation.Text.Trim(); member.Phone = this.txtPhone.Text.Trim(); member.QQ = this.txtQQ.Text.Trim(); member.Adviser = this.txtAdviser.Text.Trim(); member.Province = this.txtProvince.Text.Trim(); member.City = this.txtCity.Text.Trim(); member.County = this.txtCounty.Text.Trim(); member.Address = this.txtAddress.Text.Trim(); member.Code = this.txtCode.Text.Trim(); using (SkinDbContext context = new SkinDbContext()) { context.Members.Add(member); context.SaveChanges(); } // 进入 }
private void OnDeleteProject(object sender, EventArgs e) { if (this.CurrentProject == null) { return; } using (SkinDbContext context = new SkinDbContext()) { var dbProject = context.Projects.FirstOrDefault(p => p.Id == this.CurrentProject.Id); if (dbProject != null) { context.Projects.Remove(dbProject); context.SaveChanges(); } } // 执行重新查询 this.OnSearch(this, null); }
private void OnSave(object sender, MouseEventArgs e) { if (string.IsNullOrWhiteSpace(this.txtName.Text.Trim())) { MessageBox.Show("项目名称不允许为空", "保存项目", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtName.Focus(); return; } if (string.IsNullOrWhiteSpace(this.txtSequence.Text.Trim())) { MessageBox.Show("项目系列名称不允许为空", "保存项目", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtSequence.Focus(); return; } if (string.IsNullOrWhiteSpace(this.txtCode.Text.Trim())) { MessageBox.Show("项目代码不允许为空", "保存项目", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtCode.Focus(); return; } if (string.IsNullOrWhiteSpace(this.txtBriefIntroduction.Text.Trim())) { MessageBox.Show("项目简介不允许为空", "保存项目", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.txtBriefIntroduction.Focus(); return; } if (this.pbImage.Image == null) { MessageBox.Show("项目图片不允许为空", "保存项目", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.pbImage.Focus(); return; } Project newProject = new Project(); newProject.Name = this.txtName.Text.Trim(); newProject.Sequence = this.txtSequence.Text.Trim(); newProject.Code = this.txtCode.Text.Trim(); newProject.BriefIntroduction = this.txtBriefIntroduction.Text.Trim(); newProject.ImageData = ImageHelper.ImageToBytes(this.pbImage.Image); newProject.SkinColor = this.CalcProperty("SkinColor"); newProject.WaterContent = this.CalcProperty("WaterContent"); newProject.Pore = this.CalcProperty("Pore"); newProject.Inflammation = this.CalcProperty("Inflammation"); newProject.Pigment = this.CalcProperty("Pigment"); newProject.Sensitive = this.CalcProperty("Sensitive"); newProject.SkinCare = this.CalcProperty("SkinCare"); // 今天是否化妆 if (this.cboxIsTodayMakeupYes.Checked) { newProject.IsTodayMakeup = true; } else if (this.cboxIsTodayMakeupNo.Checked) { newProject.IsTodayMakeup = false; } // 年龄 if (this.cboxLessThan20.Checked) { newProject.AgeCategory = AgeCategory.LessThan20; } else if (this.cboxBetween20And29.Checked) { newProject.AgeCategory = AgeCategory.Between20And29; } else if (this.cboxBetween30And39.Checked) { newProject.AgeCategory = AgeCategory.Between30And39; } else if (this.cboxBetween40And49.Checked) { newProject.AgeCategory = AgeCategory.Between40And49; } else if (this.cboxBetween50And59.Checked) { newProject.AgeCategory = AgeCategory.Between50And59; } else if (this.cboxGreaterThan59.Checked) { newProject.AgeCategory = AgeCategory.GreaterThan59; } if (this.cboxSexTypeMan.Checked) { newProject.SexType = SexType.Man; } else if (this.cboxSexTypeWoman.Checked) { newProject.SexType = SexType.Women; } using (SkinDbContext context = new SkinDbContext()) { context.Projects.Add(newProject); context.SaveChanges(); } // 重新查询 MainForm.Instance.SetCurrentContentPanel(this.ParentControl); ((ProjectListControl)this.ParentControl).Research(); }