コード例 #1
0
ファイル: ReportController.cs プロジェクト: BriseLee/test
        public ActionResult Entrust()
        {
            var accountId = 0;
            string UserName = AdminProduct.Utils.Converter.ToString(Request.QueryString["UserName"], "");
            string ProductName = AdminProduct.Utils.Converter.ToString(Request.QueryString["ProductName"], "");
            int productid = AdminProduct.Utils.Converter.ToInt(Request.QueryString["productid"], 0);
            int status = AdminProduct.Utils.Converter.ToInt(Request.QueryString["status"], -1);
            string startdate = AdminProduct.Utils.Converter.ToString(Request.QueryString["startdate"], "");
            string enddate = AdminProduct.Utils.Converter.ToString(Request.QueryString["enddate"], "");
            string AccountId = AdminProduct.Utils.Converter.ToString(Request.QueryString["AccountId"]);
            using (APIDataDataContext db = APIDataContextProxy.APIDB)
            {
                var ls = db.TAgents.Where(d => d.Account == AccountId.Split('-')[0]).FirstOrDefault();
                if (ls != null)
                {
                    accountId = ls.ID;
                }
                var orders = (from c in db.TOrders
                              join b in db.TRealAccounts on c.TRealAccountsID equals b.ID
                              join a in db.TProducts on c.ProductID equals a.ID
                              where c.OrderType == 0 && b.AccountType == 1
                              orderby c.OpenTime descending
                              select new
                              {
                                  c.ID,
                                  c.OrderNum,
                                  c.ProductID,
                                  c.TRealAccountsID,
                                  c.Deal,
                                  c.OrderCount,
                                  c.OpenPrice,
                                  c.Profit,
                                  c.Loss,
                                  c.NowPrice,
                                  c.ProfitAndLoss,
                                  c.Spread,
                                  c.Deposit,
                                  c.Interest,
                                  c.OccupyFunds,
                                  c.NetProfit,
                                  c.OpenTime,
                                  c.UpdateTime,
                                  c.OperatorIP,
                                  c.OrderState,
                                  c.OrderType,
                                  b.Name,
                                  b.AccountMoney,
                                  a.ProductName,
                                  //  d.LastClose,
                                  //   a.ContractNumber
                              });
                if (!string.IsNullOrEmpty(UserName))
                {
                    orders = from c in orders
                             join b in db.TRealAccounts on c.TRealAccountsID equals b.ID
                             where b.Account.ToUpper().Contains(UserName.Split('-')[0].ToUpper())
                             select c;
                }
                else
                {
                    if (!string.IsNullOrEmpty(AccountId))
                    {
                        orders = orders.Where(c => c.TRealAccountsID == accountId);

                    }
                }
                if (!string.IsNullOrEmpty(ProductName))
                {
                    orders = from c in orders
                             join b in db.TProducts on c.ProductID equals b.ID
                             where b.ProductName.ToUpper().Contains(ProductName.ToUpper())
                             select c;
                }
                if (productid > 0)
                {
                    orders = orders.Where(c => c.ProductID == productid);
                }
                if (status >= 0)
                {

                    bool aa = status == 1;
                    orders = orders.Where(c => c.Deal == aa);
                }
                if (!string.IsNullOrEmpty(startdate))
                {
                    try
                    {
                        DateTime sd = DateTime.Parse(startdate);
                        orders = orders.Where(c => c.OpenTime >= sd);
                    }
                    catch { }
                }
                if (!string.IsNullOrEmpty(enddate))
                {
                    try
                    {
                        DateTime sd = DateTime.Parse(enddate);
                        orders = orders.Where(c => c.OpenTime <= sd);
                    }
                    catch { }
                }

                TAgents sltAgent = new TAgents();
                if (accountId > 0)
                {
                    sltAgent = db.TAgents.Where(a => a.ID == accountId).FirstOrDefault();
                }
                TProducts sltProduct = new TProducts();
                if (productid > 0)
                {
                    sltProduct = db.TProducts.Where(p => p.ID == productid).FirstOrDefault();
                }
                string typeName = "全部";
                if (status == 0)
                {
                    typeName = "卖";
                }
                if (status == 1)
                {
                    typeName = "买";
                }

                NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
                NPOI.SS.UserModel.ISheet sheet = book.CreateSheet();
                int rowIndex = 0;
                NPOI.SS.UserModel.IRow row = sheet.CreateRow(rowIndex);
                row.HeightInPoints = rowHeight;
                row.CreateCell(0).SetCellValue("查询条件");
                row.CreateCell(1).SetCellValue(string.Format("【会员:{0},产品:{1},客户名:{2},交易类型:{3},操作时间段:{4}—{5}】", sltAgent.Account + "--" + sltAgent.AgentName, sltProduct.ProductName, UserName, typeName, startdate, enddate));

                rowIndex++;
                row = sheet.CreateRow(rowIndex);
                row.CreateCell(0).SetCellValue("序号");
                row.CreateCell(1).SetCellValue("合约号");
                row.CreateCell(2).SetCellValue("交易品种");
                row.CreateCell(3).SetCellValue("用户名");
                row.CreateCell(4).SetCellValue("类型");
                row.CreateCell(5).SetCellValue("手数");
                row.CreateCell(6).SetCellValue("委托价");
                row.CreateCell(7).SetCellValue("止盈");
                row.CreateCell(8).SetCellValue("止损");
                row.CreateCell(9).SetCellValue("市场价");
                row.CreateCell(10).SetCellValue("盈亏毛利");
                row.CreateCell(11).SetCellValue("点数");
                //                     row.CreateCell(12).SetCellValue("余额");
                //                     row.CreateCell(13).SetCellValue("净值");
                row.CreateCell(12).SetCellValue("委托时间");
                rowIndex++;
                if (orders != null)
                {
                    foreach (var item in orders)
                    {
                        row = sheet.CreateRow(rowIndex);
                        row.CreateCell(0).SetCellValue(rowIndex);
                        row.CreateCell(1).SetCellValue(item.OrderNum + "");
                        row.CreateCell(2).SetCellValue(item.ProductName + "");
                        row.CreateCell(3).SetCellValue(item.Name + "");
                        row.CreateCell(4).SetCellValue(item.Deal == true ? "买" : "卖");
                        row.CreateCell(5).SetCellValue(Converter.ToFloat(item.OrderCount, 0).ToString("f2"));
                        row.CreateCell(6).SetCellValue(Converter.ToFloat(item.OpenPrice, 0).ToString("f2"));
                        row.CreateCell(7).SetCellValue(Converter.ToFloat(item.Profit, 0).ToString("f2"));
                        row.CreateCell(8).SetCellValue(Converter.ToFloat(item.Loss, 0).ToString("f2"));
                        row.CreateCell(9).SetCellValue(Converter.ToFloat(item.NowPrice, 0).ToString("f2"));
                        row.CreateCell(10).SetCellValue(Converter.ToFloat(item.ProfitAndLoss, 0).ToString("f2"));
                        row.CreateCell(11).SetCellValue(Converter.ToFloat(item.Spread, 0));
                        row.CreateCell(12).SetCellValue(item.UpdateTime + "");
                        rowIndex++;
                    }
                }
                MemoryStream ms = new MemoryStream();
                book.Write(Response.OutputStream);
                Response.ContentEncoding = Encoding.UTF8;
                Response.HeaderEncoding = Encoding.UTF8;
                Response.AddHeader("Content-Disposition", string.Format("attachment;filename=委托单分析{0}.xls", DateTime.Now.ToString("yyyyMMddHHmmssfff")));
                Response.ContentType = "application/ms-excel";
                Response.Flush();
                ms.Close();
                ms.Dispose();
                book = null;
                return new EmptyResult();
            }
        }
