Exemple #1
0
        /// <summary>
        /// 全盘分析
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="dt"></param>
        /// <param name="lockname"></param>
        /// <param name="starttime"></param>
        /// <param name="endtime"></param>
        /// <returns></returns>
        public RecordGolable totalAnalysis(out string msg, DataTable dt, string lockname, string starttime, string endtime)
        {
            RecordGolable           recordGolable = new RecordGolable();
            List <userinfoAnalysis> userinfolist  = new List <userinfoAnalysis>();

            msg = string.Empty;
            string _and        = " and ";
            int    _yeat       = DateTime.Parse(endtime).Year;
            int    _startMonth = DateTime.Parse(starttime).Month;
            int    _endMonth   = DateTime.Parse(endtime).Month;

            try
            {
                //所有用户正常次数总和
                int normal = 0;
                //所有用户异常次数总和
                int exception = 0;
                //所有用户次数总和
                int total = 0;
                //读取用户信息
                List <userDetails> userDetails = RedvelopRecord.GetInstance().getuserDetails(out msg);
                if (msg != "")
                {
                    return(recordGolable);
                }
                foreach (userDetails userinfo in userDetails)
                {
                    List <analysisdata> analysisdataslist = new List <analysisdata>();
                    if (userinfo._useName == "")
                    {
                        continue;
                    }
                    string username = userinfo._useName;

                    //该用户所有正常次数
                    int allnormaltimes = 0;
                    //该用户所有异常次数
                    int allexceptiontimes = 0;
                    //该用户所有次数
                    int alltotaltimes = 0;
                    //该用户异常次数情况占比(与所有总异常次数比)
                    string abnormaloccupancyrate = string.Empty;

                    //时间节点
                    for (int m = 1; m <= (_endMonth - _startMonth) + 1; m++)
                    {
                        AnalysisData analysisData = new AnalysisData();
                        //门锁名称
                        string sqlstr = string.Empty;
                        if (string.IsNullOrEmpty(lockname))
                        {
                            MessageBox.Show("未选择门锁", "提示");
                            msg = "未选择门锁";
                            return(null);
                        }
                        if (string.IsNullOrEmpty(starttime) || string.IsNullOrEmpty(endtime))
                        {
                            MessageBox.Show("时间段选择不正确", "提示");
                            msg = "时间段选择不正确";
                            return(null);
                        }
                        if (!string.IsNullOrEmpty(lockname))
                        {
                            sqlstr += "lockmodifyname like '%" + lockname + "%' ";
                        }
                        sqlstr += _and;
                        if (!string.IsNullOrEmpty(starttime) && !string.IsNullOrEmpty(endtime))
                        {
                            sqlstr += "openlocktime > '" + DateTime.Parse(_yeat + "-" + (_startMonth + m - 1).ToString()) + "' " + _and +
                                      " openlocktime < '" + DateTime.Parse(_yeat + "-" + (_startMonth + m).ToString()) + "' ";

                            if (!string.IsNullOrEmpty(username))
                            {
                                sqlstr += _and;
                            }
                        }
                        if (!string.IsNullOrEmpty(username))
                        {
                            sqlstr += "username = '******' ";
                        }


                        RecordLog.GetInstance().WriteLog(Level.Info, string.Format("执行sql简化语句:{0}", sqlstr));
                        DataRow[] drs = dt.Select(sqlstr);

                        analysisdata analysisdata = new analysisdata();
                        if (drs.Count() != 0)
                        {
                            //开门总次数
                            int totaltimes = drs.Count();
                            //异常总次数
                            int exceptiontimes = 0;
                            foreach (DataRow dw in drs)
                            {
                                if ("异常" == dw[13].ToString())
                                {
                                    exceptiontimes++;
                                }
                            }
                            //正常总次数
                            int normaltimes = totaltimes - exceptiontimes;
                            //异常率
                            double ayt = (double)0;
                            if ((double)exception == 0)
                            {
                                ayt = (double)0;
                            }
                            else
                            {
                                ayt = (double)exceptiontimes / (double)totaltimes;
                            }
                            decimal outtemp         = Math.Round(Convert.ToDecimal(ayt), 2, MidpointRounding.AwayFromZero);
                            string  abnormalityrate = ((int)(outtemp * 100)).ToString() + "%";

                            analysisdata = new analysisdata {
                                normaltimes     = normaltimes,
                                exceptiontimes  = exceptiontimes,
                                totaltimes      = totaltimes,
                                abnormalityrate = abnormalityrate,
                            };

                            allnormaltimes    += normaltimes;
                            allexceptiontimes += exceptiontimes;
                            alltotaltimes     += totaltimes;
                        }
                        analysisdata.month = _startMonth + m - 1;
                        analysisdataslist.Add(analysisdata);
                    }
                    normal    += allnormaltimes;
                    exception += allexceptiontimes;
                    total     += alltotaltimes;

                    userinfolist.Add(new userinfoAnalysis
                    {
                        name              = username,
                        analysisdata      = analysisdataslist,
                        allnormaltimes    = allnormaltimes,
                        allexceptiontimes = allexceptiontimes,
                        alltotaltimes     = alltotaltimes
                    });
                }
                recordGolable._analysisData.normal    = normal;
                recordGolable._analysisData.exception = exception;
                recordGolable._analysisData.total     = total;

                string abnormaloccupancyrateTmp = string.Empty;
                foreach (userDetails userinfo in userDetails)
                {
                    foreach (var user in userinfolist)
                    {
                        if (user.name == userinfo._useName)
                        {
                            double ayt = (double)0;
                            if ((double)exception == 0)
                            {
                                ayt = (double)0;
                            }
                            else
                            {
                                ayt = (double)user.allexceptiontimes / (double)exception;
                            }
                            decimal outtemp = Math.Round(Convert.ToDecimal(ayt), 2, MidpointRounding.AwayFromZero);
                            user.abnormaloccupancyrate = ((int)(outtemp * 100)).ToString() + "%";
                            recordGolable._analysisData.userinfo.Add(user);
                        }
                    }
                }
                msg = "Success";
                return(recordGolable);
            }
            catch (Exception ex)
            {
                RecordLog.GetInstance().WriteLog(Level.Error, "Ecxeption:" + ex.Message);
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// 统计分析
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="dt"></param>
        /// <param name="lockname"></param>
        /// <param name="starttime"></param>
        /// <param name="endtime"></param>
        /// <param name="username"></param>
        public RecordGolable StatisticalAnalysis(out string msg, DataTable dt, string lockname, string starttime, string endtime, string username)
        {
            RecordGolable recordGolable = new RecordGolable();

            msg = string.Empty;
            string _and        = " and ";
            int    _yeat       = DateTime.Parse(endtime).Year;
            int    _startMonth = DateTime.Parse(starttime).Month;
            int    _endMonth   = DateTime.Parse(endtime).Month;

            try
            {
                //时间节点
                for (int m = 1; m <= (_endMonth - _startMonth) + 1; m++)
                {
                    Monthlydisplay      monthlydisplay      = new Monthlydisplay();
                    StatisticalAnalysis statisticalAnalysis = new StatisticalAnalysis();
                    //门锁名称
                    string sqlstr = string.Empty;
                    if (string.IsNullOrEmpty(lockname))
                    {
                        MessageBox.Show("未选择门锁", "提示");
                        msg = "未选择门锁";
                        return(null);
                    }
                    if (string.IsNullOrEmpty(username))
                    {
                        MessageBox.Show("用户不能为空", "提示");
                        msg = "用户不能为空";
                        return(null);
                    }
                    if (string.IsNullOrEmpty(starttime) || string.IsNullOrEmpty(endtime))
                    {
                        MessageBox.Show("时间段选择不正确", "提示");
                        msg = "时间段选择不正确";
                        return(null);
                    }
                    if (!string.IsNullOrEmpty(lockname))
                    {
                        sqlstr += "lockmodifyname like '%" + lockname + "%' ";
                    }
                    sqlstr += _and;
                    if (!string.IsNullOrEmpty(starttime) && !string.IsNullOrEmpty(endtime))
                    {
                        sqlstr += "openlocktime > '" + DateTime.Parse(_yeat + "-" + (_startMonth + m - 1).ToString()) + "' " + _and +
                                  " openlocktime < '" + DateTime.Parse(_yeat + "-" + (_startMonth + m).ToString()) + "' ";
                        if (!string.IsNullOrEmpty(username))
                        {
                            sqlstr += _and;
                        }
                    }
                    if (!string.IsNullOrEmpty(username))
                    {
                        sqlstr += "username = '******' ";
                    }


                    RecordLog.GetInstance().WriteLog(Level.Info, string.Format("执行sql简化语句:{0}", sqlstr));
                    DataRow[] drs = dt.Select(sqlstr);

                    if (drs.Count() != 0)
                    {
                        //此人此月开门总次数
                        int totaltimes = drs.Count();
                        //此人此月开门异常总次数
                        int    exception = 0;
                        string userjob   = string.Empty;
                        if (drs[0][6].ToString() == username)
                        {
                            userjob = drs[0][7].ToString();
                        }
                        foreach (DataRow dw in drs)
                        {
                            if ("异常" == dw[13].ToString())
                            {
                                exception++;
                            }
                        }
                        statisticalAnalysis = new StatisticalAnalysis
                        {
                            UserName             = username,
                            UserJob              = userjob,
                            ExcetptionTotalTimes = exception,
                            SuccessTotalTimes    = totaltimes - exception,
                            TotalTimes           = totaltimes
                        };
                    }
                    monthlydisplay.dicmonth.Add("Month", _startMonth + m - 1);
                    monthlydisplay.dicstatus.Add("Data", statisticalAnalysis);
                    recordGolable._monthlydisplaysList.Add(monthlydisplay);
                }
                msg = "Success";
                return(recordGolable);
            }
            catch (Exception ex)
            {
                RecordLog.GetInstance().WriteLog(Level.Error, "Ecxeption:" + ex.Message);
                return(null);
            }
        }