public void CreateNewItem(object sender, EventArgs e) { CostSubjectCollection dataFromGrid = this.GetDataFromGrid(); CostSubjectCollection costSubjectCollection = new CostSubjectCollection(); for (int i = 0; i < dataFromGrid.Count; i++) { dataFromGrid[i].IsEdit = false; if (i != 0 && dataFromGrid[i].FirstNum != dataFromGrid[i - 1].FirstNum && dataFromGrid[i - 1].FirstNum == int.Parse(this.hidFirst.Value)) { CostSubjectInfo newItem = CostSubjectAction.GetNewItem(dataFromGrid[i - 1].FirstNum); this.dgSubject.EditItemIndex = i; costSubjectCollection.Add(newItem); } costSubjectCollection.Add(dataFromGrid[i]); if (i == dataFromGrid.Count - 1 && dataFromGrid[i].FirstNum == int.Parse(this.hidFirst.Value)) { CostSubjectInfo newItem2 = CostSubjectAction.GetNewItem(dataFromGrid[i].FirstNum); this.dgSubject.EditItemIndex = i + 1; costSubjectCollection.Add(newItem2); } } this.dgSubject.DataSource = costSubjectCollection; this.dgSubject.DataBind(); }
public static CostSubjectCollection GetCostSubjectInfos() { CostSubjectCollection subjects = new CostSubjectCollection(); string sqlString = "select * from Prj_Costsubjects where IsValid=1 and SecNum=0"; foreach (DataRow row in publicDbOpClass.DataTableQuary(sqlString).Rows) { CostSubjectInfo info = new CostSubjectInfo { SubjectID = int.Parse(row["SubjectID"].ToString()), FirstNum = int.Parse(row["FirstNum"].ToString()), SubjectName = row["SubjectName"].ToString() }; if (int.Parse(publicDbOpClass.ExecuteScalar(string.Format("select isNull(Count(*),0) from Prj_Costsubjects where firstNum={0} and secNum<>0 and IsValid=1", info.FirstNum)).ToString()) > 0) { info.IsHaveChild = true; } subjects.Add(info); DataTable table = publicDbOpClass.DataTableQuary(string.Format("select * from Prj_Costsubjects where FirstNum={0} and IsValid=1 and secnum>0 order by secNum", info.FirstNum)); for (int i = 0; i < table.Rows.Count; i++) { CostSubjectInfo info2 = new CostSubjectInfo { SubjectID = int.Parse(table.Rows[i]["SubjectID"].ToString()), FirstNum = int.Parse(table.Rows[i]["FirstNum"].ToString()), SubjectName = table.Rows[i]["SubjectName"].ToString(), SecNum = int.Parse(table.Rows[i]["SecNum"].ToString()) }; subjects.Add(info2); } table.Dispose(); } return(subjects); }
protected void btnNew_Click(object sender, EventArgs e) { CostSubjectCollection dataFromGrid = this.GetDataFromGrid(); dataFromGrid.Add(CostSubjectAction.GetFistNewItem()); this.dgSubject.EditItemIndex = dataFromGrid.Count - 1; this.dgSubject.DataSource = dataFromGrid; this.dgSubject.DataBind(); }
private CostSubjectCollection GetDataFromGrid() { CostSubjectCollection costSubjectCollection = new CostSubjectCollection(); foreach (System.Web.UI.WebControls.DataGridItem dataGridItem in this.dgSubject.Items) { CostSubjectInfo costSubjectInfo = new CostSubjectInfo(); costSubjectInfo.SubjectID = int.Parse(this.dgSubject.DataKeys[dataGridItem.ItemIndex].ToString()); costSubjectInfo.FirstNum = int.Parse(((System.Web.UI.HtmlControls.HtmlInputHidden)dataGridItem.FindControl("hidFirstNum")).Value); costSubjectInfo.SecNum = int.Parse(((System.Web.UI.HtmlControls.HtmlInputHidden)dataGridItem.FindControl("hidSecNum")).Value); costSubjectInfo.IsHaveChild = (((System.Web.UI.HtmlControls.HtmlInputHidden)dataGridItem.FindControl("hidIsHaveChild")).Value == "True"); if (((System.Web.UI.HtmlControls.HtmlInputHidden)dataGridItem.FindControl("hidIsEdit")).Value == "True") { costSubjectInfo.SubjectName = ((System.Web.UI.WebControls.TextBox)dataGridItem.FindControl("txtSubjectName")).Text; } else { costSubjectInfo.SubjectName = ((System.Web.UI.WebControls.Label)dataGridItem.FindControl("lbSubjectName")).Text; } costSubjectCollection.Add(costSubjectInfo); } return(costSubjectCollection); }