public string GetReport(Portfolio portfolio, IEnumerable<Category> categories, IEnumerable<CategoryWeight> weights)
        {
            var reportBuilder = new StringBuilder();
            var quotes = GetQuotes(portfolio);
            var valuesDict = CalculateValues(portfolio, quotes);
            var weightsList = weights.ToList();

            //DebugPrint(reportBuilder, valuesDict);

            var total = valuesDict.Values.Where(v => v > 0M).Sum();
            reportBuilder.AppendLine(string.Format("Portfolio: {0}", portfolio.Name));
            foreach (var category in categories)
            {
                Dictionary<string, decimal> calculations = new Dictionary<string, decimal>();

                foreach (var kvpair in valuesDict)
                {
                    var weight = weightsList.Single(w => w.Security.Symbol.Equals(kvpair.Key) && w.Value.Category == category);
                    if (calculations.ContainsKey(weight.Value.Name))
                        calculations[weight.Value.Name] += kvpair.Value;
                    else
                        calculations.Add(weight.Value.Name, kvpair.Value);
                }

                reportBuilder.AppendLine(string.Format("\r\n{0}", category.Name));
                foreach (var kvpair in calculations.OrderByDescending(kv => kv.Value))
                {
                    reportBuilder.AppendLine(String.Format("{0}: {1:N1}%", kvpair.Key, kvpair.Value / total * 100M));
                }
            }

            return reportBuilder.ToString();
        }
Esempio n. 2
0
        public static Dictionary<string, string> GetGroupsDict()
        {
            Dictionary<string, string> groups = new Dictionary<string, string>();

            DataTable gDt = DAL.Groups.ListGroups();
            foreach (DataRow gRow in gDt.Rows)
            {
                if (!groups.ContainsKey(gRow["groupName"].ToString()))
                {
                    groups.Add(gRow["groupName"].ToString(), gRow["groupId"].ToString());
                }
            }

            return groups;
        }