コード例 #2
0
ファイル: ReportController.cs プロジェクト: BriseLee/test
        public ActionResult Close()
        {
            int Agentid = 0;
            string OrderNum = AdminProduct.Utils.Converter.ToString(Request.QueryString["OrderNum"], "");
            string userName = AdminProduct.Utils.Converter.ToString(Request.QueryString["UserName"], "");
            string ProductName = AdminProduct.Utils.Converter.ToString(Request.QueryString["ProductName"], "");
            int pageIndex = AdminProduct.Utils.Converter.ToInt(Request.QueryString["pageindex"], 1);
            int productid = AdminProduct.Utils.Converter.ToInt(Request.QueryString["productid"], 0);
            int status = AdminProduct.Utils.Converter.ToInt(Request.QueryString["status"], -1);
            string startdate = AdminProduct.Utils.Converter.ToString(Request.QueryString["startdate"], "");
            string enddate = AdminProduct.Utils.Converter.ToString(Request.QueryString["enddate"], "");
            if (string.IsNullOrEmpty(startdate))
            {
                startdate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + " 00:00:00";
                enddate = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + " 23:59:59";
            }
            string agentid = Utils.Converter.ToString(Request.QueryString["agentid"]);

            using (APIDataDataContext db = APIDataContextProxy.APIDB)
            {
                var ls = db.TAgents.Where(d => d.Account == agentid.Split('-')[0]).FirstOrDefault();
                if (ls != null)
                {
                    Agentid = ls.ID;
                }
                var orders = (from c in db.TOrders
                              join b in db.TRealAccounts on c.TRealAccountsID equals b.ID
                              where c.OrderType == 2 && c.OrderState == 2 && b.AccountType == 1
                              orderby c.UpdateTime descending
                              select c);
                if (!string.IsNullOrEmpty(agentid))
                {
                    List<TAgents> listTR = Converter.getSonAgentByAgentid(Agentid).ToList();
                    List<int> intList = new List<int>();
                    foreach (TAgents item in listTR)
                    {
                        intList.Add(item.ID);
                    }

                    orders = from p in orders
                             join q in db.TRealAccounts on p.TRealAccountsID equals q.ID
                             where intList.Contains((int)q.AgendID)
                             select p;
                }
                if (!string.IsNullOrEmpty(OrderNum))
                {
                    orders = from c in orders
                             where c.OrderNum.ToUpper().Contains(OrderNum.ToUpper())
                             select c;
                }
                if (!string.IsNullOrEmpty(ProductName))
                {
                    orders = from c in orders
                             join b in db.TProducts on c.ProductID equals b.ID
                             where b.ProductName.ToUpper().Contains(ProductName.ToUpper())
                             select c;
                }
                if (productid > 0)
                {
                    orders = orders.Where(c => c.ProductID == productid);
                }
                if (status >= 0)
                {

                    bool aa = status == 1;
                    orders = orders.Where(c => c.Deal == aa);
                }
                if (!string.IsNullOrEmpty(userName))
                {
                    orders = from p in orders
                             join a in db.TRealAccounts on p.TRealAccountsID equals a.ID
                             where a.Name.Contains(userName.Split('-')[0])
                             select p;
                }
                if (!string.IsNullOrEmpty(startdate))
                {
                    try
                    {
                        DateTime sd = DateTime.Parse(startdate);
                        orders = orders.Where(c => c.UpdateTime >= sd);
                    }
                    catch { }
                }
                if (!string.IsNullOrEmpty(enddate))
                {
                    try
                    {
                        DateTime sd = DateTime.Parse(enddate);
                        orders = orders.Where(c => c.UpdateTime <= sd);
                    }
                    catch { }
                }
                var result = orders.ToList();

                TAgents sltAgent = new TAgents();
                if (Agentid > 0)
                {
                    sltAgent = db.TAgents.Where(a => a.ID == Agentid).FirstOrDefault();
                }
                TProducts sltProduct = new TProducts();
                if (productid > 0)
                {
                    sltProduct = db.TProducts.Where(p => p.ID == productid).FirstOrDefault();
                }
                string typeName = "全部";
                if (status == 0)
                {
                    typeName = "卖";
                }
                if (status == 1)
                {
                    typeName = "买";
                }
                NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
                NPOI.SS.UserModel.ISheet sheet = book.CreateSheet();
                sheet.DefaultColumnWidth = 13;
                int rowIndex = 0;
                NPOI.SS.UserModel.IRow row = sheet.CreateRow(rowIndex);
                row.CreateCell(0).SetCellValue("查询条件:");
                row.CreateCell(1).SetCellValue(string.Format("【会员:{0},产品:{1},合约号:{2},客户名:{3},交易类型:{4},操作时间段:{5}—{6}】", sltAgent.Account + "--" + sltAgent.AgentName, sltProduct.ProductName, OrderNum, userName, typeName, startdate, enddate));

                rowIndex++;
                row = sheet.CreateRow(rowIndex);
                row.HeightInPoints = rowHeight;
                double profit = 0f;
                double deposit = 0f;
                double interest = 0f;
                double netprofit = 0f;
                double proloss = 0f;
                row = sheet.CreateRow(rowIndex);
                row.CreateCell(0).SetCellValue("序号");
                row.CreateCell(1).SetCellValue("合约号");
                row.CreateCell(2).SetCellValue("交易品种");
                row.CreateCell(3).SetCellValue("用户名");
                row.CreateCell(4).SetCellValue("类型");
                row.CreateCell(5).SetCellValue("手数");
                row.CreateCell(6).SetCellValue("开仓价");
                row.CreateCell(7).SetCellValue("止盈");
                row.CreateCell(8).SetCellValue("止损");
                row.CreateCell(9).SetCellValue("平仓价");
                row.CreateCell(10).SetCellValue("盈亏毛利");
                row.CreateCell(11).SetCellValue("点数");
                row.CreateCell(12).SetCellValue("加工费");
                row.CreateCell(13).SetCellValue("仓息");
                row.CreateCell(14).SetCellValue("盈亏净利");
                row.CreateCell(15).SetCellValue("开仓时间");
                row.CreateCell(16).SetCellValue("平仓时间");
                row.CreateCell(17).SetCellValue("操作IP");
                row.CreateCell(18).SetCellValue("平仓类型");
                if (orders != null)
                {
                    rowIndex++;
                    foreach (var item in result)
                    {
                        row = sheet.CreateRow(rowIndex);
                        row.HeightInPoints = rowHeight;
                        row.CreateCell(0).SetCellValue(rowIndex);
                        row.CreateCell(1).SetCellValue(item.OrderNum);
                        row.CreateCell(2).SetCellValue(AdminProduct.Utils.Converter.ToProductName(item.ProductID, ""));
                        row.CreateCell(3).SetCellValue(AdminProduct.Utils.Converter.ToUserName(item.TRealAccountsID, ""));
                        row.CreateCell(4).SetCellValue(((bool)item.Deal) ? "买" : "卖");
                        row.CreateCell(5).SetCellValue(item.OrderCount == null ? "0.00" : ((double)item.OrderCount).ToString("f2"));
                        row.CreateCell(6).SetCellValue(item.OpenPrice == null ? "0.00" : ((double)item.OpenPrice).ToString("f2"));
                        row.CreateCell(7).SetCellValue(item.Profit == null ? "0.00" : ((double)item.Profit).ToString("f2"));
                        row.CreateCell(8).SetCellValue(item.Loss == null ? "0.00" : ((double)item.Loss).ToString("f2"));
                        row.CreateCell(9).SetCellValue(item.NowPrice == null ? "0.00" : ((double)item.NowPrice).ToString("f2"));
                        row.CreateCell(10).SetCellValue(item.ProfitAndLoss == null ? "0.00" : ((double)item.ProfitAndLoss).ToString("f2"));
                        row.CreateCell(11).SetCellValue(item.Spread == null ? "0.00" : ((double)item.Spread).ToString("f2"));
                        row.CreateCell(12).SetCellValue(item.Deposit == null ? "0.00" : ((double)item.Deposit).ToString("f2"));
                        row.CreateCell(13).SetCellValue(item.Interest == null ? "0.00" : ((double)item.Interest).ToString("f2"));
                        row.CreateCell(14).SetCellValue(item.NetProfit == null ? "0.00" : ((double)item.NetProfit).ToString("f2"));
                        row.CreateCell(15).SetCellValue(item.OpenTime.ToString());
                        row.CreateCell(16).SetCellValue(item.UpdateTime.ToString());
                        row.CreateCell(17).SetCellValue(item.OperatorIP);
                        row.CreateCell(18).SetCellValue(item.CloseType);
                        profit += Converter.ToFloat(item.Profit, 0);
                        deposit += Converter.ToFloat(item.Deposit, 0);
                        interest += Converter.ToFloat(item.Interest, 0);
                        netprofit += Converter.ToFloat(item.NetProfit, 0);
                        proloss += Converter.ToFloat(item.ProfitAndLoss, 0);
                        rowIndex++;
                    }
                }
                row = sheet.CreateRow(rowIndex);
                row.HeightInPoints = rowHeight;
                row.CreateCell(0).SetCellValue(string.Format("总计:合约数:{0},盈亏毛利:{1},加工费:{2},利息:{3}盈亏净利:{4}", result.Count, proloss, deposit, interest, netprofit));
                MemoryStream ms = new MemoryStream();
                book.Write(Response.OutputStream);
                Response.ContentEncoding = Encoding.UTF8;
                Response.HeaderEncoding = Encoding.UTF8;
                Response.AddHeader("Content-Disposition", string.Format("attachment;filename=交易历史{0}.xls", DateTime.Now.ToString("yyyyMMddHHmmssfff")));
                Response.ContentType = "application/ms-excel";
                Response.Flush();
                ms.Close();
                ms.Dispose();
                book = null;
                return new EmptyResult();
            }
        }
