Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SessionBo.CheckSession();
            advisorVo = (AdvisorVo)Session[SessionContents.AdvisorVo];
            userVo    = (UserVo)Session[SessionContents.UserVo];
            // Get the Repository Path in solution
            strRepositoryPath = ConfigurationManager.AppSettings["RepositoryPath"].ToString();

            // Method to get the Storage Balance & Maximum Storage
            repoBo          = new RepositoryBo();
            fStorageBalance = repoBo.GetAdviserStorageValues(advisorVo.advisorId, out fMaxStorage);

            // Bind View Grid Filters
            rgRepositoryList_Init(sender, e);

            if (!IsPostBack)
            {
                // Manage Repository Methods
                BindCategory();

                // Clear Session
                Session[SessionContents.RepositoryVo] = null;
            }

            if (Session[SessionContents.RepositoryVo] != null)
            {
                BindEditFields();
            }
        }
        private void BindCategories()
        {
            repoBo = new RepositoryBo();
            DataSet ds = new DataSet();

            ds = repoBo.GetRepositoryCategory(advisorVo.advisorId);
            int intRepoCount = ds.Tables[0].Rows.Count;
            int intRoleCount = ds.Tables[1].Rows.Count;

            ViewState["intRepoDSCount"] = intRepoCount;

            if (intRepoCount > 0)
            {
                for (int i = 0; i < intRepoCount; i++)
                {
                    Label        lbl      = (Label)this.FindControl("lblCategory" + (i + 1).ToString());
                    HiddenField  hdn      = (HiddenField)this.FindControl("hdnCat" + (i + 1).ToString());
                    TextBox      txt      = (TextBox)this.FindControl("txtCategory" + (i + 1).ToString());
                    CheckBoxList chkbxlst = (CheckBoxList)this.FindControl("CheckBoxList" + (i + 1).ToString());
                    lbl.Text  = ds.Tables[0].Rows[i]["ARC_RepositoryCategory"].ToString();
                    hdn.Value = ds.Tables[0].Rows[i]["ARC_AdviserRepositoryCategoryId"].ToString();
                    txt.Text  = ds.Tables[0].Rows[i]["ARC_RepositoryCategory"].ToString();

                    // Filter 2nd Dataset based on hdn.Value
                    foreach (DataRow dr in ds.Tables[1].Select("ARC_AdviserRepositoryCategoryId = '" + hdn.Value + "'"))
                    {
                        if (dr["UR_RoleId"].ToString() == strAdviserAdminRoleId)
                        {
                            SelectCheckboxListItem(chkbxlst, strAdviserAdminRoleId);
                        }
                        else if (dr["UR_RoleId"].ToString() == strRMRoleId)
                        {
                            SelectCheckboxListItem(chkbxlst, strRMRoleId);
                        }
                        else if (dr["UR_RoleId"].ToString() == strBMRoleId)
                        {
                            SelectCheckboxListItem(chkbxlst, strBMRoleId);
                        }
                        else if (dr["UR_RoleId"].ToString() == strCustomerRoleId)
                        {
                            SelectCheckboxListItem(chkbxlst, strCustomerRoleId);
                        }
                        else if (dr["UR_RoleId"].ToString() == strOpsRoleId)
                        {
                            SelectCheckboxListItem(chkbxlst, strOpsRoleId);
                        }
                        else if (dr["UR_RoleId"].ToString() == strResearchRoleId)
                        {
                            SelectCheckboxListItem(chkbxlst, strResearchRoleId);
                        }
                    }
                }
            }
        }
Exemple #3
0
        protected void lnkBtnFileNameClientListGrid_Click(object sender, EventArgs e)
        {
            LinkButton   lnkBtn   = (sender as LinkButton);
            GridDataItem dataItem = lnkBtn.NamingContainer as GridDataItem;
            int          intKey   = Int32.Parse(dataItem.GetDataKeyValue("AR_RepositoryId").ToString());

            // Get RepositoryVo
            RepositoryVo repoVo = new RepositoryVo();
            RepositoryBo repoBo = new RepositoryBo();

            repoVo = repoBo.GetRepositoryItem(intKey);
            Session[SessionContents.RepositoryVo] = repoVo;

            // Change the tab
            ChangeTelerikRadTab(0);

            BindEditFields();
        }
Exemple #4
0
        protected void rgRepositoryList_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            repoBo = new RepositoryBo();
            ds     = new DataSet();
            ds     = repoBo.GetAdviserRepositoryView(advisorVo.advisorId);

            if (ds.Tables[0].Rows.Count > 0)
            {
                rgRepositoryList.DataSource = ds.Tables[0];
                SetContentVisibility(true);
                ViewState["dsRepository"] = ds;
            }
            else
            {
                // display no records found
                SetContentVisibility(false);
            }
        }
