Exemple #1
0
        private ClientAgmt GetClientAgmt(int id, string strFilename, byte[] myData)
        {
            int      intOutput;
            DateTime dt1, dt2, dt3, dt4;
            Decimal  dc = 0.0m;

            ClientAgmt ca = new ClientAgmt()
            {
                Id                 = id,
                CollabCtrId        = Int32.TryParse(Request.QueryString["Id"], out intOutput) ? intOutput : -1,
                Project2Id         = Int32.TryParse(ddlProject.SelectedValue, out intOutput) ? intOutput : -1,
                ProjectPhase       = ddlProjectPhase.SelectedItem.Text,
                ClientRefNum       = txtClientRefNum.Value,
                RequestDate        = DateTime.TryParse(txtRequestDate.Text, out dt1) ? dt1 : (DateTime?)null,
                ApprovedPhdHr      = Decimal.TryParse(txtPhdHour.Value, out dc) ? dc : (Decimal?)null,
                ApprovedPhdRate    = Decimal.TryParse(txtPhdRate.Value, out dc) ? dc : (Decimal?)null,
                ApprovedMsHr       = Decimal.TryParse(txtMsHour.Value, out dc) ? dc : (Decimal?)null,
                ApprovedMsRate     = Decimal.TryParse(txtMsRate.Value, out dc) ? dc : (Decimal?)null,
                ApprovalDate       = DateTime.TryParse(txtBqhsApprovalDate.Text, out dt2) ? dt2 : DateTime.Now,
                ClientApprovalDate = DateTime.TryParse(txtClientApprovalDate.Text, out dt3) ? dt3 : (DateTime?)null,
                CompletionDate     = DateTime.TryParse(txtCompletionDate.Text, out dt4) ? dt4 : (DateTime?)null,
                FileName           = strFilename,
                FileUpload         = myData,
                Comments           = txtComments.Value,
                Creator            = Page.User.Identity.Name,
                CreateDate         = DateTime.Now,
                AgmtId             = txtAgmtId.Value,
                AgmtStatus         = ddlStatus.Value
            };

            return(ca);
        }
Exemple #2
0
        protected void rptClientAgmt_ItemCommand(Object sender, RepeaterCommandEventArgs e)
        {
            if (((Button)e.CommandSource).Text.Equals("Edit"))
            {
                int id = 0;
                int.TryParse(((Button)e.CommandSource).CommandArgument, out id);

                //txtAgmtId.Value = ((Button)e.CommandSource).CommandArgument;

                if (id > 0)
                {
                    ClientAgmt ca = GetClientAgmtById(id);

                    if (ca != null)
                    {
                        SetClientAgmt(ca);

                        //ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                        //           "ModalScript", PageUtility.LoadEditScript(true), false);
                        StringBuilder sb = new StringBuilder();
                        sb.Append(@"<script type='text/javascript'>");
                        sb.Append("$('#editModal').modal('show');");
                        sb.Append("$('#MainContent_fileUpload').fileinput('enable');");
                        //sb.Append("var projectId = $('#MainContent_ddlProject').val(); ");
                        //sb.Append("bindPI(projectId);");
                        sb.Append("calcTotal();");
                        sb.Append(@"</script>");

                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                                                "ModalScript", sb.ToString(), false);
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Loads page with fields with the correct information
        /// in preparation for data entry and/or interaction.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                BindControl();

                int    id           = 0;
                string clientAgmtId = Request.QueryString["ClientAgmtId"];
                if (clientAgmtId != null)
                {
                    ClientAgmt ca = GetClientAgmtByAgmtAbbrv(clientAgmtId);
                    if (ca != null)
                    {
                        id = ca.Id;
                    }
                }
                //Int32.TryParse(ca.Id, out id);
                if (id > 0)
                {
                    OpenClientAgmt(id);
                }
            }
            //else
            //{

            //    //Reopens modal after page postback.
            //    ClientScript.RegisterStartupScript(GetType(), "ModalScript", "$('#editModal').modal('show');", true);

            //}
        }
Exemple #4
0
        /// <summary>
        /// Opens the pop-up page of the client agreement form.
        /// </summary>
        /// <param name="id">Referred Client Agreement Id.</param>
        protected void OpenClientAgmt(int id)
        {
            if (id > 0)
            {
                ClientAgmt ca = GetClientAgmtById(id);

                if (ca != null)
                {
                    SetClientAgmt(ca);

                    //ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                    //           "ModalScript", PageUtility.LoadEditScript(true), false);
                    StringBuilder sb = new StringBuilder();
                    sb.Append(@"<script type='text/javascript'>");
                    sb.Append("$('#editModal').modal('show');");
                    sb.Append("$('#MainContent_fileUpload').fileinput('enable');");
                    //sb.Append("var projectId = $('#MainContent_ddlProject').val(); ");
                    //sb.Append("bindPI(projectId);");
                    sb.Append("calcTotal();");
                    sb.Append(@"</script>");

                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                                            "ModalScript", sb.ToString(), false);
                }
            }
        }