コード例 #3
0
ファイル: SettingController.cs プロジェクト: BriseLee/test
        public ActionResult PostProduct()
        {
            int Id = 0;  //Id
            string name = ""; //登陆名
            string Type = "";  //type
            string msg = "";  //提示信息
            bool fruit = false;  //结果

            if (!Request.IsAjaxRequest())
                return Content("{result:'fail',msg:'非法请求'}");
            int id = Converter.ToInt(Request.Form["id"], 0);
            string pname = Converter.ToString(Request.Form["ProductName"]).Trim();
            string tn = Converter.ToString(Request.Form["TableName"]).Trim();
            string cn = Converter.ToString(Request.Form["ContractNumber"]).Trim();
            string fix = Converter.ToString(Request.Form["Fixedly"]).Trim();
            string scale = Converter.ToString(Request.Form["Scale"]).Trim();
            string prof = Converter.ToString(Request.Form["ProfitSize"]).Trim();
            string losize = Converter.ToString(Request.Form["LossSize"]).Trim();
            string ensize = Converter.ToString(Request.Form["EntrustSize"]).Trim();
            int isbuy = Converter.ToInt(Request.Form["IsBuy"], 0);
            int issell = Converter.ToInt(Request.Form["IsSell"], 0);
            int type1 = Converter.ToInt(Request.Form["OccupyFundsType"], 0);
            int type2 = Converter.ToInt(Request.Form["OpenDeposit"], 0);
            int type3 = Converter.ToInt(Request.Form["InterestType"], 0);
            int sortNum = 0;
            string sortNumStr = Request.Form["SortNum"];

            int Base_TCurrencyId = Converter.ToInt(Request.Form["Base_TCurrencyId"], 0);
            int Quote_TCurrencyId = Converter.ToInt(Request.Form["Quote_TCurrencyId"], 0);

            string errMsg = "";
            if (pname == "")
                errMsg += "、产品名称不能为空;";
            if (tn == "")
                errMsg += "、数据来源不能为空;";
            int cn1 = 0;
            if (!int.TryParse(sortNumStr, out sortNum) || sortNum < 0)
                errMsg += "、排列顺序必须为数字且为正整数;";
            if (!int.TryParse(cn, out cn1) || cn1 < 0)
                errMsg += "、合约数必须为大于或等于0的正数;";
            double fix1 = 0;
            if (!double.TryParse(fix, out fix1) || fix1 < 0)
                errMsg += "、交易点差必须为大于或等于0的数;";
            int scale1 = 0;
            if (!int.TryParse(scale, out scale1) || scale1 < 0)
                errMsg += "、小数点必须为大于或等于0的正数;";
            double prof1 = 0;
            if (!double.TryParse(prof, out prof1) || prof1 < 0)
                errMsg += "、止盈距离必须为大于或等于0的数;";
            double losize1 = 0;
            if (!double.TryParse(losize, out losize1) || losize1 < 0)
                errMsg += "、止盈距离必须为大于或等于0的数;";
            double ensize1 = 0;
            if (!double.TryParse(ensize, out ensize1) || ensize1 < 0)
                errMsg += "、挂单距离必须为大于或等于0的数";

            #region 保证金
            double funds = 0;
            if (type1 == 1)
            {
                string funds1 = Converter.ToString(Request.Form["Funds1"]).Trim();
                if (!double.TryParse(funds1, out funds) || funds < 0)
                    errMsg += "、固定保证金数额不能为空;";

            }

            else if (type1 == 2)
            {
                string funds1 = Converter.ToString(Request.Form["Funds2"]).Trim();
                if (!double.TryParse(funds1, out funds) || funds < 0)
                    errMsg += "、浮动保证金比率不能为空;";
            }
            else
                errMsg += "、请选择固定保证金模式;";
            #endregion

            #region 加工费
            double open = 0;
            double close = 0;

            if (type2 == 1)
            {
                string open1 = Converter.ToString(Request.Form["Open1"]).Trim();
                string close1 = Converter.ToString(Request.Form["Close1"]).Trim();
                if (!double.TryParse(open1, out open) || open < 0)
                    errMsg += "、开仓金额不能为空;";
                if (!double.TryParse(close1, out close) || close < 0)
                    errMsg += "、平仓金额不能为空";
            }

            else if (type2 == 2)
            {
                string open2 = Converter.ToString(Request.Form["Open2"]).Trim();
                string close2 = Converter.ToString(Request.Form["Close2"]).Trim();
                if (!double.TryParse(open2, out open) || open < 0)
                    errMsg += "、开仓金额不能为空;";
                if (!double.TryParse(close2, out close) || close < 0)
                    errMsg += "、平仓金额不能为空";
            }
            else
                errMsg += "、请选择固定保证金模式;";
            #endregion

            #region 仓息
            double buy = 0;
            double sell = 0;

            if (type3 == 1)
            {
                string buy1 = Converter.ToString(Request.Form["Buy1"]).Trim();
                string sell1 = Converter.ToString(Request.Form["Sell1"]).Trim();
                if (!double.TryParse(buy1, out buy) || buy < 0)
                    errMsg += "、买单金额不能为空;";
                if (!double.TryParse(sell1, out sell) || sell < 0)
                    errMsg += "、卖单金额不能为空";
            }

            else if (type3 == 2)
            {
                string buy2 = Converter.ToString(Request.Form["Buy2"]).Trim();
                string sell2 = Converter.ToString(Request.Form["Sell2"]).Trim();
                if (!double.TryParse(buy2, out buy) || buy < 0)
                    errMsg += "、买单比率不能为空;";
                if (!double.TryParse(sell2, out sell) || sell < 0)
                    errMsg += "、卖单比率不能为空";
            }
            else
                errMsg += "、请选择仓息模式;";
            #endregion

            if (errMsg.Length > 0)
                return Content("{result:'fail',msg:'" + errMsg + "'}");

            try
            {
                TOperationLog OLog = new TOperationLog();
                OLog.BeforeValue = "";

                //id>0表名是修改
                if (id > 0)
                {
                    APIDataDataContext db = APIDataContextProxy.APIDB;
                    {
                        var entify = (from p in db.TProducts where p.ID != id && p.ProductName.ToLower() == pname.ToLower() select p).FirstOrDefault();

                        int count = (from p in db.TProducts where p.ID != id && p.ProductName.ToLower() == pname.ToLower() select p).Count();

                        if (count > 0)
                            return Content("{result:'fail',msg:'产品名称已存在,不能重复!'}");
                        var entity = db.TProducts.Where(p => p.ID == id).FirstOrDefault();
                        if (entity == null)
                            return Content("{result:'fail',msg:'修改失败,产品不存在!'}");
                        else
                        {
                            OLog.BeforeValue = ObjectToJson.ModelToJson(entity);
                            //var ProductName = (from c in db.TProductName where c.ProductCode == entity.ProductCode select c).FirstOrDefault();
                            //if (ProductName != null)
                            //{
                            //    ProductName.Quote_TCurrencyId = Quote_TCurrencyId;
                            //    ProductName.Base_TCurrencyId = Base_TCurrencyId;
                            //}

                            entity.ProductName = pname;
                            entity.ProductCode = entity.ProductTable = tn;
                            entity.ContractNumber = cn1;
                            entity.Fixedly = fix1;
                            entity.Scale = scale1;
                            entity.ProfitSize = prof1;
                            entity.LossSize = losize1;
                            entity.EntrustSize = ensize1;
                            entity.IsBuy = isbuy == 0 ? false : true;
                            entity.IsSell = issell == 0 ? false : true;
                            entity.OccupyFundsType = type1;
                            entity.OccupyFunds = funds;
                            entity.DepositType = type2;
                            entity.OpenDeposit = open;
                            entity.CloseDeposit = close;
                            entity.InterestType = type3;
                            entity.BuyInterest = buy;
                            entity.IsLook = true;
                            entity.SellInterest = sell;
                            entity.SortNum = sortNum;
                            db.SubmitChanges();

                            OLog.UpdateValue = ObjectToJson.ModelToJson(entity);
                            //写入操作日志
                            OLog.UserID = Convert.ToInt32(Session["ID"]);
                            OLog.UserType = 2;//0 用户 1 会员 2 员工
                            OLog.CreateDate = DateTime.Now;
                            OLog.PageName = "修改交易商品";
                            Converter.InsertOperationLog(OLog);

                            //存入日志
                            Id = Convert.ToInt32(Session["ID"]); //id
                            Type = Session["Type"].ToString();  //类型
                            msg = "修改成功";
                            fruit = true;
                            Converter.InsertLog(Id, name, Type, msg, fruit);

                            return Content("{result:'success',msg:'修改产品信息成功!'}");
                        }
                    }
                }
                else
                {
                    APIDataDataContext db = APIDataContextProxy.APIDB;
                    {
                        int count = (from p in db.TProducts where p.ProductName.ToLower() == pname.ToLower() select p).Count();
                        if (count > 0)
                            return Content("{result:'fail',msg:'产品名称已存在,不能重复!'}");
                        TProducts entity = new TProducts();

                        //var ProductName = (from c in db.TProductName where c.ProductCode == entity.ProductCode select c).FirstOrDefault();
                        //if (ProductName != null)
                        //{
                        //    //ProductName.Quote_TCurrencyId = Quote_TCurrencyId;
                        //    //ProductName.Base_TCurrencyId = Base_TCurrencyId;
                        //}

                        entity.ProductName = pname;
                        entity.ProductCode = entity.ProductTable = tn;
                        entity.ContractNumber = cn1;
                        entity.Fixedly = fix1;
                        entity.Scale = scale1;
                        entity.ProfitSize = prof1;
                        entity.LossSize = losize1;
                        entity.EntrustSize = ensize1;
                        entity.IsBuy = isbuy == 0 ? false : true;
                        entity.IsSell = issell == 0 ? false : true;
                        entity.OccupyFundsType = type1;
                        entity.OccupyFunds = funds;
                        entity.DepositType = type2;
                        entity.OpenDeposit = open;
                        entity.CloseDeposit = close;
                        entity.InterestType = type3;
                        entity.BuyInterest = buy;
                        entity.SellInterest = sell;
                        entity.IsLook = true;
                        entity.SortNum = sortNum;
                        db.TProducts.InsertOnSubmit(entity);
                        db.SubmitChanges();

                        OLog.UpdateValue = ObjectToJson.ModelToJson(entity);
                        //写入操作日志
                        OLog.UserID = Convert.ToInt32(Session["ID"]);
                        OLog.UserType = 2;//0 用户 1 会员 2 员工
                        OLog.CreateDate = DateTime.Now;
                        OLog.PageName = "新增交易商品";
                        Converter.InsertOperationLog(OLog);
                        //存入日志
                        Id = Convert.ToInt32(Session["ID"]); //id
                        Type = Session["Type"].ToString();  //类型
                        msg = "产品增加成功";
                        fruit = true;
                        Converter.InsertLog(Id, name, Type, msg, fruit);

                        return Content("{result:'success',msg:'产品增加成功!'}");
                    }
                }
            }
            catch
            {

                //存入日志
                Id = Convert.ToInt32(Session["ID"]); //id
                Type = Session["Type"].ToString();  //类型
                msg = "产品编辑失败";
                fruit = false;
                Converter.InsertLog(Id, name, Type, msg, fruit);

                return Content("{result:'fail',msg:'出现位置错误,操作失败!'}");
            }
        }
