示例#1
0
        // Client Name drop down list
        protected void ddlClientName_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                // Get client id
                int id = Convert.ToInt32(this.ddlClientName.SelectedValue);

                // Get clients with specific id
                var query = from client in db.CLIENTs
                            where client.ID == id
                            select client;

                // Add client to controls
                foreach (var c in query)
                {
                    txtClientContact.Text = c.cliConFName + " " + c.cliConLName;
                    txtClientAddress.Text = c.cliAddress;
                    txtClientPhone.Text   = c.cliPhone;
                }
            }
            catch (DataException dx)
            {
                NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
            }
            catch (Exception ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#2
0
        protected void btnClientCreate_Click(object sender, EventArgs e)
        {
            // Gather data to create new client
            CLIENT c = new CLIENT();

            c.cliName        = txtClientName.Text;
            c.cliAddress     = txtClientAddress.Text;
            c.cityID         = Convert.ToInt32(ddlClientCity.SelectedValue);
            c.cliProvince    = ddlClientProv.SelectedItem.Text;
            c.cliPCode       = txtClientPCode.Text;
            c.cliPhone       = txtClientPhone.Text;
            c.cliConFName    = txtClientConFName.Text;
            c.cliConLName    = txtClientConLName.Text;
            c.cliConPosition = txtClientConPosition.Text;
            db.CLIENTs.Add(c);

            try
            {
                db.SaveChanges();
                // Repopulate drop down lists
                DropDownList ddlClientList = (DropDownList)Body.FindControl("ddlClientList");
                DropDownHelper.PopulateClientList(ddlClientList);
                NotifyJS.DisplayNotification(this.Page, c.cliName + " successfully created.", "success");
                ClearClientModal();
            }
            catch (DataException ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#3
0
        protected void ddlLaborType_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                // Get id of worker
                int id = Convert.ToInt32(ddlLaborType.SelectedValue);

                // Get the selected cost for the type of worker
                var costs = (from cost in db.WORKER_TYPE
                             where cost.ID == id
                             orderby cost.wrkTypeDesc ascending
                             select cost).SingleOrDefault();

                if (ddlLaborType.SelectedValue == "-1")
                {
                    txtLaborUnitPrice.Text     = "0.00";
                    txtLaborHours.Text         = "0";
                    txtLaborExtendedPrice.Text = "0.00";
                }
                else
                {
                    txtLaborUnitPrice.Text     = Math.Round(Convert.ToDecimal(costs.wrkTypePrice), 2).ToString();
                    txtLaborExtendedPrice.Text = Math.Round(Convert.ToDecimal(txtLaborUnitPrice.Text) * Convert.ToDecimal(txtLaborHours.Text), 2).ToString();
                }
            }
            catch (DataException dx)
            {
                NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
            }
            catch (Exception ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Build the intiail table for daily work summary
                BuildInitialDailyWorkReportTable();
                DropDownHelper.PopulateEmployeeList(ddlEmployeeList);
                DropDownHelper.PopulateClientList(ddlClientList);
            }
            if (deleteClientFlag)
            {
                NotifyJS.DisplayNotification(this.Page, deletedClient + " was successfully deleted.", "success");
                deleteClientFlag = false;
            }
            //check is user is logged in
            if (User.Identity.IsAuthenticated)
            {
                // Find the control on the master page and assign the username to the label
                Label userNameLabel = (Label)Page.Master.FindControl("lblUserLoggedIn");
                userNameLabel.Text = User.Identity.Name;

                //Fill projects table from DB
                PopulateProjectsTable();

                // Set the date for the create daily work report modal to today by default
                txtCreateDailyWorkReportDateInPanel.Text = DateTime.Now.ToString("yyyy-MM-dd");
            }
            else
            {
                Response.Redirect("~/Default.aspx");
            }
        }
示例#5
0
        protected void btnSaveBid_Click(object sender, EventArgs e)
        {
            // Get project id from session
            int projectID = Convert.ToInt32(Session["ProjectID"]);

            // Find the project
            PROJECT proj = db.PROJECTs.Find(projectID);

            // Modify data
            proj.projName     = mdlTxtProjectName.Text;
            proj.projSite     = mdlTxtProjectSite.Text;
            proj.projEstStart = mdlTxtProjectBeginDate.Text;
            proj.projEstEnd   = mdlTxtProjectEndDate.Text;

            // Change entry state
            db.Entry(proj).State = System.Data.Entity.EntityState.Modified;

            try
            {
                db.SaveChanges();
                Response.Redirect("EditDesignBid.aspx", false);
            }
            catch (DataException ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#6
0
        protected void btnAddLabor_Click(object sender, EventArgs e)
        {
            // Get info from add textbox
            int   projectID         = Convert.ToInt32(Session["ProjectID"]);
            int   workerTypeID      = Convert.ToInt32(ddlLaborType.SelectedValue);
            int   taskDescriptionID = Convert.ToInt32(ddlLaborTask.SelectedValue);
            short hours             = Convert.ToInt16(txtLaborHours.Text);

            // Get production team id
            var labour = db.LABOUR_REQUIREMENT
                         .Where(p => p.ID == projectID)
                         .SingleOrDefault();

            // Add new labour requirement
            LABOUR_REQUIREMENT lr = new LABOUR_REQUIREMENT();

            lr.lreqEstHours = hours;
            lr.workerTypeID = workerTypeID;
            lr.taskID       = taskDescriptionID;
            lr.projectID    = projectID;
            lr.prodTeamID   = Convert.ToInt32(labour.prodTeamID);
            db.LABOUR_REQUIREMENT.Add(lr);

            try
            {
                db.SaveChanges();
                Response.Redirect("EditDesignBid.aspx", false);
            }
            catch (DataException ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#7
0
        protected void btnLaborAddNew_Click(object sender, EventArgs e)
        {
            try
            {
                // Add new row
                AddNewRowToLaborTable();

                // Set the summary label visibility
                lblLaborSummary.Visible = false;

                // Assign values to string array for prep in the database
                string[] row =
                {
                    ddlLaborType.SelectedItem.Text,
                    txtLaborHours.Text,
                    ddlLaborTask.SelectedValue,
                    txtLaborUnitPrice.Text,
                    txtLaborExtendedPrice.Text,
                    ddlLaborType.SelectedValue
                };

                // Add to labor rows for use with db
                laborRows.Add(row);

                // Increase labor total
                laborTotal += Convert.ToDecimal(txtLaborExtendedPrice.Text);

                // Adjust the bid amount
                bidAmount = laborTotal + materialTotal;

                // Display bid amount in textbox
                txtBidAmount.Text = bidAmount.ToString();

                // Set focus on hidden label to avoid page jump
                lblFocusHAX.Focus();

                // Add id to delete control drop down
                ddlDeleteLaborFromTable.Items.Add(laborIDCounter.ToString());

                // Increment labor ID counter
                laborIDCounter++;

                //Shows that a row has been added to the table
                labourTableFlag = true;
            }
            catch (DataException dx)
            {
                NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
            }
            catch (Exception ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#8
0
        protected void btnMaterialAddNew_Click(object sender, EventArgs e)
        {
            try
            {
                // Add new row
                AddNewRowToMaterialsTable();

                // Set visibility on summary label
                lblMaterialsSummary.Visible = false;

                // Assign values to string array and add to materialsRow list
                string[] row =
                {
                    ddlMaterialType.SelectedItem.Text,
                    txtMaterialQuantity.Text,
                    ddlMaterialDescription.SelectedValue,
                    ddlMaterialSize.SelectedItem.Text,
                    txtMaterialUnitPrice.Text,
                    txtMaterialExtendedPrice.Text
                };

                // Add data for use with db
                materialRows.Add(row);

                // Increase materials totral
                materialTotal += Convert.ToDecimal(txtMaterialExtendedPrice.Text);

                // Update bidamount
                bidAmount = materialTotal + laborTotal;

                // Apply bid amount to control
                txtBidAmount.Text = bidAmount.ToString();

                // Set focus on hidden label to avoid page jump
                lblFocusHAX.Focus();

                // Add id to delete drop down
                ddlDeleteMaterialFromTable.Items.Add(materialIDCounter.ToString());

                // Incrememnt material ID count
                materialIDCounter++;

                //Shows that a row has been added to the table
                materialsTableFlag = true;
            }
            catch (DataException dx)
            {
                NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
            }
            catch (Exception ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#9
0
        protected void ddlMaterialDescription_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                // Clear the drop down list and append initial value
                ddlMaterialSize.Items.Clear();

                if (ddlMaterialDescription.SelectedValue == "-1")
                {
                    ListItem item = new ListItem();
                    item.Text  = "Item not selected.";
                    item.Value = "-1";
                    ddlMaterialSize.Items.Add(item);
                }

                // Clear the textboxes
                txtMaterialExtendedPrice.Text = "0.00";
                txtMaterialQuantity.Text      = "0";

                // Get id of material
                int id = Convert.ToInt32(ddlMaterialDescription.SelectedValue);

                // Get the selected inventory item
                var materials = from material in db.MATERIALs
                                join inventory in db.INVENTORies on material.ID equals inventory.materialID
                                where inventory.materialID == id
                                select inventory;

                foreach (var m in materials)
                {
                    ListItem li = new ListItem();
                    li.Text  = m.invSizeAmnt + " " + m.invSizeUnit;
                    li.Value = Math.Round(Convert.ToDecimal(m.invList), 2).ToString();
                    ddlMaterialSize.Items.Add(li);
                    txtMaterialUnitPrice.Text = Math.Round(Convert.ToDecimal(m.invList), 2).ToString();
                }

                // Select the last item in the list
                ddlMaterialSize.SelectedIndex = ddlMaterialSize.Items.Count - 1;
            }
            catch (DataException dx)
            {
                NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
            }
            catch (Exception ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //check is user is logged in
            if (User.Identity.IsAuthenticated)
            {
                // Find the control on the master page and assign the username to the label
                Label userNameLabel = (Label)Page.Master.FindControl("lblUserLoggedIn");
                userNameLabel.Text = User.Identity.Name;
            }
            else
            {
                Response.Redirect("~/Default.aspx");
            }
            try
            {
                if (!IsPostBack)
                {
                    // Populate 5 drop down lists
                    PopulateDropDownLists();

                    // Build initial materials table
                    BuildInitialMaterialsTable();
                    BuildInitialLaborTable();

                    // Clear the data in the grid views and lists if not post back
                    gvMaterialsSummary.DataSource = new DataTable();
                    gvMaterialsSummary.DataBind();
                    gvLaborSummary.DataSource = new DataTable();
                    gvLaborSummary.DataBind();
                    materialRows.Clear();
                    laborRows.Clear();

                    // Hide the grid view show the label
                    gvLaborSummary.Visible      = false;
                    lblLaborSummary.Visible     = true;
                    gvMaterialsSummary.Visible  = false;
                    lblMaterialsSummary.Visible = true;
                }
            }
            catch (DataException dx)
            {
                NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
            }
            catch (Exception ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#11
0
        protected void btnEmployeeRemove_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(btnEmployeeRemove.Attributes["data-id"]);

            try
            {
                //delete an existing record
                WORKER w = db.WORKERs.Find(id);
                db.WORKERs.Remove(w);
                db.SaveChanges();
                // Reset the employeelist
                DropDownHelper.PopulateEmployeeList(ddlEmployeeList);
                NotifyJS.DisplayNotification(this.Page, w.wrkFName + " " + w.wrkLName + " was successfully deleted.", "success");
            }
            catch (DataException dx)
            {
                NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
            }
        }
示例#12
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            // Default UserStore constructor uses the default connection string named: DefaultConnection
            var          userStore = new UserStore <IdentityUser>();
            var          manager   = new UserManager <IdentityUser>(userStore);
            IdentityUser user      = manager.Find(txtUsername.Text, txtPassword.Text);

            if (user == null)
            {
                // This line of code calls a javascript helper function to display notifications
                // See Project.js DisplayNotification() for details
                NotifyJS.DisplayNotification(this.Page, "Username or password incorrect.", "error");
            }
            else
            {
                var authenticationManager = HttpContext.Current.GetOwinContext().Authentication;
                var userIdentity          = manager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
                authenticationManager.SignIn(userIdentity);
                Response.Redirect("~/Main.aspx");
            }
        }
示例#13
0
        protected void btnSaveClientChanges_Click(object sender, EventArgs e)
        {
            // Find button on body content tag
            LinkButton btnClientRemove = (LinkButton)Body.FindControl("btnClientRemove");

            // Get id from button
            int id = Convert.ToInt32(btnClientRemove.Attributes["data-id"]);

            // Find client data
            CLIENT c = db.CLIENTs.Find(id);

            c.cliName        = txtClientName.Text;
            c.cliAddress     = txtClientAddress.Text;
            c.cityID         = Convert.ToInt32(ddlClientCity.SelectedValue);
            c.cliProvince    = ddlClientProv.SelectedItem.Text;
            c.cliPCode       = txtClientPCode.Text;
            c.cliPhone       = txtClientPhone.Text;
            c.cliConFName    = txtClientConFName.Text;
            c.cliConLName    = txtClientConLName.Text;
            c.cliConPosition = txtClientConPosition.Text;

            // Set state to modified
            db.Entry(c).State = System.Data.Entity.EntityState.Modified;

            try
            {
                db.SaveChanges();

                // Repopulate drop down lists
                DropDownList ddlClientList = (DropDownList)Body.FindControl("ddlClientList");
                DropDownHelper.PopulateClientList(ddlClientList);
                NotifyJS.DisplayNotification(this.Page, c.cliName + " successfully modified.", "success");
                ClearClientModal();
                ReverseClientMode(true);
            }
            catch (DataException ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#14
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            if (txtRegisterPassword.Text != txtRegisterConfirmPassword.Text)
            {
                NotifyJS.DisplayNotification(this.Page, "Passwords do not match", "error");
            }
            else
            {
                // Default UserStore constructor uses the default connection string named: DefaultConnection
                var userStore = new UserStore <IdentityUser>();
                var manager   = new UserManager <IdentityUser>(userStore);
                var user      = new IdentityUser()
                {
                    UserName = txtRegisterUsername.Text
                };

                try
                {
                    IdentityResult result = manager.Create(user, txtRegisterPassword.Text);
                    if (result.Succeeded)
                    {
                        // This line of code calls a javascript helper function to display notifications
                        // See HelperClasses.NotifyJS for documentation on how to use it
                        NotifyJS.DisplayNotification(this.Page, user.UserName + " was created successfully!", "success");
                    }
                    else
                    {
                        // This line of code calls a javascript helper function to display notifications
                        // See Project.js DisplayNotification() for details
                        NotifyJS.DisplayNotification(this.Page, result.Errors.FirstOrDefault(), "error");
                    }
                }
                catch (DataException dx)
                {
                    lblDBERROR.Text = dx.InnerException.InnerException.Message;
                }
            }
        }
示例#15
0
        protected void btnAddNewEmployee_Click(object sender, EventArgs e)
        {
            // Gather data to create new employee
            WORKER w = new WORKER();

            w.wrkFName  = txtEmployeeFName.Text;
            w.wrkLName  = txtEmployeeLName.Text;
            w.wrkTypeID = Convert.ToInt32(ddlEmployeePosition.SelectedValue);
            db.WORKERs.Add(w);

            try
            {
                db.SaveChanges();
                // Repopulate drop down lists
                DropDownList ddlEmployeeList = (DropDownList)Body.FindControl("ddlEmployeeList");
                DropDownHelper.PopulateEmployeeList(ddlEmployeeList);
                NotifyJS.DisplayNotification(this.Page, w.wrkFName + " " + w.wrkLName + " successfully created.", "success");
            }
            catch (DataException ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#16
0
        protected void DeleteMaterialRequirement(object sender, EventArgs e)
        {
            // Get button that was clicked
            LinkButton lb = (LinkButton)sender;

            // Get id from button
            int id = Convert.ToInt32(lb.Attributes["data-id"]);

            // Find material
            MATERIAL_REQ mr = db.MATERIAL_REQ.Find(id);

            // Remove
            db.MATERIAL_REQ.Remove(mr);
            try
            {
                db.SaveChanges();
                Response.Redirect("EditDesignBid.aspx", false);
            }
            catch (DataException dx)
            {
                NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
            }
        }
示例#17
0
        protected void btnMaterialAdd_Click(object sender, EventArgs e)
        {
            // Get material id from drop down
            int matID = Convert.ToInt32(ddlMaterialDescription.SelectedValue);

            // Search inventory table
            var invQuery = (from inventory in db.INVENTORies
                            where inventory.materialID == matID
                            select inventory).SingleOrDefault();

            // Get id from query
            int invID = invQuery.ID;

            // get quantity from text box
            short matQty = Convert.ToInt16(txtMaterialQuantity.Text);

            // Add new material
            MATERIAL_REQ insertNew = new MATERIAL_REQ();

            insertNew.inventoryID = invID;
            insertNew.projectID   = Convert.ToInt32(Session["ProjectID"]);
            insertNew.mreqEstQty  = matQty;
            db.MATERIAL_REQ.Add(insertNew);

            // Reset textbox
            txtMaterialQuantity.Text = "";

            try
            {
                db.SaveChanges();
                Response.Redirect("EditDesignBid.aspx", false);
            }
            catch (DataException ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#18
0
        protected void btnDailyWorkReportAddNewTask_Click(object sender, EventArgs e)
        {
            try
            {
                // Show save button
                btnSaveDailyWorkReport.Visible = true;
                AddNewRowToDailyWorkReportTable();

                // Assign values to string array for prep in the database
                string[] row =
                {
                    ddlDailyWorkReportProjectInPanel.SelectedValue,
                    txtHoursWorked.Text,
                    ddlDailyWorkReportTaskstInPanel.SelectedValue,
                };

                // Add to rows for use with db
                dailyWorkReportRows.Add(row);

                // Set focus on hidden label to avoid page jump
                lblFocusHAX.Focus();

                // Add row numbers to drop down
                ddlDeleteDailyWorkReportFromTable.Items.Add(dailyWorkReportIDCounter.ToString());

                // Increment row counter
                dailyWorkReportIDCounter++;
            }
            catch (DataException dx)
            {
                NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
            }
            catch (Exception ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#19
0
        protected void DeleteLaborRequirement(object sender, EventArgs e)
        {
            // Get button that was clicked
            LinkButton lb = (LinkButton)sender;

            // Get the ID of the labour requirement from the button
            int id = Convert.ToInt32(lb.Attributes["data-id"]);

            // Find the requirement
            LABOUR_REQUIREMENT lr = db.LABOUR_REQUIREMENT.Find(id);

            // Remove
            db.LABOUR_REQUIREMENT.Remove(lr);

            try
            {
                db.SaveChanges();
                Response.Redirect("EditDesignBid.aspx", false);
            }
            catch (DataException dx)
            {
                NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
            }
        }
示例#20
0
        protected void ddlMaterialType_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                // Clear textboxes
                txtMaterialExtendedPrice.Text = "0.00";
                txtMaterialQuantity.Text      = "0";
                txtMaterialUnitPrice.Text     = "0.00";

                // Clear the drop down and add back the first item for the postback
                ddlMaterialDescription.Items.Clear();
                ListItem initial = new ListItem();
                initial.Text  = "Select an Item...";
                initial.Value = "-1";
                ddlMaterialDescription.Items.Add(initial);

                // Clear the item drop down list
                ddlMaterialSize.Items.Clear();
                ListItem item = new ListItem();
                item.Text  = "Item not selected.";
                item.Value = "-1";
                ddlMaterialSize.Items.Add(item);

                // Preload all materials so visual studio doesnt fight me
                var materials = from material in db.MATERIALs
                                select material;

                if (ddlMaterialType.SelectedValue == "Materials")
                {
                    materials = from material in db.MATERIALs
                                where material.matType == "Materials"
                                select material;
                }
                else if (ddlMaterialType.SelectedValue == "Plant")
                {
                    materials = from material in db.MATERIALs
                                where material.matType == "Plant"
                                select material;
                }
                else if (ddlMaterialType.SelectedValue == "Pottery")
                {
                    materials = from material in db.MATERIALs
                                where material.matType == "Pottery"
                                select material;
                }

                // Add to materials drop down list
                foreach (var m in materials)
                {
                    ListItem li = new ListItem();
                    li.Text  = m.matDesc;
                    li.Value = m.ID.ToString();
                    ddlMaterialDescription.Items.Add(li);
                }
            }
            catch (DataException dx)
            {
                NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
            }
            catch (Exception ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }
示例#21
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");
                }
            }
        }
示例#22
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");
                }
            }
        }
示例#23
0
        protected void PopulateDropDownLists()
        {
            try
            {
                // Get distinct values from material types
                var materials = (from material in db.MATERIALs
                                 select material.matType).Distinct();

                // Add to materials drop down list
                foreach (var m in materials)
                {
                    ListItem li = new ListItem();
                    li.Text  = m;
                    li.Value = m;
                    ddlMaterialType.Items.Add(li);
                }

                // Get sales associates
                var sales = from workers in db.WORKERs
                            join workerType in db.WORKER_TYPE on workers.wrkTypeID equals workerType.ID
                            where workerType.ID == 7
                            select workers;

                // Add to sales drop down list
                foreach (var s in sales)
                {
                    ListItem li = new ListItem();
                    li.Text  = s.wrkFName + " " + s.wrkLName;
                    li.Value = s.ID.ToString();
                    ddlNBDSales.Items.Add(li);
                }

                // Get designers
                var designers = from workers in db.WORKERs
                                join workerType in db.WORKER_TYPE on workers.wrkTypeID equals workerType.ID
                                where workerType.ID == 2 || workerType.ID == 5
                                select workers;

                // Add to designers drop down list
                foreach (var d in designers)
                {
                    ListItem li = new ListItem();
                    li.Text  = d.wrkFName + " " + d.wrkLName;
                    li.Value = d.ID.ToString();
                    ddlNBDDesigner.Items.Add(li);
                }

                // Add employees to create labor type modal
                var workerTypes = from workers in db.WORKER_TYPE
                                  orderby workers.wrkTypeDesc ascending
                                  select workers;

                foreach (var w in workerTypes)
                {
                    ListItem li = new ListItem();
                    li.Text  = w.wrkTypeDesc;
                    li.Value = w.ID.ToString();
                    ddlLaborType.Items.Add(li);
                }

                // Get the list of tasks from the database
                var tasks = from task in db.TASKs
                            orderby task.taskDesc ascending
                            select task;

                foreach (var t in tasks)
                {
                    ListItem li = new ListItem();
                    li.Text  = t.taskDesc;
                    li.Value = t.ID.ToString();
                    ddlLaborTask.Items.Add(li);
                }
            }
            catch (DataException dx)
            {
                NotifyJS.DisplayNotification(this.Page, dx.InnerException.InnerException.Message, "danger");
            }
            catch (Exception ex)
            {
                NotifyJS.DisplayNotification(this.Page, ex.InnerException.InnerException.Message, "danger");
            }
        }