private void InsertForm() { int RiskID = Convert.ToInt32(ViewState["RiskID"]); ControlingWorks p = new ControlingWorks() { ControlTitle = txtControl.Text, RiskID = RiskID, CodeID = Convert.ToInt32(txtCode.Text), IsAcceptedByAdmin = true }; db.ControlingWorks.AddObject(p); db.SaveChanges(); }
private void InsertForm() { int RiskID = Convert.ToInt32(ViewState["RiskID"]); //ControlingWorks p = new ControlingWorks() //{ // ControlTitle = txtControl.Text, // RiskID = RiskID, // CodeID = Convert.ToInt32(txtCode.Text), // IsAcceptedByAdmin = true //}; //DataContext.Context.ControlingWorks.AddObject(p); //DataContext.Context.SaveChanges(); int a = 0; if (TextBox1.Text.Length > 0) { a = a + 1; } if (TextBox2.Text.Length > 0) { a = a + 1; } if (TextBox3.Text.Length > 0) { a = a + 1; } if (TextBox4.Text.Length > 0) { a = a + 1; } if (TextBox5.Text.Length > 0) { a = a + 1; } if (TextBox6.Text.Length > 0) { a = a + 1; } if (TextBox7.Text.Length > 0) { a = a + 1; } if (TextBox8.Text.Length > 0) { a = a + 1; } if (TextBox9.Text.Length > 0) { a = a + 1; } if (TextBox10.Text.Length > 0) { a = a + 1; } if (TextBox11.Text.Length > 0) { a = a + 1; } if (TextBox12.Text.Length > 0) { a = a + 1; } if (TextBox13.Text.Length > 0) { a = a + 1; } if (TextBox14.Text.Length > 0) { a = a + 1; } if (TextBox15.Text.Length > 0) { a = a + 1; } if (TextBox16.Text.Length > 0) { a = a + 1; } if (TextBox17.Text.Length > 0) { a = a + 1; } if (TextBox18.Text.Length > 0) { a = a + 1; } if (TextBox19.Text.Length > 0) { a = a + 1; } if (TextBox20.Text.Length > 0) { a = a + 1; } if (a > 0) { for (int i = 1; i <= a; i++) { TextBox risktitle = (TextBox)vwEdit.FindControl("TextBox" + i.ToString()); string aa = risktitle.Text; ControlingWorks p = new ControlingWorks() { ControlTitle = aa, RiskID = RiskID, CodeID = i, IsAcceptedByAdmin = true }; DataContext.Context.ControlingWorks.AddObject(p); DataContext.Context.SaveChanges(); } } int newriskid = RiskID + 1; Response.Redirect("~/Admin/WebFormcontrol.aspx?ID=" + newriskid.ToString()); }