コード例 #4
0
ファイル: ReportController.cs プロジェクト: BriseLee/test
        public ActionResult WareOrder(string agentid, string name, int productid)
        {
            APIDataDataContext db = APIDataContextProxy.APIDB;
            int Agentid = 0;
            var ls = db.TAgents.Where(d => d.Account == agentid.Split('-')[0]).FirstOrDefault();
            if (ls != null)
            {
                Agentid = ls.ID;
            }
            var res = from p in db.TOrders
                      join q in db.TRealAccounts on p.TRealAccountsID equals q.ID
                      join r in db.TProducts on p.ProductID equals r.ID
                      join s in db.TLastClose on r.ProductCode equals s.ProductCode
                      where p.OrderType == 1 && p.OrderState == 1 && q.AccountType == 1
                      orderby p.OpenTime descending
                      select new
                      {
                          p.ID,
                          p.OrderNum,
                          p.ProductID,
                          r.ProductName,
                          q.Name,
                          q.AgendID,
                          AgentName = (from a in db.TAgents where a.ID == q.AgendID select a.AgentName).FirstOrDefault(),
                          AgentAccount = (from b in db.TAgents where b.ID == q.AgendID select b.Account).FirstOrDefault(),
                          p.Deal,
                          p.OrderCount,
                          p.OpenPrice,
                          p.Profit,
                          p.Loss,
                          s.LastClose,
                          p.ProfitAndLoss,
                          p.Deposit,
                          p.Interest,
                          p.OccupyFunds,
                          p.OpenTime,
                          p.OperatorIP
                      };
            if (!string.IsNullOrEmpty(agentid))
            {
                List<TAgents> agents = Converter.getSonAgentByAgentid(Agentid).ToList();
                List<int> ids = new List<int>();
                foreach (TAgents agent in agents)
                {
                    ids.Add(agent.ID);
                }
                res = res.Where(p => ids.Contains((int)p.AgendID));
            }
            if (name != "")
                res = res.Where(p => p.Name.ToLower().Contains(name.Split('-')[0]));
            if (productid > 0)
                res = res.Where(p => p.ProductID == productid);
            double totalProfitLoss = 0f;
            double totalDeposit = 0f;
            double totalInterest = 0f;
            TAgents sltAgent = new TAgents();
            if (Agentid > 0)
            {
                sltAgent = db.TAgents.Where(a => a.ID == Agentid).FirstOrDefault();
            }
            TProducts sltProduct = new TProducts();
            if (productid > 0)
            {
                sltProduct = db.TProducts.Where(p => p.ID == productid).FirstOrDefault();
            }
            NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook();
            NPOI.SS.UserModel.ISheet sheet = book.CreateSheet();
            sheet.DefaultColumnWidth = 13;
            int rowIndex = 0;
            NPOI.SS.UserModel.IRow row = sheet.CreateRow(rowIndex);
            row.HeightInPoints = rowHeight;
            row.CreateCell(0).SetCellValue("查询条件");
            row.CreateCell(1).SetCellValue(string.Format("【会员:{0},产品:{1},客户名:{2}】", sltAgent.Account + "--" + sltAgent.AgentName, sltProduct.ProductName, name));
            rowIndex++;
            row = sheet.CreateRow(rowIndex);
            row.HeightInPoints = rowHeight;
            row.CreateCell(0).SetCellValue("序号");
            row.CreateCell(1).SetCellValue("合约号");
            row.CreateCell(2).SetCellValue("产品名称");
            row.CreateCell(3).SetCellValue("姓名");
            row.CreateCell(4).SetCellValue("会员名称");
            row.CreateCell(5).SetCellValue("会员账号");
            row.CreateCell(6).SetCellValue("类型");
            row.CreateCell(7).SetCellValue("数量");
            row.CreateCell(8).SetCellValue("开仓价");
            row.CreateCell(9).SetCellValue("止盈");
            row.CreateCell(10).SetCellValue("止损");
            row.CreateCell(11).SetCellValue("市场价");
            row.CreateCell(12).SetCellValue("浮动盈亏");
            row.CreateCell(13).SetCellValue("加工费");
            row.CreateCell(14).SetCellValue("利息");
            row.CreateCell(15).SetCellValue("保证金");
            row.CreateCell(16).SetCellValue("开仓日期");
            row.CreateCell(17).SetCellValue("IP");
            if (res != null)
            {
                rowIndex++;
                foreach (var item in res)
                {
                    totalProfitLoss += Converter.ToFloat(item.ProfitAndLoss, 0f);
                    totalDeposit += Converter.ToFloat(item.Deposit, 0f);
                    totalInterest += Converter.ToFloat(item.Interest, 0f);
                    row = sheet.CreateRow(rowIndex);
                    row.HeightInPoints = rowHeight;
                    row.CreateCell(0).SetCellValue(rowIndex);
                    row.CreateCell(1).SetCellValue(item.OrderNum + "");
                    row.CreateCell(2).SetCellValue(item.ProductName);
                    row.CreateCell(3).SetCellValue(item.Name);
                    row.CreateCell(4).SetCellValue(item.AgentName);
                    row.CreateCell(5).SetCellValue(item.AgentAccount);
                    row.CreateCell(6).SetCellValue(item.Deal == true ? "买" : "卖");
                    row.CreateCell(7).SetCellValue(Converter.ToFloat(item.OrderCount));
                    row.CreateCell(8).SetCellValue(Converter.ToFloat(item.OpenPrice));
                    row.CreateCell(9).SetCellValue(Converter.ToFloat(item.Profit));
                    row.CreateCell(10).SetCellValue(Converter.ToFloat(item.Loss));
                    row.CreateCell(11).SetCellValue(Converter.ToFloat(item.LastClose));
                    row.CreateCell(12).SetCellValue(Converter.ToFloat(item.ProfitAndLoss));
                    row.CreateCell(13).SetCellValue(Converter.ToFloat(item.Deposit));
                    row.CreateCell(14).SetCellValue(Converter.ToFloat(item.Interest));
                    row.CreateCell(15).SetCellValue(Converter.ToFloat(item.OccupyFunds));
                    row.CreateCell(16).SetCellValue(Converter.ToFloat(item.OpenTime));
                    row.CreateCell(17).SetCellValue(Converter.ToFloat(item.OperatorIP));
                    rowIndex++;
                }
            }
            row = sheet.CreateRow(rowIndex);
            row.HeightInPoints = rowHeight;
            row.CreateCell(0).SetCellValue(string.Format("总计:合约数:{0},浮动盈亏:{1},加工费:{2},利息:{3}", res.Count(), totalProfitLoss, totalDeposit, totalInterest));

            MemoryStream ms = new MemoryStream();
            book.Write(Response.OutputStream);
            Response.ContentEncoding = Encoding.UTF8;
            Response.HeaderEncoding = Encoding.UTF8;
            Response.AddHeader("Content-Disposition", string.Format("attachment;filename=在手订单{0}.xls", DateTime.Now.ToString("yyyyMMddHHmmssfff")));
            Response.ContentType = "application/ms-excel";
            Response.Flush();
            ms.Close();
            ms.Dispose();
            book = null;
            return new EmptyResult();
        }
