protected void gvbind() { conn.Open(); SqlCommand cmd = new SqlCommand("Select ID, FactObject, WorkType, UnitName, CostName, Labor, Materials, Mechanisms from Fact where FactID=" + planID, conn); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); conn.Close(); if (ds.Tables[0].Rows.Count > 0) { GridView1.DataSource = ds; GridView1.DataBind(); } else { // (Table1.Rows.Count > 1) { var db = new DBClassesDataContext(); var query = from plan in db.Plans where plan.PlanID == planID select plan; Plan[] plans = query.ToArray(); List<Fact> facts = new List<Fact>(); for (int i = 0; i < plans.Length; i++) { Fact f = new Fact { FactID = planID, CostName = plans[i].CostName, FactObject = plans[i].Object, Labor = plans[i].Labor, Materials = plans[i].Materials, Mechanisms = plans[i].Mechanisms, UnitName = plans[i].UnitName, WorkType = plans[i].WorkType, Status = 1 }; facts.Add(f); } db.Facts.InsertAllOnSubmit<Fact>(facts); try { db.SubmitChanges(); } catch (Exception ex) { System.Diagnostics.Debug.Print(ex.StackTrace); } conn.Open(); cmd = new SqlCommand("Select ID, FactObject, WorkType, UnitName, CostName, Labor, Materials, Mechanisms from Fact where FactID=" + planID, conn); da = new SqlDataAdapter(cmd); ds = new DataSet(); da.Fill(ds); conn.Close(); if (ds.Tables[0].Rows.Count > 0) { GridView1.DataSource = ds; GridView1.DataBind(); } else { ds.Tables[0].Rows.Add(ds.Tables[0].NewRow()); GridView1.DataSource = ds; GridView1.DataBind(); int columncount = GridView1.Rows[0].Cells.Count; GridView1.Rows[0].Cells.Clear(); GridView1.Rows[0].Cells.Add(new TableCell()); GridView1.Rows[0].Cells[0].ColumnSpan = columncount; GridView1.Rows[0].Cells[0].Text = "Ошибка"; } } } }
private void attach_Facts(Fact entity) { this.SendPropertyChanging(); entity.Plan = this; }
private void detach_Facts(Fact entity) { this.SendPropertyChanging(); entity.Plan = null; }
partial void DeleteFact(Fact instance);
partial void UpdateFact(Fact instance);
partial void InsertFact(Fact instance);
private void buildPlanTable() { for (int i = 1; i < Table1.Rows.Count; i++) { Table1.Rows.RemoveAt(i); } var db = new DBClassesDataContext(); var query = from plan in db.Plans where plan.PlanID == int.Parse(DropDownList1.SelectedValue) select plan; //query.Cast<Plan>(); Plan[] results = null; try { results = query.ToArray<Plan>(); Table1.Caption = results[0].Name; if (results[0].Status < 3 || results[0].Status==4) { Table1.Caption += ", " + "Не одобрен\n\n"; approve.Visible = true; reject.Visible = true; } else { Table1.Caption += ", " + "Одобрен\n\n"; approve.Visible = false; reject.Visible = false; } bool gotfacts = false; foreach (Plan item in results) { var fact_query = from fact in db.Facts where fact.ExtPlanID == item.ID select fact; Fact facts; try { facts = fact_query.First<Fact>(); gotfacts = true; } catch (Exception ex) { facts = new Fact { Labor = "er", Materials = "er", Mechanisms = "er" }; } TableRow tr = new TableRow(); List<TableCell> cells = new List<TableCell>(); TableCell c = new TableCell(); c.Text = item.ID + ""; c.BorderStyle = BorderStyle.Solid; c.BorderWidth = 1; c.BorderColor = System.Drawing.Color.Black; c.Visible = false; cells.Add(c); c = new TableCell(); c.Text = item.Object; c.BorderStyle = BorderStyle.Solid; c.BorderWidth = 1; c.BorderColor = System.Drawing.Color.Black; cells.Add(c); c = new TableCell(); c.Text = item.WorkType; c.BorderStyle = BorderStyle.Solid; c.BorderWidth = 1; c.BorderColor = System.Drawing.Color.Black; cells.Add(c); c = new TableCell(); c.Text = item.CostName; c.BorderStyle = BorderStyle.Solid; c.BorderWidth = 1; c.BorderColor = System.Drawing.Color.Black; cells.Add(c); c = new TableCell(); c.Text = item.UnitName; c.BorderStyle = BorderStyle.Solid; c.BorderWidth = 1; c.BorderColor = System.Drawing.Color.Black; cells.Add(c); c = new TableCell(); c.Text = item.Labor; c.BorderStyle = BorderStyle.Solid; c.BorderWidth = 1; c.BorderColor = System.Drawing.Color.Black; cells.Add(c); c = new TableCell(); c.Text = facts.Labor; c.BorderStyle = BorderStyle.Solid; c.BorderWidth = 1; c.BorderColor = System.Drawing.Color.Black; c.BackColor = System.Drawing.Color.PowderBlue; cells.Add(c); c = new TableCell(); c.Text = item.Materials; c.BorderStyle = BorderStyle.Solid; c.BorderWidth = 1; c.BorderColor = System.Drawing.Color.Black; cells.Add(c); c = new TableCell(); c.Text = facts.Materials; c.BackColor = System.Drawing.Color.PowderBlue; c.BorderStyle = BorderStyle.Solid; c.BorderWidth = 1; c.BorderColor = System.Drawing.Color.Black; cells.Add(c); c = new TableCell(); c.Text = item.Mechanisms; c.BorderStyle = BorderStyle.Solid; c.BorderWidth = 1; c.BorderColor = System.Drawing.Color.Black; cells.Add(c); c = new TableCell(); c.Text = facts.Mechanisms; c.BackColor = System.Drawing.Color.PowderBlue; c.BorderStyle = BorderStyle.Solid; c.BorderWidth = 1; c.BorderColor = System.Drawing.Color.Black; cells.Add(c); c = new TableCell(); c.Text = item.Status + ""; c.BorderStyle = BorderStyle.Solid; c.BorderWidth = 1; c.BorderColor = System.Drawing.Color.Black; c.Visible = false; //c.Enabled = true; cells.Add(c); foreach (TableCell cell in cells) { tr.Cells.Add(cell); } Table1.Rows.Add(tr); planID = int.Parse(DropDownList1.SelectedValue); } if (!gotfacts) { foreach (TableRow tr in Table1.Rows) { tr.Cells[6].Visible = false; tr.Cells[8].Visible = false; tr.Cells[10].Visible = false; } } else { foreach (TableRow tr in Table1.Rows) { tr.Cells[6].Visible = true; tr.Cells[8].Visible = true; tr.Cells[10].Visible = true; } } } catch (FormatException fe) { Table1.Visible = false; return; } }
protected void sendFact_Click(object sender, EventArgs e) { int tmpID; List<Fact> facts = new List<Fact>(); foreach (TableRow row in Table.Rows) { if (row.Cells[0].Text == "№ ") continue; try { tmpID = int.Parse(row.Cells[0].Text); TextBox lab = (TextBox)row.Cells[6].Controls[0]; TextBox mat = (TextBox)row.Cells[8].Controls[0]; TextBox mech = (TextBox)row.Cells[10].Controls[0]; Fact tmp = new Fact { FactObject = row.Cells[1].Text, WorkType = row.Cells[2].Text, UnitName = row.Cells[3].Text, CostName = row.Cells[4].Text, Labor = lab.Text, Materials = mat.Text, Mechanisms = mech.Text, ExtPlanID = tmpID, FactID = planID }; facts.Add(tmp); } catch (Exception ex) { System.Diagnostics.Debug.Print(ex.StackTrace); } } try { var db = new DBClassesDataContext(); var query = from fact in db.Facts where fact.FactID == planID select fact; Fact[] factsToRemove = query.ToArray(); db.Facts.DeleteAllOnSubmit(factsToRemove); db.SubmitChanges(); db.Facts.InsertAllOnSubmit(facts); db.SubmitChanges(); String updatePlan = "UPDATE [Plan] SET Status=5 WHERE PlanID=" + planID; conn.Open(); SqlCommand cmd = new SqlCommand(updatePlan, conn); cmd.ExecuteNonQuery(); conn.Close(); Alert.Show("Фактические значения успешно отправлены!"); Response.Redirect("NewPlan.aspx"); } catch (Exception ex) { System.Diagnostics.Debug.Print(ex.StackTrace); } }