Esempio n. 3
0
        /// <summary> 踢出用户
        /// </summary>
        void UCOnLineUser_ShotoffEvent(object sender, EventArgs e)
        {
            try
            {
                if (cmbacc.SelectedIndex == 0)
                {
                    MessageBoxEx.ShowInformation("请选择所属账套");
                    return;
                }

                Dictionary<string, string> dic = new Dictionary<string, string>();
                foreach (DataGridViewRow dr in dgvUser.Rows)
                {
                    object isCheck = dr.Cells["colCheck"].EditedFormattedValue;
                    if (isCheck != null && (bool)isCheck)
                    {
                        string userid = dr.Cells["user_id"].Value.ToString();
                        if (!dic.ContainsKey("userid"))
                        {
                            dic.Add(userid, dr.Cells["land_name"].Value.ToString());
                        }
                    }
                }
                if (dic.Keys.Count == 0)
                {
                    MessageBoxEx.ShowInformation("请选择踢出用户!");
                    return;
                }
                if (MessageBoxEx.ShowQuestion("你确定要将选中用户踢出系统吗?"))
                {
                    string accCode = cmbacc.SelectedValue.ToString();
                    foreach (string str in dic.Keys)
                    {
                        LoginSessionInfo.Instance.ShotOffUser(accCode, str);
                        if (accCode == GlobalStaticObj_Server.CommAccCode)
                        {
                            ClientUser.UserLoginOut(dic[str], accCode);
                        }
                        else
                        {
                            ServerUser.UserLoginOut(dic[str], accCode);
                        }
                    }
                }
                MessageBoxEx.ShowInformation("操作成功");
            }
            catch (Exception ex)
            {
                GlobalStaticObj_Server.GlobalLogService.WriteLog("在线用户", ex);
                MessageBoxEx.ShowWarning("程序异常");
            }
        }
        private static IDictionary<string, decimal> CalculateValues(Portfolio portfolio, IDictionary<string, decimal> quotes)
        {
            var results = new Dictionary<string, decimal>();

            foreach (var account in portfolio.Accounts)
            {
                foreach (var position in account.Positions)
                {
                    try
                    {
                        var price = quotes[position.Security.Symbol];
                        var value = price * position.Shares;
                        if (results.ContainsKey(position.Security.Symbol))
                            results[position.Security.Symbol] += value;
                        else
                            results.Add(position.Security.Symbol, value);
                    }
                    catch (KeyNotFoundException)
                    {
                        results.Add(position.Security.Symbol, -1M);
                    }
                }
            }

            return results;
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            var confirmedItemsQuantity = new Dictionary<int, long>();
            var confirmedItems = new List<int>();
            var valid = ValidateFields();
            if (valid == "true")
            {
                if (XtraMessageBox.Show("Are You Sure, You Want To Save This Transaction?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    var issDoc = new IssueDoc();
                    var recDoc = new ReceiveDoc();
                    DataTable dtConfirm;
                    long currentSOH = 0;
                    var storeId = 0;
                    var itemId = 0;

                    using (dtConfirm = (DataTable)gridConfirmation.DataSource)
                    {
                        for (int i = 0; i < dtConfirm.Rows.Count; i++)
                        {
                           var receivedocid = Convert.ToInt32(dtConfirm.Rows[i]["RecId"]);
                            issDoc.GetDULastIssue(Convert.ToInt32(dtConfirm.Rows[i]["ItemID"]), Convert.ToInt32(cboReceivingUnits.EditValue));
                            confirmedItems.Add(Convert.ToInt32(dtConfirm.Rows[i]["ItemID"]));
                            if (issDoc.RowCount > 0)
                            {
                                //issDoc.DUSOH = ((dtConfirmation.Rows[i]["DUSOH"] != null) ? Convert.ToInt64(dtConfirmation.Rows[i]["DUSOH"]) : 0);
                                //issDoc.Save();
                            }
                            //Saving the issue
                            issDoc.AddNew();
                            issDoc.StoreId = Convert.ToInt32(cboStores.EditValue);
                            issDoc.RefNo = txtRefNo.Text.Trim();
                            issDoc.ReceivingUnitID = Convert.ToInt32(cboReceivingUnits.EditValue);
                            DateTime xx = dtIssueDate.Value;
                            dtIssueDate.CustomFormat = "MM/dd/yyyy";

                            DateTime dtCurrent = ConvertDate.DateConverter(dtIssueDate.Text);
                            issDoc.Date = dtCurrent;
                            dtIssueDate.IsGregorianCurrentCalendar = true;
                            issDoc.EurDate = dtIssueDate.Value;
                            dtIssueDate.IsGregorianCurrentCalendar = false;
                            issDoc.RecievDocID =Convert.ToInt32(dtConfirm.Rows[i]["RecId"]); // Used to have 8 as an index
                            recDoc.LoadByPrimaryKey(receivedocid);
                            issDoc.IsApproved = true;
                            issDoc.IsTransfer = false;

                            issDoc.Remark = txtRemark.Text;
                            issDoc.RecipientName = txtRecipientName.Text;
                            issDoc.IssuedBy = txtIssuedBy.Text;
                            issDoc.DUSOH = Convert.ToInt32(dtConfirm.Rows[i]["DUSOH"]);
                            issDoc.ItemID = Convert.ToInt32(dtConfirm.Rows[i]["ItemId"]);
                            issDoc.Quantity = Convert.ToInt64(dtConfirm.Rows[i]["Quantity"]);

                            issDoc.NoOfPack = Convert.ToInt32(dtConfirm.Rows[i]["No Of Pack"]);
                            issDoc.QtyPerPack = Convert.ToInt32(dtConfirm.Rows[i]["Qty Per Pack"]);
                            switch (VisibilitySetting.HandleUnits)
                            {
                                case 1:
                                    issDoc.UnitID = 0;
                                    break;
                                case 2:
                                    issDoc.UnitID = Convert.ToInt32(dtConfirm.Rows[i]["UnitID"]);
                                    break;
                                default:
                                    issDoc.UnitID = Convert.ToInt32(dtConfirm.Rows[i]["UnitID"]);
                                    break;
                            }
                            issDoc.BatchNo = dtConfirm.Rows[i]["BatchNo"].ToString();
                            issDoc.Cost = Convert.ToDouble(dtConfirm.Rows[i]["Unit Price"]);
                            issDoc.RecomendedQty = Convert.ToInt32(dtConfirm.Rows[i]["DURecomended"]);// ((recQty > 0) ? Convert.ToInt64(recQty) : 0);
                            //End DU
                            issDoc.Save();
                            //updating the receiving doc
                            recDoc.LoadByPrimaryKey(Convert.ToInt32(dtConfirm.Rows[i]["RecId"]));
                            //this line calculates the current SOH
                            recDoc.QuantityLeft = recDoc.QuantityLeft - issDoc.Quantity;
                            currentSOH = currentSOH + recDoc.QuantityLeft;

                            itemId = Convert.ToInt32(dtConfirm.Rows[i]["ItemId"]);
                            var unitId = Convert.ToInt32(dtConfirm.Rows[i]["UnitID"]);
                            if (recDoc.QuantityLeft != 0)
                                recDoc.Out = false;
                            else
                                recDoc.Out = true;

                            if (confirmedItemsQuantity.ContainsKey(itemId))
                                confirmedItemsQuantity[itemId] += recDoc.QuantityLeft;
                            else
                            {
                                confirmedItemsQuantity.Add(itemId, recDoc.QuantityLeft);
                            }
                            recDoc.Save();

                            storeId = Convert.ToInt32(cboStores.EditValue);

                            //Log Activity
                            dtIssueDate.Value = xx;
                            Builder.RefreshAMCValues(storeId, confirmedItemsQuantity,unitId);
                        }

                        //save stockout information for the current item in current store
                        //if current SOH after this issue is 0
                        if (currentSOH == 0)
                        {
                            StockoutLog stockoutLog = new StockoutLog();
                            stockoutLog.AddNew();
                            stockoutLog.StoreID = storeId;
                            stockoutLog.ItemID = itemId;
                            stockoutLog.StartDate = DateTime.Today;
                            stockoutLog.Save();
                        }
                    }
                    XtraMessageBox.Show("Transaction Successfully Saved!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

            }
            else
            {
                XtraMessageBox.Show(valid, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
            xpButton2_Click(sender, e);
            issueGrid.DataSource = null;
            issueGridView.RefreshData();
            RefreshItems();
        }