예제 #1
0
        public void DeleteClientOrProject(IQueryable <PROJECT> project, string type, int id)
        {
            // Delete all projects and child records associated with passed paramater project
            foreach (var p in project)
            {
                var labourSummary = db.LABOUR_SUMMARY
                                    .Where(labID => labID.projectID == p.ID);

                foreach (var l in labourSummary)
                {
                    int            lsID = l.ID;
                    LABOUR_SUMMARY ls   = db.LABOUR_SUMMARY.Find(lsID);
                    db.LABOUR_SUMMARY.Remove(ls);
                }

                var materialRequirement = db.MATERIAL_REQ
                                          .Where(matID => matID.projectID == p.ID);

                foreach (var m in materialRequirement)
                {
                    int          mID = m.ID;
                    MATERIAL_REQ mr  = db.MATERIAL_REQ.Find(mID);
                    db.MATERIAL_REQ.Remove(mr);
                }

                var labourRequirement = db.LABOUR_REQUIREMENT
                                        .Where(lrID => lrID.projectID == p.ID);

                foreach (var l in labourRequirement)
                {
                    int lID = l.ID;
                    LABOUR_REQUIREMENT lr = db.LABOUR_REQUIREMENT.Find(lID);
                    db.LABOUR_REQUIREMENT.Remove(lr);
                }

                var prodTeam = db.PROD_TEAM
                               .Where(ptID => ptID.projectID == p.ID);

                foreach (var pts in prodTeam)
                {
                    int       pteamID = pts.ID;
                    PROD_TEAM pt      = db.PROD_TEAM.Find(pteamID);
                    db.PROD_TEAM.Remove(pt);

                    var teamMember = db.TEAM_MEMBER
                                     .Where(tmID => tmID.teamID == pts.ID);

                    foreach (var ptm in teamMember)
                    {
                        int         teamMemberID = ptm.Id;
                        TEAM_MEMBER tm           = db.TEAM_MEMBER.Find(teamMemberID);
                        db.TEAM_MEMBER.Remove(tm);
                    }
                }
                db.PROJECTs.Remove(p);
            }
            if (type == "Client")
            {
                try
                {
                    //delete an existing record
                    CLIENT c = db.CLIENTs.Find(id);
                    db.CLIENTs.Remove(c);
                    db.SaveChanges();
                    DropDownHelper.PopulateClientList(ddlClientList);
                    deletedClient    = c.cliName;
                    deleteClientFlag = true;
                    Response.Redirect("~/Main.aspx", false);
                }
                catch (DataException dx)
                {
                    NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
                }
            }
            else
            {
                try
                {
                    db.SaveChanges();
                    Response.Redirect("~/Main.aspx", false);
                }
                catch (DataException dx)
                {
                    NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
                }
            }
        }