コード例 #5
0
ファイル: SettingController.cs プロジェクト: BriseLee/test
        public ActionResult Products()
        {
            int pid = Converter.ToInt(Request.QueryString["pid"], 0);

            string sql = "select ID,ProductName from dbo.[TProducts] where [islook]='true' order by sortnum";
            DataTable dtProducts = APIDataContextProxy.GetTable(null, sql, CommandType.Text);
            ViewData["Products"] = dtProducts;

            sql = "select TableName from TProductName;";
            DataTable dt = APIDataContextProxy.GetTable(null, sql, CommandType.Text);
            ViewData["TableName"] = dt;

            TProducts model = new TProducts();
            APIDataDataContext db2 = APIDataContextProxy.APIDB;
            var Currency = (from c in db2.TCurrency select c).ToList();

            ViewData["Currency"] = Currency;
            //ViewData["Base_TCurrencyId"] = 0;
            //ViewData["Quote_TCurrencyId"] = 0;
            if (pid > 0)
            {
                APIDataDataContext db = APIDataContextProxy.APIDB;
                {
                    var res = db.TProducts.Where(p => p.ID == pid).FirstOrDefault();
                    if (res != null)
                    {
                        var ProductName = db.TProductName.Where(p => p.ProductCode == res.ProductCode).FirstOrDefault();

                        //ViewData["Base_TCurrencyId"] = ProductName.Base_TCurrencyId;
                        //ViewData["Quote_TCurrencyId"] = ProductName.Quote_TCurrencyId;
                        model = res;
                    }
                    else
                        return Content("<h1>产品不存在!</h1>");
                }
            }

            ViewData.Model = model;
            return View();
        }