Exemple #5
0
 private bool AddUpdateRepositoryLink(bool blResult, string strAction, RepositoryVo repoVo)
 {
     repoBo = new RepositoryBo();
     try
     {
         blResult = (strAction.Equals(Constants.Add.ToString())) ? repoBo.AddRepositoryItem(repoVo, issueId) : repoBo.UpdateRepositoryItem(repoVo);
     }
     catch (BaseApplicationException Ex)
     {
         throw Ex;
     }
     catch (Exception Ex)
     {
         object[] objects = new object[1];
         objects[0] = repoVo;
         PageException(objects, Ex, "ManageRepository.ascx:AddClick()");
     }
     return(blResult);
 }
Exemple #6
0
        private void BindCategory()
        {
            repoBo = new RepositoryBo();
            ds     = new DataSet();
            int CatId = 0;

            CatId = creatingProspectus();
            ds    = repoBo.GetRepositoryCategory(advisorVo.advisorId);

            if (ds.Tables[0].Rows.Count > 0)
            {
                // Bind Category DDL for Manage Tab
                ddlRCategory.DataSource     = ds.Tables[0];
                ddlRCategory.DataTextField  = strRepositoryCategoryTextField;
                ddlRCategory.DataValueField = strRepositoryCategoryValueField;
                ddlRCategory.DataBind();
                ddlRCategory.Items.Insert(0, new ListItem("Select", "Select"));
            }
            if (CatId > 0)
            {
                ddlRCategory.SelectedValue = "PR";
                ddlRCategory.Enabled       = false;
            }
        }
        private void BindListBoxes()
        {
            RepositoryBo  repoBo     = new RepositoryBo();
            DataSet       ds         = new DataSet();
            StringBuilder sbRoleList = new StringBuilder();

            // creating comma separated roleId list so that we can reuse the function which separates comma separated role list
            if (userVo.RoleList != null)
            {
                foreach (string str in userVo.RoleList)
                {
                    string strRoleId = string.Empty;
                    if (str.ToLower() == "admin")
                    {
                        strRoleId = "1000";
                    }
                    else if (str.ToLower() == "rm")
                    {
                        strRoleId = "1001";
                    }
                    else if (str.ToLower() == "bm")
                    {
                        strRoleId = "1002";
                    }
                    else if (str.ToLower() == "research")
                    {
                        strRoleId = "1005";
                    }
                    else if (str.ToLower() == "ops")
                    {
                        strRoleId = "1004";
                    }
                    else if (str.ToLower() == "customer")
                    {
                        strRoleId = "1003";
                    }
                    sbRoleList.Append(strRoleId);
                    sbRoleList.Append(",");
                }
            }
            else if (userVo.UserType.ToLower() == "customer")
            {
                string strRoleId = "1003";
                sbRoleList.Append(strRoleId);
                sbRoleList.Append(",");
            }

            sbRoleList.Remove(sbRoleList.Length - 1, 1);

            ds = repoBo.GetRepositoryView(userVo.UserId, sbRoleList.ToString());

            if (ds.Tables[0].Rows.Count > 0 && ds.Tables[2].Rows.Count > 0)
            {
                trNoRecords.Visible = false;
                int intAdviserId = 0;
                if (ds.Tables[1].Rows[0]["AdviserId"] != null)
                {
                    intAdviserId = Int32.Parse(ds.Tables[1].Rows[0]["AdviserId"].ToString());
                }
                string strPrevDataRowCategory = string.Empty;
                bool   blNewCategory          = false;
                int    count = 0;
                string strCurrentPageHostAuthority = Request.Url.Authority;


                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (dr["ARC_RepositoryCategoryCode"].ToString() != strPrevDataRowCategory)
                    {
                        blNewCategory = true;
                    }

                    if (blNewCategory)
                    {
                        // increment the count to bind to the different lists based on ListId+count
                        count++;

                        // reset the new category flag
                        blNewCategory = false;

                        // store the new Category
                        strPrevDataRowCategory = dr["ARC_RepositoryCategoryCode"].ToString();

                        // Give the Category Name as the header
                        Label ctrlLabel = (Label)FindControl("lblCategory" + count);
                        if (ctrlLabel != null)
                        {
                            ctrlLabel.Visible = true;
                            ctrlLabel.Text    = dr["ARC_RepositoryCategory"].ToString();
                        }
                    }

                    ListBox ctrlLstBx = (ListBox)FindControl("ListBox" + count);

                    if (ctrlLstBx != null)
                    {
                        ctrlLstBx.Visible = true;
                        string strLink = string.Empty;
                        if (dr["AR_IsFile"].ToString().ToLower() == Boolean.TrueString.ToLower())
                        {
                            strLink = "~//" + strRepositoryPath + "//advisor_" + intAdviserId.ToString() + "////" + dr["AR_Filename"].ToString();
                            strLink = this.ResolveUrl(strLink);
                            ctrlLstBx.Items.Add(new ListItem(dr["AR_HeadingText"].ToString(), strLink));

                            ctrlLstBx.CssClass            = "option";
                            ctrlLstBx.Attributes["style"] = "cursor:pointer;";
                        }
                        else
                        {
                            strLink = dr["AR_Link"].ToString();
                            ctrlLstBx.Items.Add(new ListItem(dr["AR_HeadingText"].ToString(), strLink));

                            ctrlLstBx.Attributes["style"] = "cursor:pointer;";
                            ctrlLstBx.CssClass            = "option";
                        }
                    }
                    else
                    {
                        // Error message List Box not found
                    }
                }
            }
            else
            {
                // Display no items on display
                trNoRecords.Visible = true;
            }
        }
Exemple #8
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            bool      blAnyChecked = false;
            bool      blResult     = false;
            DataSet   ds           = new DataSet();
            DataTable dt           = new DataTable();

            dt.Columns.Add("Id");
            dt.Columns.Add("FileName");
            dt.Columns.Add("IsFile");
            DataRow drDelete;

            foreach (GridDataItem item in rgRepositoryList.Items)
            {
                CheckBox chkbxRow = (CheckBox)item.FindControl("chkbxRow");
                if (chkbxRow != null)
                {
                    if (chkbxRow.Checked)
                    {
                        // Update flag for validation message [select atleast one to delete]
                        blAnyChecked = true;

                        drDelete = dt.NewRow();
                        string strKeyValue = item.GetDataKeyValue("AR_RepositoryId").ToString();
                        string strIsFile   = item.GetDataKeyValue("AR_IsFile").ToString();
                        string strFileName = item.GetDataKeyValue("AR_Filename").ToString();
                        drDelete[0] = strKeyValue;
                        drDelete[1] = strFileName;
                        drDelete[2] = strIsFile;
                        dt.Rows.Add(drDelete);
                    }
                }
            }

            dt.TableName = "Table";
            ds.Tables.Add(dt);
            ds.DataSetName = "Deleted";

            if (blAnyChecked)
            {
                #region Put Transaction Scope 3 here

                // Get the system file path. Delete for each id in the dataset
                float  fBalanceStorage = 0.0F;
                string strPath         = Server.MapPath(strRepositoryPath) + "\\advisor_" + advisorVo.advisorId + "\\";
                fBalanceStorage = DeleteRepositoryItems(strPath, ds);

                repoBo   = new RepositoryBo();
                blResult = repoBo.DeleteRepositoryItems(ds.GetXml().ToString(), fBalanceStorage, advisorVo.advisorId);

                if (blResult)
                {
                    // Store the fBalanceStorage in advisor session and update the database
                    advisorVo.SubscriptionVo.StorageBalance = fBalanceStorage;
                    Session[SessionContents.AdvisorVo]      = advisorVo;
                    rgRepositoryList.Rebind();
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "Repository", "alert('Items deleted successfully!');", true);
                }
                else
                {
                    rgRepositoryList.Rebind();
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "Repository", "alert('Error deleting items!');", true);
                }

                #endregion
            }
            else
            {
                // Display validation message that atleast one checkbox should be checked
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "Repository", "alert('Please select an item!');", true);
            }
        }
Exemple #9
0
        private bool UpdateFile(out bool blZeroBalance, out bool blFileSizeExceeded)
        {
            repoBo = new RepositoryBo();
            bool blResult = false;

            blZeroBalance      = false;
            blFileSizeExceeded = false;

            try
            {
                // Reading File Upload Control
                int intUploadedFileCount = radUploadRepoItem.UploadedFiles.Count;

                if (intUploadedFileCount == 0)
                {
                    // normal update
                    repoVo.Description = txtDescription.Text.Trim();
                    repoVo.HeadingText = txtHeadingText.Text.Trim();
                    repoVo.Link        = String.Empty;
                    blResult           = repoBo.UpdateRepositoryItem(repoVo);
                }
                else
                {
                    // delete existing file and update new file

                    // Put this part under a transaction scope
                    using (TransactionScope scope2 = new TransactionScope())
                    {
                        /* Perform transactional work here */

                        UploadedFile file        = radUploadRepoItem.UploadedFiles[0];
                        float        fileSize    = float.Parse(file.ContentLength.ToString()) / 1048576; // Converting bytes to MB
                        float        oldFileSize = 0.0F;

                        if (fileSize <= 2)
                        {
                            // If file size is less than 2 MB then upload

                            // Get the Repository Path in solution
                            string    strFilePath     = Server.MapPath(strRepositoryPath) + "\\advisor_" + advisorVo.advisorId + "\\" + repoVo.Link;
                            float     fStorageBalance = advisorVo.SubscriptionVo.StorageBalance;
                            AdvisorBo advBo           = new AdvisorBo();

                            // Delete file if it exists
                            if (File.Exists(strFilePath))
                            {
                                // Get the file size of the old file to calculate the balance storagee size
                                FileInfo f     = new FileInfo(strFilePath);
                                long     lSize = f.Length;
                                oldFileSize = (lSize / (float)1048576);
                                float flRemainingBal = fStorageBalance + oldFileSize;

                                if (flRemainingBal >= fileSize)
                                {
                                    File.Delete(strFilePath);
                                }
                                else
                                {
                                    blZeroBalance = true;
                                }
                            }

                            if (!blZeroBalance)
                            {
                                // Add new file
                                strRepositoryPath = Server.MapPath(strRepositoryPath) + "\\advisor_" + advisorVo.advisorId;
                                strGuid           = Guid.NewGuid().ToString();

                                // Reading File Upload Control
                                string newFileName = SaveFileIntoServer(file, strGuid, strRepositoryPath);

                                // Update the DB with new details
                                repoVo.Description = txtDescription.Text.Trim();
                                repoVo.HeadingText = txtHeadingText.Text.Trim();
                                repoVo.Link        = newFileName;

                                blResult = repoBo.UpdateRepositoryItem(repoVo);

                                if (blResult)
                                {
                                    // Once updating the repository is a success, then update the balance storage in advisor subscription table
                                    fStorageBalance = UpdateAdvisorStorageBalance(fileSize, oldFileSize, fStorageBalance);
                                }
                            }
                        }
                        else
                        {
                            blFileSizeExceeded = true;
                        }

                        scope2.Complete();
                    }
                }
            }
            catch (BaseApplicationException Ex)
            {
                throw Ex;
            }
            catch (Exception Ex)
            {
                object[] objects = new object[2];
                objects[0] = repoVo;
                objects[1] = repoBo;
                PageException(objects, Ex, "ManageRepository.ascx:UpdateClick()");
            }
            return(blResult);
        }
