private void SaveButton_Click(object sender, EventArgs e) { Item item = new Item(); string cat = CategoryComboBox.SelectedItem.ToString(); string com = CompanyComboBox.SelectedItem.ToString(); if (!String.IsNullOrEmpty(nameTextBox.Text) && !String.IsNullOrEmpty(cat) && !String.IsNullOrEmpty(com)) { item.CategoryId = categoryBll.GetCategoryByName(cat).Id; item.CompanyId = companyBll.GetCompanyByName(com).Id; item.Name = nameTextBox.Text; item.ReorderLebel = Convert.ToInt32(reorderLablelTextBox.Text); if (itemBll.AddItem(item)) { MessageBox.Show("Item created successfully..."); } else { MessageBox.Show("Item Creation failed..."); } } else { MessageBox.Show("Please fill the fields properly..."); } }
//新增数据 private void DataInsert(int testNo) { this.hfTestNoBefore.Value = testNo.ToString(); ItemBLL bllItem = new ItemBLL(); //如果这个hfMainItemID为空,则Cloze的题干尚未保存 if (String.IsNullOrEmpty(this.hfMainItemID.Value)) { RailExam.Model.Item mainItem = new RailExam.Model.Item(); mainItem.BookId = Int32.Parse(this.hfBookID.Value); mainItem.ChapterId = Int32.Parse(this.hfChapterID.Value); mainItem.OrganizationId = PrjPub.CurrentLoginUser.OrgID; mainItem.TypeId = 4; mainItem.CompleteTime = 60; mainItem.DifficultyId = 3; mainItem.Score = 4m; mainItem.Content = this.txtContent.Text; mainItem.AnswerCount = Int32.Parse(this.txtTestCount.Text); mainItem.OutDateDate = Convert.ToDateTime(this.dateOut.DateValue); mainItem.UsageId = Int32.Parse(this.dropPurpose.SelectedValue); mainItem.StatusId = Int32.Parse(this.dropStatus.SelectedValue); mainItem.CreatePerson = this.txtCreater.Text; mainItem.CreateTime = Convert.ToDateTime(this.dateCreate.DateValue); mainItem.UsedCount = 0; mainItem.Memo = this.txtMemo.Text; mainItem.HasPicture = 0; mainItem.KeyWord = this.txtKeyWord.Text; mainItem.ParentItemId = 0; try { int newID = bllItem.AddItem(mainItem); this.hfMainItemID.Value = newID.ToString(); } catch (Exception) { this.ClientScript.RegisterStartupScript(this.GetType(), "OK", "alert('错误:题干保存失败');", true); return; } } //保存选项 //如果该小题已经保存了,不执行 if (!this.hfSavedTestNo.Value.Contains(testNo.ToString())) { RailExam.Model.Item subItem = new RailExam.Model.Item(); subItem.BookId = Int32.Parse(this.hfBookID.Value); subItem.ChapterId = Int32.Parse(this.hfChapterID.Value); subItem.OrganizationId = PrjPub.CurrentLoginUser.OrgID; subItem.TypeId = 5; subItem.CompleteTime = 60; subItem.DifficultyId = 3; subItem.Score = 4m; subItem.Content = String.IsNullOrEmpty(this.txtSubContent.Text) ? this.txtContent.Text : this.txtSubContent.Text; subItem.AnswerCount = Int32.Parse(this.dropItemCount.Text); string selectAnswer = String.Empty; //存储选项 TextBox[] txts = { this.txtA, this.txtB, this.txtC, this.txtD, this.txtE, this.txtF, this.txtG, this.txtH, this.txtI, this.txtJ, this.txtK, this.txtL }; for (int i = 0; i < 12; i++) { if (!String.IsNullOrEmpty(txts[i].Text)) { selectAnswer += String.IsNullOrEmpty(selectAnswer) ? txts[i].Text : "|" + txts[i].Text; } else { break; } } subItem.SelectAnswer = selectAnswer; //存储答案 RadioButton[] radioes = { this.radioA, this.radioB, this.radioC, this.radioD, this.radioE, this.radioF, this.radioG, this.radioH, this.radioI, this.radioJ, this.radioK, this.radioL }; for (int i = 0; i < 12; i++) { if (radioes[i].Checked) { subItem.StandardAnswer = Convert.ToString(i); break; } } subItem.OutDateDate = Convert.ToDateTime(this.dateOut.DateValue); subItem.UsageId = Int32.Parse(this.dropPurpose.SelectedValue); subItem.StatusId = Int32.Parse(this.dropStatus.SelectedValue); subItem.CreatePerson = this.txtCreater.Text; subItem.CreateTime = Convert.ToDateTime(this.dateCreate.DateValue); subItem.UsedCount = 0; subItem.Memo = this.txtMemo.Text; subItem.HasPicture = 0; subItem.KeyWord = this.txtKeyWord.Text; subItem.ParentItemId = Int32.Parse(this.hfMainItemID.Value); subItem.ItemIndex = testNo; try { bllItem.AddItem(subItem); this.hfSavedTestNo.Value = String.IsNullOrEmpty(this.hfSavedTestNo.Value) ? subItem.ItemIndex.ToString() : this.hfSavedTestNo.Value + "," + subItem.ItemIndex.ToString(); this.ClientScript.RegisterStartupScript(this.GetType(), "OK", "alert('第" + testNo + "小题已保存');", true); ItemsClear(); } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "OK", "alert('错误:选项保存失败. " + ex.Message + "');", true); } } }