예제 #2
0
        /* ----------------------------------------------------------------------------------------- */
        /* ------------------------ GRID VIEW CODE FOR LABOR TABLE ----------------------------- */
        /* ----------------------------------------------------------------------------------------- */
        protected void btnDesignBidCreate_Click(object sender, EventArgs e)
        {
            if (labourTableFlag == false || materialsTableFlag == false)
            {
                if (materialsTableFlag == false)
                {
                    NotifyJS.DisplayNotification(this.Page, "You cannot create a Design Bid with no Materials added.", "danger");
                }

                if (labourTableFlag == false)
                {
                    NotifyJS.DisplayNotification(this.Page, "You cannot create a Design Bid with no Labor Requirements.", "danger");
                }
            }
            else
            {
                try
                {
                    // Get the last ID from the projects table
                    var projId = db.PROJECTs.Max(x => x.ID) + 1;

                    // Store project information into project variable
                    PROJECT p = new PROJECT();
                    p.ID                = projId;
                    p.projName          = txtProjectName.Text;
                    p.projSite          = txtProjectSite.Text;
                    p.projBidDate       = DateTime.Now;
                    p.projEstStart      = txtProjectBeginDate.Text;
                    p.projEstEnd        = txtProjectEndDate.Text;
                    p.projActStart      = "TBA";
                    p.projActEnd        = "TBA";
                    p.projEstCost       = (txtBidAmount.Text == string.Empty) ? "0.00" : txtBidAmount.Text;
                    p.projActCost       = "0";
                    p.projBidCustAccept = false;
                    p.projBidMgmtAccept = false;
                    p.projCurrentPhase  = "D";
                    p.projIsFlagged     = false;
                    p.clientID          = Convert.ToInt32(ddlClientName.SelectedValue);
                    p.designerID        = Convert.ToInt32(ddlNBDDesigner.SelectedValue);

                    // Add to projects table
                    db.PROJECTs.Add(p);

                    // MATERIAL REQUIREMENTS
                    for (int i = 0; i < materialRows.Count; i++)
                    {
                        // Get the appropriate inventory ID for the material
                        int matID = Convert.ToInt32(materialRows[i][2]);
                        var invID = db.INVENTORies.Where(x => x.ID == matID).SingleOrDefault();

                        // Create material requirements object to hold material data
                        MATERIAL_REQ m = new MATERIAL_REQ();
                        m.inventoryID = invID.ID;
                        m.projectID   = projId;
                        m.mreqDeliver = null;
                        m.mreqInstall = null;
                        m.mreqEstQty  = Convert.ToInt16(materialRows[i][1]);
                        m.mreqActQty  = null;

                        // Add to material requirements table
                        db.MATERIAL_REQ.Add(m);
                    }

                    // PRODUCTION TEAM
                    PROD_TEAM team = new PROD_TEAM();
                    team.projectID   = projId;
                    team.teamName    = "TEST TEAM BRA";
                    team.teamPhaseIn = "B";
                    db.PROD_TEAM.Add(team);

                    // Save changes in order to get the new max prod team id
                    db.SaveChanges();

                    // Get the last production team ID
                    int teamID = db.PROD_TEAM.Max(m => m.ID);

                    //Add Designer
                    TEAM_MEMBER designer = new TEAM_MEMBER();
                    designer.workerID = p.designerID;
                    designer.teamID   = teamID;
                    db.TEAM_MEMBER.Add(designer);

                    //Add Sales Associate
                    TEAM_MEMBER sales = new TEAM_MEMBER();
                    sales.workerID = Convert.ToInt32(ddlNBDSales.SelectedValue);
                    sales.teamID   = teamID;
                    db.TEAM_MEMBER.Add(sales);

                    // LABOR SUMMARY
                    LABOUR_SUMMARY ls = new LABOUR_SUMMARY();
                    ls.projectID    = projId;
                    ls.workerTypeID = Convert.ToInt32(ddlLaborType.SelectedValue);

                    // Total up labor hours and add to object
                    short labourHours = 0;
                    for (int i = 0; i < laborRows.Count; i++)
                    {
                        labourHours += Convert.ToInt16(laborRows[i][1]);
                    }
                    ls.lsHours = labourHours;
                    db.LABOUR_SUMMARY.Add(ls);

                    for (int i = 0; i < laborRows.Count; i++)
                    {
                        LABOUR_REQUIREMENT l = new LABOUR_REQUIREMENT();
                        l.prodTeamID   = teamID;
                        l.taskID       = Convert.ToInt32(laborRows[i][2]);
                        l.lreqEstDate  = null;
                        l.lreqEstHours = Convert.ToInt16(laborRows[i][1]);
                        l.lreqActDate  = null;
                        l.lreqActHours = null;
                        l.lreqComments = null;
                        l.projectID    = projId;
                        l.workerTypeID = Convert.ToInt32(laborRows[i][5]);
                        db.LABOUR_REQUIREMENT.Add(l);
                    }

                    // Save
                    db.SaveChanges();

                    // Display notification
                    Response.Redirect("~/Main.aspx", false);
                    NotifyJS.DisplayNotification(this.Page, "Design bid " + p.projName + " for " + p.CLIENT.cliName + " successfully added.", "success");
                }
                catch (DataException dx)
                {
                    NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
                }
                catch (Exception ex)
                {
                    NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
                }
            }
        }