Exemple #5
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int    id      = 0;
            string ccAbbrv = txtCCAbbrv.Value,
                   agmtId  = txtAgmtId.Value,
                   strId   = txtId.Value;

            //char[] delimiter = { '-', '_' };

            //if (agmtId.Split(delimiter).Length > 1)
            //{
            //    Int32.TryParse(agmtId.Split(delimiter)[1], out id);
            //}

            Int32.TryParse(strId, out id);

            string strFilename = "";

            byte[] myData = new byte[0];
            // Check to see if file was uploaded
            if (fileUpload.PostedFile != null)
            {
                // Get a reference to PostedFile object
                HttpPostedFile myFile = fileUpload.PostedFile;

                // Get size of uploaded file
                int nFileLen = myFile.ContentLength;

                // make sure the size of the file is > 0
                if (nFileLen > 0)
                {
                    // Allocate a buffer for reading of the file
                    myData = new byte[nFileLen];

                    // Read uploaded file from the Stream
                    myFile.InputStream.Read(myData, 0, nFileLen);

                    // Create a name for the file to store
                    strFilename = System.IO.Path.GetFileName(myFile.FileName);

                    // Write data into a file
                    //WriteToFile(Server.MapPath(strFilename), ref myData);

                    //// Store it in database
                    //int nFileID = WriteToDB(strFilename, myFile.ContentType, ref myData);
                }
            }

            ClientAgmt agmt = GetClientAgmt(id, strFilename, myData);

            //save to database
            SaveClientAgmt(agmt);

            ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                                    "ModalScript", PageUtility.LoadEditScript(false), false);

            BindRptClientAgmt();
        }
Exemple #6
0
        private ClientAgmt GetClientAgmtById(int id)
        {
            ClientAgmt ca = null;

            using (var db = new ProjectTrackerContainer())
            {
                ca = db.ClientAgmt
                     .Include(a => a.Project2.Invests)
                     .Include(a => a.CollabCtr)
                     .FirstOrDefault(a => a.Id == id);

                //ca.CollabCtr = ca.CollabCtr;
                //ca.Project2.Invests = ca.Project2.Invests;
                //ca.ProjectPhase = ca.ProjectPhase;
                //ca.AgmtStatus = ca.AgmtStatus;

                //if (ca.Project2Id > 0)
                //{
                //    var query = db.ProjectPhase.Where(p => p.ProjectId == ca.Project2Id).ToList();

                //    //ListItem removeItem=ddlProjectPhase.Items.FindByValue("1");
                //    //ddlProjectPhase.Items.Remove(removeItem);

                //    //foreach (var p in query)
                //    //{
                //    //    foreach (ListItem li in ddlProjectPhaseHdn.Items)
                //    //    {
                //    //        ListItem newItem = new ListItem();
                //    //        newItem.Value = li.Value;
                //    //        newItem.Text = li.Text;
                //    //        newItem.Selected = false;

                //    //        if (li.Text == p.Name)
                //    //        {
                //    //            newItem.Selected = true;
                //    //        }

                //    //        ddlProjectPhase.Items.Add(newItem);
                //    //    }
                //    //}

                //    //ddlProjectPhase.Items.Insert(0, new ListItem(string.Empty, String.Empty));

                //    foreach (ListItem li in ddlProjectPhase.Items)
                //    {
                //        //if (query.Contains(li.Text))
                //        //remove item if not in query
                //    }
                //}
            }

            return(ca);
        }
Exemple #7
0
        /// <summary>
        /// Based on the given Client Agreement abbreviation, returns the instance of a client
        /// agreement instance.
        /// </summary>
        /// <param name="agmtAbbrv">Given Client Agreement Name Abbreviation.</param>
        /// <returns>Instance of the Client Agreement matched with its name abbrevation.</returns>
        private ClientAgmt GetClientAgmtByAgmtAbbrv(string agmtAbbrv)
        {
            ClientAgmt ca = null;

            using (var db = new ProjectTrackerContainer())
            {
                ca = db.ClientAgmt
                     .Include(a => a.Project2.Invests)
                     .Include(a => a.CollabCtr)
                     .FirstOrDefault(a => a.AgmtId == agmtAbbrv);
            }

            return(ca);
        }
