Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web.UI.WebControls;
  5.  
  6. namespace dbexam
  7. {
  8.     public partial class WebForm1 : System.Web.UI.Page
  9.     {
  10.         DataClasses1DataContext dbContext;
  11.  
  12.         protected void Page_Load(object sender, EventArgs e)
  13.         {
  14.             dbContext = new DataClasses1DataContext();
  15.             getFixedPriceProjects();
  16.         }
  17.  
  18.         private void getFixedPriceProjects()
  19.         {
  20.             var fixedprojects =
  21.             from p in dbContext.projects
  22.             where p.fixedprice != null && p.projectstatus == "active"
  23.             select new { p.estimatedhours, p.id, p.projectname };
  24.  
  25.             foreach (var p in fixedprojects)
  26.             {
  27.                 var timeregistrationtables =
  28.                 from t in dbContext.timeregistrations
  29.                 where t.projectid == p.id
  30.                 select new { t.starttime, t.endtime };
  31.  
  32.                 TimeSpan totalTimeSpentOnProject = new TimeSpan(0);
  33.  
  34.                 foreach (var t in timeregistrationtables)
  35.                 {
  36.                     var start = ((DateTime)t.starttime).ToString("hh:mm");
  37.                     var end = ((DateTime)t.endtime).ToString("hh:mm");
  38.                     if (t.starttime != null && t.endtime != null)
  39.                     {
  40.                         totalTimeSpentOnProject += DateTime.Parse(end).Subtract(DateTime.Parse(start));
  41.                     }
  42.                 }
  43.                 var estimatedHours = "Estimated hours: " + p.estimatedhours;
  44.                 var totalTime = "Total man hours spent: " + totalTimeSpentOnProject;
  45.                 var fixedprojectoutcome = new List<Object> { estimatedHours, totalTime };
  46.  
  47.                 GridView fixedProjectGrid = new GridView();
  48.                 GridViewRow HeaderGridRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
  49.                 TableCell HeaderCell = new TableCell();
  50.                 HeaderCell.Text = p.projectname;
  51.                 HeaderCell.HorizontalAlign = HorizontalAlign.Center;
  52.                 HeaderCell.ColumnSpan = 2;
  53.                 HeaderGridRow.Cells.Add(HeaderCell);
  54.  
  55.                 fixedProjectGrid.DataSource = fixedprojectoutcome;
  56.                 fixedProjectGrid.DataBind();
  57.                 fixedProjectGrid.Controls[0].Controls.AddAt(0, HeaderGridRow);
  58.                 form1.Controls.Add(fixedProjectGrid);
  59.             }
  60.         }
  61.  
  62.         protected void BossBotton_Click(object sender, EventArgs e)
  63.         {
  64.             if (BossNameText.Text.Length > 0)
  65.             {
  66.                 var bossData =
  67.                 from b in dbContext.bosses
  68.                 where b.name == BossNameText.Text
  69.                 select new { b.id };
  70.  
  71.                 foreach (var b in bossData)
  72.                 {
  73.                     var employeeData =
  74.                         from em in dbContext.employees
  75.                         from empro in dbContext.employeeprojects
  76.                         from p in dbContext.projects
  77.                         from c in dbContext.customers
  78.                         where em.bossid == b.id
  79.                         where empro.employeeid == em.id
  80.                         where p.id == empro.projectid
  81.                         where c.id == p.customerid
  82.                         select new { p.projectname, c.customername };
  83.                     GridView bossGrid = new GridView();
  84.                     bossGrid.DataSource = employeeData;
  85.                     bossGrid.DataBind();
  86.                     form1.Controls.Add(bossGrid);
  87.  
  88.                 }
  89.             }
  90.         }
  91.  
  92.         protected void NewProjectButton_Click(object sender, EventArgs e)
  93.         {
  94.             project of = new project
  95.             {
  96.                 projectname = NewProjectName.Text,
  97.                 projectstatus = "active",
  98.                 customerid = 3,
  99.                 fixedprice = null,
  100.                 estimatedhours = null,
  101.                 hourlyrate = null
  102.             };
  103.             dbContext.projects.InsertOnSubmit(of);
  104.             try
  105.             {
  106.                 dbContext.SubmitChanges();
  107.             }
  108.             catch (Exception ex)
  109.             {
  110.                 Console.WriteLine(e);
  111.             }
  112.             var newProjectData =
  113.               from ep in dbContext.employeeprojects
  114.               where ep.projectid == Int32.Parse(OldProjectID.Text)
  115.               select new { ep.employeeid };
  116.             foreach (var np in newProjectData)
  117.             {
  118.                 employeeproject emp = new employeeproject
  119.                 {
  120.                     employeeid = np.employeeid,
  121.                     projectid = of.id
  122.                 };
  123.                 dbContext.employeeprojects.InsertOnSubmit(emp);
  124.                 try
  125.                 {
  126.                     dbContext.SubmitChanges();
  127.                 }
  128.                 catch (Exception ex)
  129.                 {
  130.                     Console.WriteLine(e);
  131.                 }
  132.             }
  133.         }
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement