Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            MethodBase lmth          = MethodBase.GetCurrentMethod();
            string     lsRoutineName = lmth.DeclaringType + "." + lmth.Name;

            Classes.cUser User = new Classes.cUser(Session["Username"].ToString(), "PasswordNotNeeded", Session.SessionID);

            Classes.cCharacter cChar = new Classes.cCharacter();

            cChar.LoadCharacterBySkillSetID(User.LastLoggedInSkillSetID);
            lblCharName.Text = cChar.AKA + " ( " + cChar.SkillSetName + " ) - " + cChar.CampaignName;
            lblAKA.Text      = cChar.AKA;
            lblFullName.Text = cChar.FirstName;
            if (cChar.MiddleName.Trim().Length > 0)
            {
                lblFullName.Text += " " + cChar.MiddleName;
            }
            if (cChar.LastName.Trim().Length > 0)
            {
                lblFullName.Text += " " + cChar.LastName;
            }
            lblFullName.Text.Trim();

            lblRace.Text       = cChar.Race.FullRaceName;
            lblOrigin.Text     = cChar.WhereFrom;
            lblPlayerName.Text = "";

            DataTable  dtCharacterSkills = new DataTable();
            SortedList sParams           = new SortedList();

            sParams.Add("@SkillSetID", cChar.SkillSetID);
            DataSet dsCharInfo = Classes.cUtilities.LoadDataSet("uspGetCharCardSkills", sParams, "LARPortal", Session["UserName"].ToString(), lsRoutineName);

            //            dtCharacterSkills = Classes.cUtilities.LoadDataTable("uspGetCharCardSkills", sParams, "LARPortal", Session["UserName"].ToString(), lsRoutineName);
            dtCharacterSkills = dsCharInfo.Tables[0];
            DataTable dtSkillCosts = dsCharInfo.Tables[1];

            if (dtCharacterSkills.Columns["FullDescription"] == null)
            {
                dtCharacterSkills.Columns.Add(new DataColumn("FullDescription", typeof(string)));
            }

            Classes.cSkillPool skDefault = cChar.SkillPools.Find(x => x.DefaultPool == true);
            object             oCPSpent;
            double             dCPSpent;


//            oCPSpent = dtCharacterSkills.Compute("sum(cpcostpaid)", "CampaignSkillPoolID = " + skDefault.PoolID.ToString());
            oCPSpent = dtSkillCosts.Compute("sum(cpcostpaid)", "CampaignSkillPoolID = " + skDefault.PoolID.ToString());
            double.TryParse(oCPSpent.ToString(), out dCPSpent);

            TableRow  dTotalRow = new TableRow();
            TableCell dcCell    = new TableCell();

            dcCell.CssClass = "TableLabel";
            dcCell.Text     = "Total CP:";
            dTotalRow.Cells.Add(dcCell);

            dcCell      = new TableCell();
            dcCell.Text = cChar.TotalCP.ToString("0.00");
            dTotalRow.Cells.Add(dcCell);

            dcCell          = new TableCell();
            dcCell.CssClass = "TableLabel";
            dcCell.Text     = "Total Spent:";
            dTotalRow.Cells.Add(dcCell);

            dcCell      = new TableCell();
            dcCell.Text = dCPSpent.ToString("0.00");
            dTotalRow.Cells.Add(dcCell);

            dcCell          = new TableCell();
            dcCell.CssClass = "TableLabel";
            dcCell.Text     = "Total Avail:";
            dTotalRow.Cells.Add(dcCell);

            dcCell      = new TableCell();
            dcCell.Text = (cChar.TotalCP - dCPSpent).ToString("0.00");
            dTotalRow.Cells.Add(dcCell);
            tblCharInfo.Rows.Add(dTotalRow);


            List <Classes.cSkillPool> skNotDefault = cChar.SkillPools.FindAll(x => x.DefaultPool == false).OrderBy(x => x.PoolDescription).ToList();

            foreach (Classes.cSkillPool PoolNotDefault in skNotDefault)
            {
//                oCPSpent = dtCharacterSkills.Compute("sum(cpcostpaid)", "CampaignSkillPoolID = " + PoolNotDefault.PoolID.ToString());
                oCPSpent = dtSkillCosts.Compute("sum(cpcostpaid)", "CampaignSkillPoolID = " + PoolNotDefault.PoolID.ToString());
                double.TryParse(oCPSpent.ToString(), out dCPSpent);
                double TotalPoints = cChar.SkillPools.Find(x => x.PoolID == PoolNotDefault.PoolID).TotalPoints;

                dTotalRow           = new TableRow();
                dTotalRow.ForeColor = System.Drawing.Color.FromName(PoolNotDefault.PoolDisplayColor);

                dcCell          = new TableCell();
                dcCell.CssClass = "TableLabel";
                dcCell.Text     = PoolNotDefault.PoolDescription + " Points:";
                dTotalRow.Cells.Add(dcCell);

                dcCell      = new TableCell();
                dcCell.Text = TotalPoints.ToString("0.00");
                dTotalRow.Cells.Add(dcCell);

                dcCell          = new TableCell();
                dcCell.CssClass = "TableLabel";
                dcCell.Text     = "Total Spent:";
                dTotalRow.Cells.Add(dcCell);

                dcCell      = new TableCell();
                dcCell.Text = dCPSpent.ToString("0.00");
                dTotalRow.Cells.Add(dcCell);

                dcCell          = new TableCell();
                dcCell.CssClass = "TableLabel";
                dcCell.Text     = "Total Avail:";
                dTotalRow.Cells.Add(dcCell);

                dcCell      = new TableCell();
                dcCell.Text = (TotalPoints - dCPSpent).ToString("0.00");
                dTotalRow.Cells.Add(dcCell);
                tblCharInfo.Rows.Add(dTotalRow);
            }

            double CPCost;
            double CPSpent = 0.0;

            if (dtCharacterSkills.Columns["CostString"] is null)
            {
                dtCharacterSkills.Columns.Add("CostString", typeof(string));
            }

            foreach (DataRow dSkillRow in dtCharacterSkills.Rows)
            {
                int iSkillID;
                if (int.TryParse(dSkillRow["CharacterSkillID"].ToString(), out iSkillID))
                {
                    Classes.cCharacterSkill cCharacterSkill = cChar.CharacterSkills.Where(x => x.CharacterSkillID == iSkillID).FirstOrDefault();
                    dSkillRow["CostString"] = cCharacterSkill.CostString();
                }

                if (double.TryParse(dSkillRow["CPCostPaid"].ToString(), out CPCost))
                {
                    CPSpent += CPCost;
                }

                string FullDesc = "";
                bool   bDisplay;

                if (dSkillRow["AddInfoValue"].ToString().Length > 0)
                {
                    FullDesc += dSkillRow["AddInfoValue"].ToString() + "; ";
                }

                if (bool.TryParse(dSkillRow["CardDisplayDescription"].ToString(), out bDisplay))
                {
                    if (bDisplay)
                    {
                        if (dSkillRow["SkillCardDescription"].ToString().Trim().Length > 0)
                        {
                            FullDesc += dSkillRow["SkillCardDescription"].ToString().Trim() + "; ";
                        }
                    }
                }

                if (dSkillRow["PlayerDescription"].ToString().Trim().Length > 0)
                {
                    FullDesc += dSkillRow["PlayerDescription"].ToString().Trim() + "; ";
                }

                if (bool.TryParse(dSkillRow["CardDisplayIncant"].ToString(), out bDisplay))
                {
                    if (bDisplay)
                    {
                        if (dSkillRow["SkillIncant"].ToString().Trim().Length > 0)
                        {
                            FullDesc += "<i>" + dSkillRow["SkillIncant"].ToString().Trim() + "</i>; ";
                        }
                    }
                }

                if (dSkillRow["PlayerIncant"].ToString().Trim().Length > 0)
                {
                    FullDesc += "<b><i>" + dSkillRow["PlayerIncant"].ToString().Trim() + "</b></i>";
                }

                FullDesc = FullDesc.Trim();
                if (FullDesc.EndsWith(";"))
                {
                    FullDesc = FullDesc.Substring(0, FullDesc.Length - 1);
                }

                dSkillRow["FullDescription"] = FullDesc;
            }

            foreach (Classes.cCharacterSkill Cost in cChar.CharacterSkills)
            {
                string t = Cost.CostString();
            }

            Dictionary <string, string> NonCost = new Dictionary <string, string>();

            foreach (Classes.cDescriptor Desc in cChar.Descriptors)
            {
                if (NonCost.ContainsKey(Desc.CharacterDescriptor))
                {
                    NonCost[Desc.CharacterDescriptor] += Desc.DescriptorValue + ", ";
                }
                else
                {
                    NonCost.Add(Desc.CharacterDescriptor, Desc.DescriptorValue + ", ");
                }
            }

            foreach (string KeyValue in NonCost.Keys.ToList())
            {
                if (NonCost[KeyValue].EndsWith(", "))
                {
                    NonCost[KeyValue] = NonCost[KeyValue].Substring(0, NonCost[KeyValue].Length - 2);
                }
            }

            gvSkills.DataSource = dtCharacterSkills;
            gvSkills.DataBind();

            gvNonCost.DataSource = NonCost;
            gvNonCost.DataBind();

            lblPlayerName.Text = User.FirstName + " " + User.MiddleName + " " + User.LastName;
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            int iCharID;

            if (Session["SelectedCharacter"] != null)
            {
                if (int.TryParse(Session["SelectedCharacter"].ToString(), out iCharID))
                {
                    DataTable dtCampaignSkills = Session["SkillNodes"] as DataTable;

                    Classes.cCharacter Char = new Classes.cCharacter();
                    Char.LoadCharacter(iCharID);

                    int CharacterSkillsSetID = -1;

                    CharacterSkillsSetID = Char.CharacterSkillSetID;

                    foreach (Classes.cCharacterSkill cSkill in Char.CharacterSkills)
                    {
                        cSkill.RecordStatus  = Classes.RecordStatuses.Delete;
                        CharacterSkillsSetID = cSkill.CharacterSkillSetID;
                    }

                    foreach (TreeNode SkillNode in tvSkills.CheckedNodes)
                    {
                        int iSkillNodeID;
                        if (int.TryParse(SkillNode.Value, out iSkillNodeID))
                        {
                            var FoundRecord = Char.CharacterSkills.Find(x => x.CampaignSkillNodeID == iSkillNodeID);
                            if (FoundRecord != null)
                            {
                                FoundRecord.RecordStatus = Classes.RecordStatuses.Active;
                            }
                            else
                            {
                                Classes.cCharacterSkill Newskill = new Classes.cCharacterSkill();
                                Newskill.CharacterSkillID    = -1;
                                Newskill.CharacterID         = iCharID;
                                Newskill.CampaignSkillNodeID = iSkillNodeID;
                                Newskill.CharacterSkillSetID = CharacterSkillsSetID;
                                Newskill.CPCostPaid          = 0;
                                DataView dvCampaignSkill = new DataView(dtCampaignSkills, "CampaignSkillNodeID = " + iSkillNodeID.ToString(), "", DataViewRowState.CurrentRows);
                                if (dvCampaignSkill.Count > 0)
                                {
                                    double dSkillCPCost = 0;
                                    if (double.TryParse(dvCampaignSkill[0]["SkillCPCost"].ToString(), out dSkillCPCost))
                                    {
                                        Newskill.CPCostPaid = dSkillCPCost;
                                    }
                                }
                                Char.CharacterSkills.Add(Newskill);
                            }
                        }
                    }

                    string Msg = Char.SaveCharacter(Session["UserName"].ToString(), (int)Session["UserID"]);

                    lblPopMessage.Text = "Character " + Char.AKA + " has been saved.";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openModal();", true);
                }
            }
        }