Exemple #10
0
        private bool AddFile(out bool blZeroBalance, out bool blFileSizeExceeded)
        {
            // If the upload type is file
            // We need to see if the adviser has a folder in Repository folder
            // Case 1: If not, then encode the adviser id and create a folder with the encoded id
            // then create a folder for the repository category within the encoded folder
            // then store the encoded adviserID + GUID + file name
            // Case 2: If folder exists, check if the category folder exists.
            // If not then, create a folder with the category code and store the file as done above.
            // If yes, then just store the file as done above.
            // Once this is done, store the info in the DB with the file path.
            strRepositoryPath = Server.MapPath(strRepositoryPath) + "\\advisor_" + advisorVo.advisorId;
            AdvisorBo advBo = new AdvisorBo();

            repoBo = new RepositoryBo();
            bool blResult = false;

            blZeroBalance      = false;
            blFileSizeExceeded = false;

            try
            {
                // Reading File Upload Control
                if (radUploadRepoItem.UploadedFiles.Count != 0)
                {
                    // Put this part under a transaction scope
                    using (TransactionScope scope1 = new TransactionScope())
                    {
                        UploadedFile file     = radUploadRepoItem.UploadedFiles[0];
                        float        fileSize = float.Parse(file.ContentLength.ToString()) / 1048576; // Converting bytes to MB

                        // If space is there to upload file
                        if (fStorageBalance >= fileSize)
                        {
                            if (fileSize <= 20)   // If upload file size is less than 10 MB then upload
                            {
                                // Check if directory for advisor exists, and if not then create a new directoty
                                if (!Directory.Exists(strRepositoryPath))
                                {
                                    Directory.CreateDirectory(strRepositoryPath);
                                }
                                strGuid = Guid.NewGuid().ToString();
                                string newFileName = SaveFileIntoServer(file, strGuid, strRepositoryPath);
                                repoVo              = new RepositoryVo();
                                repoVo.AdviserId    = advisorVo.advisorId;
                                repoVo.CategoryCode = ddlRCategory.SelectedValue;
                                repoVo.Description  = txtDescription.Text.Trim();
                                repoVo.HeadingText  = txtHeadingText.Text.Trim();
                                repoVo.IsFile       = true;
                                repoVo.Link         = newFileName;
                                if (Request.QueryString["NCDProspect"] != null)
                                {
                                    issueId = Convert.ToInt32(Request.QueryString["issueId"].ToString());
                                }
                                blResult = repoBo.AddRepositoryItem(repoVo, issueId);

                                if (blResult)
                                {
                                    // Once the adding of repository is a success, then update the balance storage in advisor subscription table
                                    fStorageBalance = UpdateAdvisorStorageBalance(fileSize, 0, fStorageBalance);
                                }
                            }
                            else
                            {
                                blFileSizeExceeded = true;
                            }
                        }
                        else
                        {
                            blZeroBalance = true;
                        }

                        scope1.Complete();   // Commit the transaction scope if no errors
                    }
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('Please select a file to upload!');", true);
                }
            }
            catch (BaseApplicationException Ex)
            {
                throw Ex;
            }
            catch (Exception Ex)
            {
                object[] objects = new object[2];
                objects[0] = repoVo;
                objects[1] = repoBo;
                PageException(objects, Ex, "ManageRepository.ascx:AddClick()");
            }
            return(blResult);
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            int     intRepoCount = (int)ViewState["intRepoDSCount"];
            bool    blChanged    = false;
            bool    blResult     = false;
            DataSet dsChanges    = new DataSet();
            DataSet dsCatRole    = new DataSet();

            DataTable dtChanges = new DataTable();

            dtChanges.Columns.Add("AdviserRepositoryCategoryId");
            dtChanges.Columns.Add("RepositoryCategory");
            DataRow drChanges;

            DataTable dtCatRole = new DataTable();

            dtCatRole.Columns.Add("AdviserRepositoryCategoryId");
            dtCatRole.Columns.Add("RoleId");
            DataRow drCatRole;


            //for (int i = 0; i < intRepoCount; i++)
            //{
            //    Label lbl = (Label)this.FindControl("lblCategory" + (i + 1).ToString());
            //    HiddenField hdn = (HiddenField)this.FindControl("hdnCat" + (i + 1).ToString());
            //    TextBox txt = (TextBox)this.FindControl("txtCategory" + (i + 1).ToString());
            //    if (lbl.Text.Trim().ToLower() != txt.Text.Trim().ToLower())
            //    {
            //        blChanged = true;
            //        break;
            //    }
            //}

            //if (blChanged)
            //{

            // Update DB Changes
            for (int i = 0; i < intRepoCount; i++)
            {
                HiddenField hdn = (HiddenField)this.FindControl("hdnCat" + (i + 1).ToString());
                TextBox     txt = (TextBox)this.FindControl("txtCategory" + (i + 1).ToString());
                drChanges    = dtChanges.NewRow();
                drChanges[0] = hdn.Value.Trim();
                drChanges[1] = txt.Text.Trim();
                dtChanges.Rows.Add(drChanges);

                // Update Roles for the Category
                CheckBoxList chkbxlst = (CheckBoxList)this.FindControl("CheckBoxList" + (i + 1).ToString());
                foreach (ListItem li in chkbxlst.Items)
                {
                    if (li.Selected)
                    {
                        drCatRole    = dtCatRole.NewRow();
                        drCatRole[0] = hdn.Value.Trim();
                        drCatRole[1] = li.Value.Trim();
                        dtCatRole.Rows.Add(drCatRole);
                    }
                }
            }

            dtChanges.TableName = "Table";
            dsChanges.Tables.Add(dtChanges);
            dsChanges.DataSetName = "Categories";

            dtCatRole.TableName = "Table2";
            dsCatRole.Tables.Add(dtCatRole);
            dsCatRole.DataSetName = "CategoryRole";

            repoBo   = new RepositoryBo();
            blResult = repoBo.UpdateRepositoryCategoryNames(advisorVo.advisorId, dsChanges.GetXml().ToString(), dsCatRole.GetXml().ToString(), userVo.UserId);

            if (blResult)
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "Repository", "alert('Category names and associated roles updated successfully!');", true);
                BindCategories();
            }
            //}
        }