Exemple #8
0
        private int SaveClientAgmt(ClientAgmt ca)
        {
            int caid = -1;

            try
            {
                using (ProjectTrackerContainer db = new ProjectTrackerContainer())
                {
                    if (ca.Id > 0) //update
                    {
                        var prevClientAgmt = db.ClientAgmt.FirstOrDefault(c => c.Id == ca.Id);

                        if (prevClientAgmt != null)
                        {
                            ca.CollabCtrId = prevClientAgmt.CollabCtrId;

                            if (prevClientAgmt.FileName != null && prevClientAgmt.FileUpload != null)
                            {
                                if (ca.FileUpload.Count <byte>() == 0 && prevClientAgmt.FileUpload.Count <byte>() > 0)
                                {
                                    ca.FileName   = prevClientAgmt.FileName;
                                    ca.FileUpload = prevClientAgmt.FileUpload;
                                }
                            }

                            db.Entry(prevClientAgmt).CurrentValues.SetValues(ca);
                        }
                    }
                    else //new
                    {
                        db.ClientAgmt.Add(ca);
                    }

                    db.SaveChanges();

                    caid = ca.Id;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //
            }

            return(caid);
        }
Exemple #9
0
        private void SetClientAgmt(ClientAgmt ca)
        {
            txtId.Value              = ca.Id.ToString();
            txtCCAbbrv.Value         = ca.CollabCtr.NameAbbrv;
            txtAgmtId.Value          = ca.AgmtId; //ca.Id > 0 ? txtCCAbbrv.Value + '-' + ca.Id.ToString() : "";
            ddlProject.SelectedValue = ca.Project2Id.ToString();
            txtPI.Value              = ca.Project2.Invests.FirstName + ' ' + ca.Project2.Invests.LastName;
            txtProjectType.Value     = Enum.GetName(typeof(ProjectType), ca.Project2.ProjectType);

            int phaseId = 0;

            string[] phase = ca.ProjectPhase.Split('-');
            if (phase.Length > 1)
            {
                Int32.TryParse(phase[1], out phaseId);
            }

            ddlProjectPhase.SelectedValue = phaseId > 0 ? phaseId.ToString() : "";

            txtClientRefNum.Value = ca.ClientRefNum;
            txtRequestDate.Text   = ca.RequestDate != null?Convert.ToDateTime(ca.RequestDate).ToShortDateString() : "";

            txtPhdRate.Value = ca.ApprovedPhdRate != null?ca.ApprovedPhdRate.ToString() : "";

            txtPhdHour.Value = ca.ApprovedPhdHr != null?ca.ApprovedPhdHr.ToString() : "";

            txtMsRate.Value = ca.ApprovedMsRate != null?ca.ApprovedMsRate.ToString() : "";

            txtMsHour.Value = ca.ApprovedMsHr != null?ca.ApprovedMsHr.ToString() : "";

            txtBqhsApprovalDate.Text = ca.ApprovalDate != null?Convert.ToDateTime(ca.ApprovalDate).ToShortDateString() : "";

            txtClientApprovalDate.Text = ca.ClientApprovalDate != null?Convert.ToDateTime(ca.ClientApprovalDate).ToShortDateString() : "";

            txtCompletionDate.Text = ca.CompletionDate != null?Convert.ToDateTime(ca.CompletionDate).ToShortDateString() : "";

            ddlStatus.Value = ca.AgmtStatus != null ? ca.AgmtStatus : "";

            //fileUpload
            lnkFile.Text = ca.FileName;

            txtComments.Value = ca.Comments;
        }
Exemple #10
0
        /// <summary>
        /// Saves the current project form into the database when the "Save" button has been selected.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int    id      = 0;
            string ccAbbrv = txtCCAbbrv.Value,
                   agmtId  = txtAgmtId.Value,
                   strId   = txtId.Value;

            //char[] delimiter = { '-', '_' };

            //if (agmtId.Split(delimiter).Length > 1)
            //{
            //    Int32.TryParse(agmtId.Split(delimiter)[1], out id);
            //}

            Int32.TryParse(strId, out id);

            string strFilename = "";

            byte[] myData = new byte[0];
            // Check to see if file was uploaded
            if (fileUpload.PostedFile != null)
            {
                // Get a reference to PostedFile object
                HttpPostedFile myFile = fileUpload.PostedFile;

                // Get size of uploaded file
                int nFileLen = myFile.ContentLength;

                // make sure the size of the file is > 0
                if (nFileLen > 0)
                {
                    // Allocate a buffer for reading of the file
                    myData = new byte[nFileLen];

                    // Read uploaded file from the Stream
                    myFile.InputStream.Read(myData, 0, nFileLen);

                    // Create a name for the file to store
                    strFilename = System.IO.Path.GetFileName(myFile.FileName);

                    // Write data into a file
                    //WriteToFile(Server.MapPath(strFilename), ref myData);

                    //// Store it in database
                    //int nFileID = WriteToDB(strFilename, myFile.ContentType, ref myData);
                }
            }

            ClientAgmt agmt = GetClientAgmt(id, strFilename, myData);

            //save to database
            SaveClientAgmt(agmt);

            string appPath = String.Empty;

            appPath = HttpContext.Current.Request.ApplicationPath.Length > 1 ? HttpContext.Current.Request.ApplicationPath
                      + "/Admin/"
                                                                             : String.Empty;

            ScriptManager.RegisterStartupScript(this, this.GetType(), "successMsg",
                                                "alert('Record Saved Successfully'); window.location='" + appPath
                                                + "ClientAgreementForm?ClientAgmtId="
                                                + agmtId + "';", true);

            //ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
            //           "ModalScript", PageUtility.LoadEditScript(false), false);

            //BindRptClientAgmt(id);

            //Response.Redirect(String.Format("~/Admin/ClientAgreementForm?ClientAgmtId={0}", agmtId));
        }