Esempio n. 1
0
        public static void UpdatePayEst(int ledger)
        {
            YDS6000.BLL.DataProcess.PayEstBLL bll = new YDS6000.BLL.DataProcess.PayEstBLL(ledger, Config.Uid);
            //
            DateTime  dtTime     = DateTime.Now;
            DataTable dtRateInfo = bll.GetRateInfo();
            DataTable dtSource   = bll.GetPayEstInfo();

            dtSource.Columns.Add("UseVal", typeof(System.Decimal)); /**/
            dtSource.Columns.Add("UseAmt", typeof(System.Decimal)); /*物业费金额*/
            StringBuilder strFilter = new StringBuilder();
            int           point     = 2;

            #region 计算物业费
            foreach (DataRow dr in dtSource.Rows)
            {
                int     attrib   = CommFunc.ConvertDBNullToInt32(dr["Attrib"]);
                int     isDefine = CommFunc.ConvertDBNullToInt32(dr["IsDefine"]);
                int     bank     = CommFunc.ConvertDBNullToInt32(dr["Bank"]);
                int     isCtl    = CommFunc.ConvertDBNullToInt32(dr["IsCtl"]);
                decimal area     = CommFunc.ConvertDBNullToDecimal(dr["Area"]);
                int     rate_id  = CommFunc.ConvertDBNullToInt32(dr["Rate_id"]);
                int     rule     = CommFunc.ConvertDBNullToInt32(dr["Rule"]);
                string  unit     = CommFunc.ConvertDBNullToString(dr["Unit"]);
                decimal unitBase = CommFunc.ConvertDBNullToDecimal(dr["UnitBase"]);
                unitBase = unitBase == 0 ? 1 : unitBase;
                if (rate_id == 0)
                {
                    continue;
                }
                ////////
                ////////
                decimal useAmt = 0;
                #region 计算金额
                if (isCtl == 0)
                {/*使用系统计算*/
                    foreach (DataRow drRate in dtRateInfo.Select("Rate_id=" + rate_id))
                    {
                        string  pStart = CommFunc.ConvertDBNullToString(drRate["PStart"]);
                        string  pEnd   = CommFunc.ConvertDBNullToString(drRate["PEnd"]);
                        decimal price  = CommFunc.ConvertDBNullToDecimal(drRate["Price"]);
                        /////////////////////////////////////////////////////////////////////
                        bool isBindGo = false;

                        if (RateUnit.Area.ToString().Equals(unit))
                        {
                            #region  平方计算
                            if (rule == 0)
                            {
                                isBindGo = true;
                            }
                            else if (rule == 1)
                            { /*按平方的日期计算*/
                                DateTime dtFm = CommFunc.ConvertDBNullToDateTime(pStart);
                                DateTime dtTo = CommFunc.ConvertDBNullToDateTime(pEnd);
                                if (dtTime > dtFm && dtTime <= dtTo)
                                {
                                    isBindGo = true;
                                }
                            }
                            else if (rule == 2)
                            {
                                decimal nStart = CommFunc.ConvertDBNullToDecimal(pStart);
                                decimal nEnd   = CommFunc.ConvertDBNullToDecimal(pEnd);
                                if (area > nStart && area <= nEnd)
                                {
                                    isBindGo = true;
                                }
                            }
                            if (isBindGo == true)
                            {
                                useAmt = Math.Round((area / unitBase) * price, point, MidpointRounding.AwayFromZero);
                            }
                            #endregion
                        }
                        else if (RateUnit.Bank.ToString().Equals(unit))
                        { /*按户数计算*/
                            #region  户数计算
                            if (rule == 0)
                            {
                                isBindGo = true;
                            }
                            else if (rule == 1)
                            { /*按平方的日期计算*/
                                DateTime dtFm = CommFunc.ConvertDBNullToDateTime(pStart);
                                DateTime dtTo = CommFunc.ConvertDBNullToDateTime(pEnd);
                                if (dtTime > dtFm && dtTime <= dtTo)
                                {
                                    isBindGo = true;
                                }
                            }
                            else if (rule == 2)
                            {
                                decimal nStart = CommFunc.ConvertDBNullToDecimal(pStart);
                                decimal nEnd   = CommFunc.ConvertDBNullToDecimal(pEnd);
                                if (bank > nStart && bank <= nEnd)
                                {
                                    isBindGo = true;
                                }
                            }
                            if (isBindGo == true)
                            {
                                useAmt = Math.Round((bank / unitBase) * price, point, MidpointRounding.AwayFromZero);
                            }
                            #endregion
                        }
                        if (isBindGo == true)
                        {
                            break;
                        }
                    }
                }
                else
                {
                }
                #endregion
                dr["UseAmt"] = useAmt;
                ///////
            }
            #endregion

            bll.UpdatePayEst(dtSource);/*更新*/
        }
Esempio n. 2
0
        /// <summary>
        /// 回来能耗统计分析(区间粒度)
        /// </summary>
        /// <param name="selKey">选择的对象</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <returns></returns>
        public DataTable GetYdModuleCollectValList(int co_id, int meter_id, DateTime start, DateTime end)
        {
            StringBuilder splitMdQuery = new StringBuilder();
            DataTable     dtRst        = this.GetYdModuleCollectValTabSchema();
            DataTable     dtSource     = dal.GetYdModuleListParams(co_id, meter_id);

            dtRst.PrimaryKey    = new DataColumn[] { dtRst.Columns["Module_id"], dtRst.Columns["ModuleAddr"] };
            dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] };
            //
            foreach (DataRow dr in dtSource.Rows)
            {
                if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitMdQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["Module_id"]), ",")))
                {
                    if (!string.IsNullOrEmpty(splitMdQuery.ToString()))
                    {
                        splitMdQuery.Append(",");
                    }
                    splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"]));
                }
                DataRow addDr = dtRst.Rows.Find(new object[] { dr["Module_id"], dr["ModuleAddr"] });
                if (addDr == null)
                {
                    addDr = dtRst.NewRow();
                    addDr["Module_id"]  = dr["Module_id"];
                    addDr["ModuleAddr"] = dr["ModuleAddr"];
                    addDr["Start"]      = start;
                    addDr["End"]        = end;
                    addDr["ModuleName"] = dr["ModuleName"];
                    addDr["RoomName"]   = dr["CoName"];
                    addDr["StrcName"]   = dr["CoStrcName"];
                    dtRst.Rows.Add(addDr);
                }
            }
            this.GetYdModuleCollectValData("FirstVal", splitMdQuery.ToString(), start, end, ref dtRst, ref dtSource);
            this.GetYdModuleCollectValData("LastVal", splitMdQuery.ToString(), start, end, ref dtRst, ref dtSource);
            return(dtRst);
        }
Esempio n. 3
0
        /// <summary>
        /// 设置映射关系
        /// </summary>
        /// <param name="Module_id"></param>
        /// <param name="dr"></param>
        /// <returns></returns>
        public int YdModuleOnMapInSave(int Module_id, DataRow dr)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Clear();
            DataTable obj = new DataTable();

            int action = CommFunc.ConvertDBNullToInt32(dr["Action"]);


            if (action == 0 && string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(dr["TagName"])) && CommFunc.ConvertDBNullToInt32(dr["Disabled"]) == 0)
            {
                strSql.Clear();
                strSql.Append("delete from v1_map where Ledger=@Ledger and Module_id=@Module_id and Fun_id=@Fun_id");
                return(SQLHelper.Execute(strSql.ToString(), new { Ledger = this.Ledger, Module_id = Module_id, Fun_id = CommFunc.ConvertDBNullToInt32(dr["Fun_id"]) }));
            }
            else
            {
                strSql.Clear();
                strSql.Append("select count(*) as cnt from v1_map where Ledger=@Ledger and Module_id=@Module_id and Fun_id=@Fun_id");
                obj = SQLHelper.Query(strSql.ToString(), new { Ledger = this.Ledger, Module_id = Module_id, Fun_id = CommFunc.ConvertDBNullToInt32(dr["Fun_id"]) });
                int cnt = obj.Rows.Count > 0 ? CommFunc.ConvertDBNullToInt32(obj.Rows[0]["cnt"]) : 0;
                if (cnt == 0)
                {
                    bool isRun = true;
                    if (action == 1 && string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(dr["DataValue"])) && CommFunc.ConvertDBNullToInt32(dr["Disabled"]) == 0)
                    {
                        isRun = false;
                    }
                    if (isRun == true)
                    {
                        strSql.Clear();
                        strSql.Append("insert into v1_map(Ledger,Module_id,Fun_id,TagName,DataValue,Status,Rmk,Disabled,Update_by,Update_dt)");
                        strSql.Append("values(@Ledger,@Module_id,@Fun_id,@TagName,@DataValue,0,'',@Disabled,@Uid,now())");
                        return(SQLHelper.Execute(strSql.ToString(), new { Ledger = this.Ledger, Module_id = Module_id, Fun_id = CommFunc.ConvertDBNullToInt32(dr["Fun_id"]), TagName = CommFunc.ConvertDBNullToString(dr["TagName"]), DataValue = CommFunc.ConvertDBNullToString(dr["DataValue"]), Disabled = CommFunc.ConvertDBNullToInt32(dr["Disabled"]), Uid = this.SysUid }));
                    }
                }
                else
                {
                    strSql.Clear();
                    strSql.Append("update v1_map set TagName=@TagName,DataValue=@DataValue,Status=0,Disabled=@Disabled,Update_by=@Uid,Update_dt=now()");
                    strSql.Append(" where Ledger=@Ledger and Module_id=@Module_id and Fun_id=@Fun_id");
                    if (action == 1)
                    {
                        strSql.Append(" and (ifnull(Status,0)=0 or (ifnull(Status,0)=1 and DataValue!=@DataValue))");
                    }
                    return(SQLHelper.Execute(strSql.ToString(), new { Ledger = this.Ledger, Module_id = Module_id, Fun_id = CommFunc.ConvertDBNullToInt32(dr["Fun_id"]), TagName = CommFunc.ConvertDBNullToString(dr["TagName"]), DataValue = CommFunc.ConvertDBNullToString(dr["DataValue"]), Disabled = CommFunc.ConvertDBNullToInt32(dr["Disabled"]), Uid = this.SysUid }));
                }
            }
            return(0);
        }
Esempio n. 4
0
 public APIResult GetStationList(string name = "")
 {
     return(baseInfoHelper.GetStationList(0, CommFunc.ConvertDBNullToString(name)));
 }
Esempio n. 5
0
        public void Login()
        {
            string uid     = this.txtName.Text.Trim();
            string passwd1 = this.txtPassword.Text.Trim();

            if (string.IsNullOrEmpty(uid))
            {
                MessageBox.Show("请输入用户名");
                this.txtName.Focus();
                return;
            }
            if (string.IsNullOrEmpty(passwd1))
            {
                MessageBox.Show("请输入密码");
                this.txtPassword.Focus();
                return;
            }
            //
            try
            {
                string name = "", passwd2 = "";
                foreach (var s1 in NCSys.Pro)
                {
                    DataTable dt = bll.GetSys_user(s1.Key, uid);
                    if (dt.Rows.Count > 0)
                    {
                        name    = CommFunc.ConvertDBNullToString(dt.Rows[0]["USign"]).Trim();
                        passwd2 = CommFunc.ConvertDBNullToString(dt.Rows[0]["UPasswd"]).Trim();
                        if (passwd1.Trim().Equals(passwd2.Trim()))
                        {
                            break;
                        }
                    }
                }
                if (string.IsNullOrEmpty(name))
                {
                    MessageBox.Show("用户名不存在");
                    this.txtName.SelectAll();
                    this.txtPassword.Focus();
                    return;
                }
                if (!passwd1.Trim().Equals(passwd2.Trim()))
                {
                    MessageBox.Show("密码错误");
                    this.txtPassword.SelectAll();
                    this.txtPassword.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("错误信息:" + ex.Message);
                return;
            }

            if (txtName.Text == uid && txtPassword.Text == passwd1)
            {
                MessageBox.Show("管理员密码验证成功!", "提示");
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            else
            {
                MessageBox.Show("请输入管理员用户名和密码进行验证", "提示");
                return;
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 采集-保存并发送指令
        /// </summary>
        /// <param name="Cmd"></param>
        /// <param name="Mm_id"></param>
        /// <param name="ModuleName">型号名称</param>
        /// <param name="ModuleType">型号</param>
        /// <param name="Disabled">是否弃用</param>
        /// <param name="ModulePwd">编程密码</param>
        /// <param name="ModuleUid">编程操作人</param>
        /// <param name="Level">密码级别</param>
        /// <param name="Spec">接线方式</param>
        /// <param name="Fty_prod">生产厂家</param>
        /// <param name="IsCharg">计费方式</param>
        /// <param name="Protocol">协议类型</param>
        /// <param name="Pmap"></param>
        /// <returns></returns>
        public APIRst SetYdModelsOnSave(int Cmd, int Mm_id, string ModuleName, string ModuleType, int Disabled, string ModulePwd, string ModuleUid, string Level, string Spec, string Fty_prod, int IsCharg, string Protocol, string Pmap)
        {
            APIRst rst = new APIRst();

            try
            {
                v0_moduleVModel mm = new v0_moduleVModel();
                mm.Mm_id      = Mm_id;
                mm.ModuleName = ModuleName;
                mm.ModuleType = ModuleType;
                mm.Disabled   = Disabled;
                mm.ModulePwd  = ModulePwd == "undefined" || ModulePwd == "null" || ModulePwd == "{ModulePwd}" ? null : ModulePwd;
                mm.ModuleUid  = ModuleUid == "undefined" || ModuleUid == "null" || ModuleUid == "{ModuleUid}" ? null : ModuleUid;
                mm.Level      = Level == "undefined" || Level == "null" || Level == "{Level}" ? null : Level;
                mm.Spec       = Spec == "undefined" || Spec == "null" || Spec == "{Spec}" ? null : Spec;
                mm.Fty_prod   = Fty_prod == "undefined" || Fty_prod == "null" || Fty_prod == "{Fty_prod}" ? null : Fty_prod;
                mm.IsCharg    = IsCharg;
                mm.Protocol   = Protocol;

                if (string.IsNullOrEmpty(mm.ModuleType))
                {
                    throw new Exception("型号不能为空");
                }
                if (string.IsNullOrEmpty(mm.ModuleName))
                {
                    throw new Exception("型号名称不能为空");
                }

                int       cmdNum   = 0;
                DataTable dtSource = JsonHelper.ToDataTable(Pmap);
                bll.SetYdModelsOnSave(mm, dtSource);
                if (Cmd == 1)
                {
                    DataTable dtCmd = bll.GetYdModelsSendCmd(mm.Mm_id);
                    cmdNum = dtCmd.Rows.Count;
                    this.GetYdModelsSendCmd(dtCmd);
                }
                DataTable dtNew = bll.GetYdModelsOnList(mm.Mm_id);
                var       res1  = from s1 in dtNew.AsEnumerable()
                                  select new
                {
                    RowId      = dtSource.Rows.IndexOf(s1) + 1,
                    Mm_id      = CommFunc.ConvertDBNullToInt32(s1["Mm_id"]),
                    ModuleType = CommFunc.ConvertDBNullToString(s1["ModuleType"]),
                    ModuleName = CommFunc.ConvertDBNullToString(s1["ModuleName"]),
                    Spec       = CommFunc.ConvertDBNullToString(s1["Spec"]),
                    Fty_prod   = CommFunc.ConvertDBNullToString(s1["Fty_prod"]),
                    IsCharg    = CommFunc.ConvertDBNullToInt32(s1["IsCharg"]),
                    ModulePwd  = CommFunc.ConvertDBNullToString(s1["ModulePwd"]),
                    ModuleUid  = CommFunc.ConvertDBNullToString(s1["ModuleUid"]),
                    Level      = CommFunc.ConvertDBNullToString(s1["Level"]),
                    Disabled   = CommFunc.ConvertDBNullToInt32(s1["Disabled"]),
                };
                rst.data = res1.ToList();
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("采集-保存并发送指令错误:" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Esempio n. 7
0
        /// <summary>
        /// 设置用户信息
        /// </summary>
        /// <param name="Uid">用户ID</param>
        /// <param name="sAct">操作类型:增加=1,修改=2,删除=3</param>
        /// <param name="Rid">用户权限</param>
        /// <param name="Name">用户名称</param>
        /// <param name="SName">登录名</param>
        /// <param name="Pwd">登录密码</param>
        /// <returns></returns>
        public APIRst SetUser(int Uid, int sAct, int Rid, string Name, string SName, string Pwd, string TelNo)
        {
            APIRst rst = new APIRst();

            try
            {
                int      id   = CommFunc.ConvertDBNullToInt32(Uid);//用户ID号
                int      nAct = CommFunc.ConvertDBNullToInt32(sAct);
                sys_user uu   = new sys_user();
                uu.Uid   = id;
                uu.TelNo = TelNo;
                if (nAct == 2 || nAct == 3)
                {
                    if (Uid == 0)
                    {
                        throw new Exception(" 数据出错,请选择行再重试..");
                    }
                }
                if (nAct == 1 || nAct == 2)
                {
                    uu.Role_id = Rid;   //用户权限
                    uu.UName   = Name;  //用户名称
                    uu.USign   = SName; //登录名
                    uu.UPasswd = Pwd;   //登录密码
                }
                if (nAct != 1 && nAct != 2 && nAct != 3)
                {
                    throw new Exception(" 操作类型错误");
                }
                if (nAct != 3 && string.IsNullOrEmpty(uu.UName))
                {
                    throw new Exception(" 请输入用户名称");
                }
                if (nAct != 3 && uu.Role_id == 0)
                {
                    throw new Exception(" 请选择用户角色");
                }
                if (nAct != 3 && string.IsNullOrEmpty(uu.UPasswd))
                {
                    throw new Exception(" 请输入用户密码");
                }

                if (nAct == 3)
                {
                    bll.DelUser(Uid);
                }
                else
                {
                    bll.EditUser(uu, nAct);
                }
                DataTable dtSource = bll.GetUser(uu.Uid);
                var       res1     = from s1 in dtSource.AsEnumerable()
                                     select new
                {
                    RowId         = CommFunc.ConvertDBNullToInt32(s1["RowId"]),
                    Rid           = CommFunc.ConvertDBNullToInt32(s1["Role_id"]),
                    Ledger        = CommFunc.ConvertDBNullToInt32(s1["Ledger"]),
                    Uid           = CommFunc.ConvertDBNullToInt32(s1["Uid"]),
                    Name          = CommFunc.ConvertDBNullToString(s1["UName"]),
                    Pwd           = CommFunc.ConvertDBNullToString(s1["UPasswd"]),
                    SName         = CommFunc.ConvertDBNullToString(s1["USign"]),
                    RName         = CommFunc.ConvertDBNullToString(s1["Descr"]),
                    TelNo         = CommFunc.ConvertDBNullToString(s1["TelNo"]),
                    Create_by     = CommFunc.ConvertDBNullToInt32(s1["Create_by"]),
                    Create_byName = CommFunc.ConvertDBNullToString(s1["Create_byName"]),
                    Create_dt     = CommFunc.ConvertDBNullToDateTime(s1["Create_dt"]).ToString("yyyy-MM-dd")
                };

                rst.data = res1.ToList();
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("获取充值参数信息错误:" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Esempio n. 8
0
        internal bool GetAlarm()
        {
            DataTable dtSource      = null;
            DataTable dtAlarmConfig = null;

            try
            {
                dtAlarmConfig = bll.GetAlarmConfig();
                int     cnt       = dtAlarmConfig.Rows.Count;
                decimal alarmVal1 = cnt == 0 ? 0 : CommFunc.ConvertDBNullToDecimal(dtAlarmConfig.Rows[0]["CfValue"]);
                string  unit      = cnt == 0 ? "" : CommFunc.ConvertDBNullToString(dtAlarmConfig.Rows[0]["Unit"]);
                dtSource = bll.GetAlarmData(alarmVal1, unit);
            }
            catch (Exception ex)
            {
                FileLog.WriteLog("获取告警数据错误:" + ex.Message + ex.StackTrace);
            }
            //
            if (dtSource == null)
            {
                return(false);
            }
            Thread.Sleep(100);
            int co_idPrev = -9999;

            foreach (DataRow dr in dtSource.Rows)
            {
                int      co_id = CommFunc.ConvertDBNullToInt32(dr["Co_id"]);
                string   coName = CommFunc.ConvertDBNullToString(dr["CoName"]);
                int      chrgType = CommFunc.ConvertDBNullToInt32(dr["ChrgType"]); /*<=1 房间 >1电表*/
                int      isAlarm = CommFunc.ConvertDBNullToInt32(dr["IsAlarm"]);   /*<=1 房间 >1电表*/
                DateTime lastTime = CommFunc.ConvertDBNullToDateTime(dr["LastTime"]);
                int      transferType = CommFunc.ConvertDBNullToInt32(dr["TransferType"]);
                decimal  rdVal = CommFunc.ConvertDBNullToDecimal(dr["RdVal"]);
                decimal  price = CommFunc.ConvertDBNullToDecimal(dr["Price"]);
                decimal  rdAmt = CommFunc.ConvertDBNullToDecimal(dr["RdAmt"]);
                int      module_id = CommFunc.ConvertDBNullToInt32(dr["Module_id"]);
                string   moduleAddr = CommFunc.ConvertDBNullToString(dr["ModuleAddr"]);
                string   moduleName = CommFunc.ConvertDBNullToString(dr["ModuleName"]);
                string   cfKey = "", cfUnit = "";
                decimal  cfValue = 0;
                decimal  cfRule  = 1;
                bool     isRun   = true;
                if (chrgType <= 1 && co_idPrev == co_id)
                {
                    isRun = false;
                }
                co_idPrev = co_id;
                if (isRun == false)
                {
                    continue;
                }
                int ccc = dtAlarmConfig.Rows.Count;
                int crn = 0;
                foreach (DataRow drC in dtAlarmConfig.Rows)
                {/*从大到小排列*/
                    cfKey   = CommFunc.ConvertDBNullToString(drC["CfKey"]);
                    cfValue = CommFunc.ConvertDBNullToDecimal(drC["CfValue"]);
                    cfRule  = CommFunc.ConvertDBNullToDecimal(drC["Rule"]);
                    cfUnit  = CommFunc.ConvertDBNullToString(drC["Unit"]).ToLower();
                    if (pro.Project.Equals("YdXip") && cfKey.Equals("AlarmValOd"))
                    {/*西安培华的拉闸电量*/
                        cfValue = CommFunc.ConvertDBNullToDecimal(dr["OdValue"]);
                    }
                    //if (!cfKey.ToLower().Equals("AlarmValOd".ToLower()))
                    //    cfRule = cfRule == 0 ? 1 : cfRule;
                    decimal comVal  = string.IsNullOrEmpty(cfUnit) || cfUnit.Equals("kWh".ToLower()) ? rdVal : rdAmt;
                    decimal toValue = cfValue;
                    if (crn < ccc - 1)
                    {
                        toValue = CommFunc.ConvertDBNullToDecimal(dtAlarmConfig.Rows[crn + 1]["CfValue"]);
                    }
                    if (cfValue >= comVal && comVal > toValue)
                    {
                        break;
                    }
                    crn = crn + 1;
                }
                //FileLog.WriteLog("电表ID:" + module_id + "地址:" + moduleAddr + "房间:" + coName + "剩余电量:" + rdVal + "告警类型:" + cfKey + "规则:" + cfRule + "告警值:" + cfValue);
                bool sendAlarm = true;
                if (cfKey.ToLower().Equals("AlarmValOd".ToLower()) && isAlarm == 1)
                {     /*拉合闸*/
                    if (CommFunc.ConvertDBNullToInt32(cfRule) == 1)
                    { /*发送拉合闸命令*/
                        sendAlarm = false;
                        try
                        {
                            string key    = pro.ProjectKey + CommFunc.ConvertDBNullToString(dr["LpszSsr"]);
                            RstVar rstVar = MemcachedMgr.GetVal <RstVar>(key);
                            bool   isPass = false;
                            if (rstVar != null && CommFunc.ConvertDBNullToDecimal(rstVar.lpszVal) == 0)
                            {
                                isPass = true;
                            }

                            if (isPass == true)
                            {
                                this.CtorlSsr1(module_id);
                            }
                        }
                        catch (Exception ex)
                        {
                            FileLog.Error("透支电量发送拉合闸命令错误:" + ex.Message + ex.StackTrace);
                        }
                    }
                }
                if (sendAlarm == true)
                {/*发送告警*/
                    cfRule = cfRule == 0 ? 1 : cfRule;
                    v2_alarm_logVModel alarmInfo = this.AlarmInfo(dr, cfValue, cfRule);
                    if (isAlarm == 1)
                    {
                        if (!string.IsNullOrEmpty(EmailUtilities.EmConfig.MailFrom) && !string.IsNullOrEmpty(EmailUtilities.EmConfig.MailSmtpHost) &&
                            !string.IsNullOrEmpty(EmailUtilities.EmConfig.MailSmtpUser) && !string.IsNullOrEmpty(EmailUtilities.EmConfig.MailSmtpPassword)
                            )
                        {/*邮件告警*/
                            this.AlarmEmail(alarmInfo.Log_id, co_id, coName, lastTime, rdVal);
                        }
                        if (!string.IsNullOrEmpty(pro.Sms.ComSmsConfig.ComSms) ||
                            (!string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliAppKey) && !string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliAppSecret) && !string.IsNullOrEmpty(SmsFun.AliSmsConfig.AliSignName))
                            )
                        {/*短信告警*/
                            this.AlarmSms(alarmInfo.Log_id, co_id, moduleName, coName, lastTime, rdVal, rdAmt);
                        }
                        if (!string.IsNullOrEmpty(pro.Wx.WxConfig.WxAPPID))
                        {/*微信告警*/
                         //this.AlarmWx(alarmInfo.Log_id, co_id, coName, lastTime, rdVal);
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 9
0
        private void AlarmSms(long log_id, int co_id, string coName, string moduleName, DateTime lastTime, decimal rdVal, decimal rdAmt)
        {
            List <string> listReceipts = new List <string>();
            string        crmName = "", content = "";
            int           aid = 0, errCode = 0;
            string        errTxt = "";
            string        msg    = "";

            try
            {
                DataTable dtSource = bll.GetAlarm_log_hand(log_id, HdType.AL_Sms.ToString());
                if (dtSource.Rows.Count > 0)
                {
                    aid     = CommFunc.ConvertDBNullToInt32(dtSource.Rows[0]["Aid"]);
                    errCode = CommFunc.ConvertDBNullToInt32(dtSource.Rows[0]["ErrCode"]);
                }
                if (errCode == 1)
                {
                    return;
                }

                DataTable dtCrm = bll.GetCrmOfCo(co_id);
                foreach (DataRow drCrm in dtCrm.Rows)
                {
                    if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(drCrm["MPhone"])))
                    {
                        listReceipts.Add(CommFunc.ConvertDBNullToString(drCrm["MPhone"]));
                    }
                    //if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(drCrm["MPhone"])))
                    //    mphone.Add(CommFunc.ConvertDBNullToString(drCrm["MPhone"]));
                    //if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(drCrm["Email"])))
                    //    listReceipts.Add(CommFunc.ConvertDBNullToString(drCrm["Email"]));
                    crmName = CommFunc.ConvertDBNullToString(drCrm["CrmName"]);
                }
                //object obj = new
                //{
                //    CrmName = crmName,
                //    DateTime = lastTime.ToString("yyyy-MM-dd"),
                //    CoName = coName,
                //    SyAmt = rdAmt.ToString("f2"),
                //    SyVal = rdVal.ToString("f2") + "kWh"
                //};
                object obj = new
                {
                    moduleName = moduleName,
                    rdAmt      = rdAmt.ToString("f2") + "元",
                };
                content = JsonHelper.Serialize(obj);
            }
            catch (Exception ex)
            {
                FileLog.Error("获取告警数据错误:" + ex.Message + ex.StackTrace);
                errTxt = "获取告警用户邮件手机号码错误";
            }
            ////////////////
            bool sue = false;

            if (listReceipts.Count != 0)
            {
                //【电费通知】尊敬的【房间名】用户,您好,您已欠费【具体金额】,请及时缴费。
                if (!string.IsNullOrEmpty(pro.Sms.ComSmsConfig.ComSms))
                {
                    if (rdAmt < 0)
                    {
                        content = "【电费通知】尊敬的【" + coName + "】用户,您好,您已欠费【" + Math.Abs(rdAmt).ToString("f2") + "元】,请及时缴费。";
                    }
                    else
                    {
                        content = "【电费通知】尊敬的【" + coName + "】用户,您好,您已剩余【" + Math.Abs(rdAmt).ToString("f2") + "元】,请及时缴费。";
                    }
                    //content = "你好当前设备:" + moduleName + "余额:" + rdAmt.ToString("f2");
                }
                sue = this.SendSms(listReceipts, content, out msg);
            }
            else
            {
                msg = "无手机号码";
            }
            errTxt  = msg;
            errCode = (sue == true ? 1 : -1);
            bll.AddAV2_alarm_log_hand(log_id, aid, HdType.AL_Sms.ToString(), "", "", errCode, errTxt);
        }
Esempio n. 10
0
 private void GetYdStatusOnLine(DataTable dtSource)
 {
     dtSource.Columns.Add("SsrS", typeof(System.String));
     foreach (DataRow dr in dtSource.Rows)
     {
         RstVar var = null;
         //RstVar varSsr = null;
         int frMd = CommFunc.ConvertDBNullToInt32(dr["FrMd"]);
         //int ssr = -1;
         string   memcachKey    = CommFunc.ConvertDBNullToString(dr["MemcachKey"]);
         string   memcachKeySsr = memcachKey.Replace(".E", ".Ssr");
         string   cachComm      = CommFunc.ConvertDBNullToString(dr["CachComm"]);
         DateTime lastTime      = CommFunc.ConvertDBNullToDateTime(dr["LastTime"]);
         frMd         = frMd == 0 ? 15 : frMd;
         dr["OnLine"] = 0;
         dr["Ssr"]    = -1;
         dr["SsrS"]   = "未知";
         if (lastTime.AddDays(1) < DateTime.Now)
         {
             continue;
         }
         #region 是否在线
         if (!string.IsNullOrEmpty(cachComm))
         {
             var = null; int i = 0;
             while (var == null && ++i < 2)
             {
                 var = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + cachComm);
                 if (var != null)
                 {
                     break;
                 }
                 System.Threading.Thread.Sleep(2);
             }
             if (var != null)
             {
                 dr["OnLine"] = ((int)CommFunc.ConvertDBNullToDecimal(var.lpszVal) == 0) ? 1 : 0;
             }
         }
         else if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(dr["MemcachKey"])))
         {
             var = null; int i = 0;
             while (var == null && ++i < 2)
             {
                 var = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + memcachKey);
                 if (var != null)
                 {
                     //FileLog.WriteLog("key:" + Common.GetMemcachKey + memcachKey + " Val:" + JsonHelper.Serialize(var));
                     break;
                 }
                 else
                 {
                     //FileLog.WriteLog("空值 key:" + Common.GetMemcachKey + memcachKey);
                     //FileLog.WriteLog("空值 SSr key:" + Common.GetMemcachKey + memcachKeySsr);
                 }
                 System.Threading.Thread.Sleep(2);
             }
             if (var != null)
             {
                 DateTime callTime = var.lpszdateTime;
                 if (callTime >= DateTime.Now.AddMinutes(0 - frMd))
                 {
                     dr["OnLine"] = 1;
                 }
             }
         }
         #endregion
         #region 拉合闸状态
         if (!string.IsNullOrEmpty(memcachKeySsr))
         {
             var = null; int i = 0;
             while (var == null && ++i < 2)
             {
                 var = MemcachedMgr.GetVal <RstVar>(WebConfig.MemcachKey + memcachKeySsr);
                 if (var != null)
                 {
                     break;
                 }
                 System.Threading.Thread.Sleep(2);
             }
             if (var != null)
             {
                 int ssr = (int)CommFunc.ConvertDBNullToDecimal(var.lpszVal);
                 //ssr = ssr == 0 ? 0 : 1;
                 dr["Ssr"] = ssr;
                 if (ssr == 0)
                 {
                     dr["SsrS"] = "合闸";
                 }
                 else if (ssr == 129)
                 {
                     dr["SsrS"] = "恶性负载跳闸";
                 }
                 else if (ssr == 130)
                 {
                     dr["SsrS"] = "总功率超限跳闸";
                 }
                 else if (ssr == 132)
                 {
                     dr["SsrS"] = "移相器或半波跳闸";
                 }
                 else if (ssr == 136)
                 {
                     dr["SsrS"] = "定时断电拉闸";
                 }
                 else if (ssr == 144)
                 {
                     dr["SsrS"] = "远程拉闸";
                 }
                 else if (ssr == 160)
                 {
                     dr["SsrS"] = "过流超限跳闸";
                 }
                 else if (ssr == 192)
                 {
                     dr["SsrS"] = "单次功率超限跳闸";
                 }
                 else
                 {
                     dr["SsrS"] = "跳闸";
                 }
             }
         }
         #endregion
         //int i = 0;
         //int onLine = -1;
         //if (!string.IsNullOrEmpty(CommFunc.ConvertDBNullToString(dr["MemcachKey"])))
         //{
         //    while (var == null && ++i < 2)
         //    {
         //        var = MemcachedMgr.GetVal<RstVar>(WebConfig.MemcachKey + memcachKey);
         //        varSsr = MemcachedMgr.GetVal<RstVar>(WebConfig.MemcachKey + memcachKeySsr);
         //        if (var != null || varSsr != null)
         //        {
         //            //FileLog.WriteLog("key:" + WebConfig.MemcachKey + memcachKey + " Val:" + JsonHelper.Serialize(var));
         //            break;
         //        }
         //        else
         //        {
         //            //FileLog.WriteLog("空值 key:" + WebConfig.MemcachKey + memcachKey);
         //            //FileLog.WriteLog("空值 SSr key:" + WebConfig.MemcachKey + memcachKeySsr);
         //        }
         //        System.Threading.Thread.Sleep(2);
         //    }
         //}
         //onLine = 0;
         //if (var != null)
         //{
         //    DateTime callTime = var.lpszdateTime;
         //    if (callTime >= DateTime.Now.AddMinutes(0 - frMd))
         //        onLine = 1;
         //}
         //if (varSsr != null)
         //    ssr = CommFunc.ConvertDBNullToInt32(varSsr.lpszVal);
         //dr["OnLine"] = onLine;
         //dr["Ssr"] = ssr;
     }
 }
Esempio n. 11
0
        public APIResult GetYdModuleUseValList(string selKey, DateTime time, string dataType)
        {
            APIResult rst = new APIResult();

            try
            {
                string[] kk = selKey.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
                int      id = kk.Count() != 2 ? 0 : CommFunc.ConvertDBNullToInt32(kk[1]);
                int      co_id = 0, meter_id = 0;
                if (selKey.Contains("M-"))
                {
                    meter_id = id;
                }
                else
                {
                    co_id = id;
                }
                DataTable dtSource = bll.GetYdModuleUseValList(co_id, meter_id, time, dataType);
                var       res1     = from s1 in dtSource.AsEnumerable()
                                     select new
                {
                    RowId      = dtSource.Rows.IndexOf(s1) + 1,
                    Module_id  = CommFunc.ConvertDBNullToInt32(s1["Module_id"]),
                    ModuleAddr = CommFunc.ConvertDBNullToString(s1["ModuleAddr"]),
                    Cnt        = CommFunc.ConvertDBNullToInt32(s1["Cnt"]),
                    V01        = CommFunc.ConvertDBNullToDecimal(s1["V01"]),
                    V02        = CommFunc.ConvertDBNullToDecimal(s1["V02"]),
                    V03        = CommFunc.ConvertDBNullToDecimal(s1["V03"]),
                    V04        = CommFunc.ConvertDBNullToDecimal(s1["V04"]),
                    V05        = CommFunc.ConvertDBNullToDecimal(s1["V05"]),
                    V06        = CommFunc.ConvertDBNullToDecimal(s1["V06"]),
                    V07        = CommFunc.ConvertDBNullToDecimal(s1["V07"]),
                    V08        = CommFunc.ConvertDBNullToDecimal(s1["V08"]),
                    V09        = CommFunc.ConvertDBNullToDecimal(s1["V09"]),
                    V10        = CommFunc.ConvertDBNullToDecimal(s1["V10"]),
                    V11        = CommFunc.ConvertDBNullToDecimal(s1["V11"]),
                    V12        = CommFunc.ConvertDBNullToDecimal(s1["V12"]),
                    V13        = CommFunc.ConvertDBNullToDecimal(s1["V13"]),
                    V14        = CommFunc.ConvertDBNullToDecimal(s1["V14"]),
                    V15        = CommFunc.ConvertDBNullToDecimal(s1["V15"]),
                    V16        = CommFunc.ConvertDBNullToDecimal(s1["V16"]),
                    V17        = CommFunc.ConvertDBNullToDecimal(s1["V17"]),
                    V18        = CommFunc.ConvertDBNullToDecimal(s1["V18"]),
                    V19        = CommFunc.ConvertDBNullToDecimal(s1["V19"]),
                    V20        = CommFunc.ConvertDBNullToDecimal(s1["V20"]),
                    V21        = CommFunc.ConvertDBNullToDecimal(s1["V21"]),
                    V22        = CommFunc.ConvertDBNullToDecimal(s1["V22"]),
                    V23        = CommFunc.ConvertDBNullToDecimal(s1["V23"]),
                    V24        = CommFunc.ConvertDBNullToDecimal(s1["V24"]),
                    V25        = CommFunc.ConvertDBNullToDecimal(s1["V25"]),
                    V26        = CommFunc.ConvertDBNullToDecimal(s1["V26"]),
                    V27        = CommFunc.ConvertDBNullToDecimal(s1["V27"]),
                    V28        = CommFunc.ConvertDBNullToDecimal(s1["V28"]),
                    V29        = CommFunc.ConvertDBNullToDecimal(s1["V29"]),
                    V30        = CommFunc.ConvertDBNullToDecimal(s1["V30"]),
                    V31        = CommFunc.ConvertDBNullToDecimal(s1["V31"]),
                    ModuleName = CommFunc.ConvertDBNullToString(s1["ModuleName"]),
                    RoomName   = CommFunc.ConvertDBNullToString(s1["RoomName"]),
                    StrcName   = CommFunc.ConvertDBNullToString(s1["StrcName"]),
                };
                rst.Code = 0;
                rst.Msg  = "";
                rst.Data = new { total = dtSource.Rows.Count, rows = res1.ToList() };
            }
            catch (Exception ex)
            {
                rst.Code = -1;
                rst.Msg  = ex.Message;
                FileLog.WriteLog("获取按时间粒度列表错误(GetYdModuleList):" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Esempio n. 12
0
        /// <summary>
        /// 用户登陆
        /// </summary>
        /// <param name="ledger"></param>
        /// <param name="uSign"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public APIRst Login(string uSign, string pwd)
        {
            int    ledger = 0;
            APIRst rst    = new APIRst();

            try
            {
                //DataTable dt = new YDS6000.BLL.ExpApp.Home.HomeBLL(9999, 0).GetProjectList();
                //foreach (DataRow dr in dt.Rows)
                //    ledger = CommFunc.ConvertDBNullToInt32(dr["Rule"]);
                bll = new YDS6000.BLL.ExpApp.Home.HomeBLL(ledger, user.Uid);

                if (string.IsNullOrEmpty(uSign))
                {
                    rst.rst      = false;
                    rst.err.code = (int)ResultCodeDefine.Error;
                    rst.err.msg  = "用户名不能为空";
                    return(rst);
                }
                if (string.IsNullOrEmpty(pwd))
                {
                    rst.rst      = false;
                    rst.err.code = (int)ResultCodeDefine.Error;
                    rst.err.msg  = "密码不能为空";
                    return(rst);
                }
                WebConfig.GetSysConfig();
                DataTable dtSource = bll.GetUser(uSign);
                int       nRows    = dtSource.Rows.Count;
                if (nRows == 0)
                {
                    rst.rst      = false;
                    rst.err.code = (int)ResultCodeDefine.Error;
                    rst.err.msg  = "没有此用户";
                    return(rst);
                }
                else if (nRows != 1)
                {
                    rst.rst      = false;
                    rst.err.code = (int)ResultCodeDefine.Error;
                    rst.err.msg  = "此用户有多个";
                    return(rst);
                }

                int    uid     = CommFunc.ConvertDBNullToInt32(dtSource.Rows[0]["Uid"]);
                string uName   = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["UName"]);
                string dbPwd   = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["UPasswd"]);
                string project = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["Project"]);
                int    role_id = 0;
                if (!pwd.Trim().Equals(dbPwd))
                {
                    //查询最后最后的登录时间,判断如果少于十五分钟且错误次数已经为五次,提示十五分钟后再次登录
                    //int num = CommFunc.ConvertDBNullToInt32(dtSource.Rows[0]["LoginInt"]);
                    //DateTime dt = CommFunc.ConvertDBNullToDateTime(dtSource.Rows[0]["LoginDate"]);
                    //TimeSpan ts = new TimeSpan();
                    //ts = DateTime.Now - dt; //现在时间-数据库时间
                    //int Result = Convert.ToInt32(ts.TotalMinutes); //转换时间间隔为 分钟  Double型转化成Int型
                    //if (Result < 15 && num > 4)
                    //{
                    //    rst.err.code = (int)ResultCodeDefine.Error;
                    //    rst.err.msg = "登录的次数超过了规定次数,请十五分钟后再试";
                    //    return rst;
                    //}
                    ////登录密码错误,将登录错误次数+1
                    //bll.UpdateLoginErr(uSign);
                    rst.rst      = false;
                    rst.err.code = (int)ResultCodeDefine.Error;
                    rst.err.msg  = "密码错误";
                    return(rst);
                }
                ////
                DataTable dtMd  = bll.GetV3_UserOfModule(uid);
                int       mid   = 0;
                decimal   price = 0;
                foreach (DataRow dr in dtMd.Rows)
                {
                    mid   = CommFunc.ConvertDBNullToInt32(dr["Module_id"]);
                    price = Math.Round(CommFunc.ConvertDBNullToDecimal(dr["Price"]), 4, MidpointRounding.AwayFromZero);
                }
                dynamic attach = new { mid = mid, price = price, step = new { s1 = 200, s2 = 400, p1 = price, p2 = price } };
                //////
                WebConfig.SysProject = project;
                //////
                int    seed = new Random(Guid.NewGuid().GetHashCode()).Next(65, 91);
                string zm   = CommFunc.NunberToChar(seed);
                zm = string.IsNullOrEmpty(zm) ? "APP" : zm;
                string    ticket    = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10) + zm + (ledger + seed).ToString() + zm + (seed + uid).ToString();
                string    ccKey     = ledger.ToString() + "APP" + uid.ToString();
                CacheUser cacheUser = new CacheUser();
                cacheUser.Ledger   = ledger;
                cacheUser.Uid      = uid;
                cacheUser.USign    = uSign;
                cacheUser.Role_id  = role_id;
                cacheUser.CacheKey = project + "->" + ledger + "->";
                //随机数前10位+ 种子数+ (种子数+用户数之和)
                cacheUser.Ticket = ticket;// Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10) + (seed + cacheUser.Uid).ToString().PadLeft(7, '0');
                cacheUser.Attach = attach;
                //
                //bll.UpdateLoginSue(uSign);
                rst.err.code = 0;
                rst.data     = new { Ticket = cacheUser.Ticket, Name = uName };
                //
                int timeSpan = CommFunc.ConvertDBNullToInt32(ConfigHelper.GetAppSettings("Cached:Time"));
                timeSpan = timeSpan == 0 ? 15 : timeSpan;
                HttpRuntime.Cache.Insert(ccKey, cacheUser, null, DateTime.MaxValue, TimeSpan.FromMinutes(timeSpan));
                HttpContext.Current.Session["CacheUser"] = cacheUser;
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("登录错误:" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Esempio n. 13
0
        /// <summary>
        /// 获取系统控制日志
        /// </summary>
        /// <returns></returns>
        public APIRst GetYdSysLogCtrl(string UName, DateTime StartTime, DateTime EndTime)
        {
            APIRst rst = new APIRst();

            try
            {
                DataTable dtSource = bll.GetYdSysLogCtrl(UName, StartTime, EndTime);
                int       total    = dtSource.Rows.Count;
                var       res1     = from s1 in dtSource.AsEnumerable()
                                     select new
                {
                    RowId   = CommFunc.ConvertDBNullToInt32(s1["RowId"]),
                    UName   = CommFunc.ConvertDBNullToString(s1["UName"]),
                    Content = CommFunc.ConvertDBNullToString(s1["Descr"]),
                    Result  = CommFunc.ConvertDBNullToInt32(s1["ErrCode"]) == 0 ? "已下发" : (CommFunc.ConvertDBNullToInt32(s1["ErrCode"]) == 1 ? "执行成功" : CommFunc.ConvertDBNullToString(s1["ErrTxt"])),
                    Ctime   = CommFunc.ConvertDBNullToDateTime(s1["Create_dt"]).ToString("yyyy-MM-dd HH:mm:ss"),
                };
                object obj = new { total = total, rows = res1.ToList() };
                rst.data = obj;
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("获取系统操作日志内容错误(GetYdSysLogCtrl):" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Esempio n. 14
0
        static string KT6   = IniHepler.GetConfig(lpFileName, "DATA", "KT6");   //C1栋2楼空调
        //private int Ledger = 0;
        //private int SysUid = 0;
        //private readonly YDS6000.DAL.Energy.Home.HomeDAL dal = null;
        //public HomeBLL(int _ledger, int _uid)
        //{
        //    this.Ledger = _ledger;
        //    this.SysUid = _uid;
        //    dal = new YDS6000.DAL.Energy.Home.HomeDAL(_ledger, _uid);
        //}

        ///// <summary>
        ///// 获取楼房当日用能曲线数据
        ///// 返回参数
        ///// 第一个是当天的小时用能
        ///// 第二个是昨日的小时用能
        ///// 第三个当天的用能总和
        ///// 最后是同期比
        ///// </summary>
        ///// <param name="co_id">楼房ID号</param>
        ///// <returns></returns>
        //public object GetDayEnergyUseValForBuild(int co_id)
        //{
        //    DataTable DT_SOURCE = dal.GetEnergyUseVal(co_id, 1);
        //    DT_SOURCE.PrimaryKey = new DataColumn[] { DT_SOURCE.Columns["Module_id"], DT_SOURCE.Columns["Fun_id"] };
        //    StringBuilder splitMdQuery = new StringBuilder();
        //    StringBuilder splitTyQuery = new StringBuilder();
        //    foreach (DataRow dr in DT_SOURCE.Rows)
        //    {
        //        if (!string.IsNullOrEmpty(splitMdQuery.ToString()))
        //            splitMdQuery.Append(",");
        //        splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"]));
        //        if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitTyQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["FunType"]), ",")))
        //        {
        //            if (!string.IsNullOrEmpty(splitTyQuery.ToString()))
        //                splitTyQuery.Append(",");
        //            splitTyQuery.Append(CommFunc.ConvertDBNullToString(dr["FunType"]));
        //        }
        //    }
        //    DateTime today2 = DateTime.Now.AddHours(-1); DateTime today1 = new DateTime(today2.Year, today2.Month, today2.Day);
        //    DateTime yesterday1 = today1.AddDays(-1); DateTime yesterday2 = new DateTime(yesterday1.Year, yesterday1.Month, yesterday1.Day, 23, 59, 0);
        //    DataTable dtUse1 = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), today1, today2, "hour", splitTyQuery.ToString());
        //    DataTable dtUse2 = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), yesterday1, yesterday2, "hour", splitTyQuery.ToString());
        //    List<decimal> todayList = new List<decimal>();
        //    List<decimal> ysdayList = new List<decimal>() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
        //    int nn = today2.Hour;
        //    while (nn-- >= 0)
        //    {
        //        todayList.Add(0);
        //    }
        //    decimal todayUse = 0, yesterdayUse = 0;
        //    foreach (DataRow dr in dtUse1.Rows)
        //    {
        //        DataRow curDr = DT_SOURCE.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] });
        //        if (curDr == null) continue;
        //        int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]);
        //        decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]);
        //        scale = scale == 0 ? 2 : scale;

        //        DateTime tagTime = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]);
        //        decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]);
        //        decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]);
        //        decimal useVal = lastVal - firstVal;
        //        useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero);

        //        todayList[tagTime.Hour] = CommFunc.ConvertDBNullToDecimal(todayList[tagTime.Hour]) + useVal;
        //        todayUse = todayUse + useVal;
        //    }
        //    foreach (DataRow dr in dtUse2.Rows)
        //    {
        //        DataRow curDr = DT_SOURCE.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] });
        //        if (curDr == null) continue;
        //        int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]);
        //        decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]);
        //        scale = scale == 0 ? 2 : scale;

        //        DateTime tagTime = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]);
        //        decimal firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]);
        //        decimal lastVal = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]);
        //        decimal useVal = lastVal - firstVal;
        //        useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero);

        //        ysdayList[tagTime.Hour] = CommFunc.ConvertDBNullToDecimal(ysdayList[tagTime.Hour]) + useVal;
        //        if (tagTime.Hour <= today2.Hour)
        //            yesterdayUse = yesterdayUse + useVal;
        //    }
        //    decimal tongBiZeng = Math.Round((yesterdayUse == 0 ? 0 : ((todayUse - yesterdayUse) / yesterdayUse)) * 100, 2, MidpointRounding.AwayFromZero);
        //    return new { todayList = todayList, ysdayList = ysdayList, todayUse = todayUse, tongBiZeng = tongBiZeng.ToString("f2") + "%" };
        //}
        /// <summary>
        /// 获取全部回路
        /// </summary>
        private void GetModuleData()
        {
            DT_SOURCE            = dal.GetEnergyUseVal(1);
            DT_SOURCE.PrimaryKey = new DataColumn[] { DT_SOURCE.Columns["Module_id"], DT_SOURCE.Columns["Fun_id"] };

            foreach (DataRow dr in DT_SOURCE.Rows)
            {
                if (!string.IsNullOrEmpty(splitMdQuery.ToString()))
                {
                    splitMdQuery.Append(",");
                }
                splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"]));
                if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitTyQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["FunType"]), ",")))
                {
                    if (!string.IsNullOrEmpty(splitTyQuery.ToString()))
                    {
                        splitTyQuery.Append(",");
                    }
                    splitTyQuery.Append(CommFunc.ConvertDBNullToString(dr["FunType"]));
                }
            }
        }
Esempio n. 15
0
        public object GetPduFunTypes(int co_id, string funTypes)
        {
            //string funType = string.Join(",", funTypes.ToArray());
            string funType = funTypes;//

            DateTime today2 = DateTime.Now.AddHours(-1); DateTime today1 = new DateTime(today2.Year, today2.Month, today2.Day);
            Dictionary <string, List <decimal> > rr = new Dictionary <string, List <decimal> >();

            foreach (string str in funTypes.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                List <decimal> todayList = new List <decimal>();
                if (rr.TryGetValue(str, out todayList) == false)
                {
                    todayList = new List <decimal>();
                    int nn = today2.Hour;
                    while (nn-- >= 0)
                    {
                        todayList.Add(0);
                    }
                    rr.Add(str, todayList);
                }
            }
            //
            DataTable dtSource = dal.GetPduFunTypes(co_id, funType);

            dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] };
            StringBuilder splitMdQuery = new StringBuilder();
            StringBuilder splitTyQuery = new StringBuilder();

            foreach (DataRow dr in dtSource.Rows)
            {
                if (string.IsNullOrEmpty(splitMdQuery.ToString()))
                {
                    splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"]));
                }
                //if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitMdQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["Module_id"]), ",")))
                //{
                //    if (!string.IsNullOrEmpty(splitMdQuery.ToString()))
                //        splitMdQuery.Append(",");
                //    splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"]));
                //}
                if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitTyQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["FunType"]), ",")))
                {
                    if (!string.IsNullOrEmpty(splitTyQuery.ToString()))
                    {
                        splitTyQuery.Append(",");
                    }
                    splitTyQuery.Append(CommFunc.ConvertDBNullToString(dr["FunType"]));
                }
            }
            DataTable dtUse1   = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), today1, today2, "hour", splitTyQuery.ToString());
            decimal   todayUse = 0;

            foreach (DataRow dr in dtUse1.Rows)
            {
                DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] });
                if (curDr == null)
                {
                    continue;
                }
                int     scale    = CommFunc.ConvertDBNullToInt32(curDr["Scale"]);
                int     isChrg   = CommFunc.ConvertDBNullToInt32(curDr["IsChrg"]);
                decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]);
                scale = scale == 0 ? 2 : scale;
                //
                DateTime tagTime  = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]);
                decimal  firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]);
                decimal  lastVal  = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]);
                decimal  useVal   = 0;
                if (isChrg == 1)
                {
                    useVal = lastVal - firstVal;
                    useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero);
                    //
                    List <decimal> todayList = new List <decimal>();
                    if (rr.TryGetValue(CommFunc.ConvertDBNullToString(curDr["FunType"]), out todayList) == true)
                    {
                        todayList[tagTime.Hour] = CommFunc.ConvertDBNullToDecimal(todayList[tagTime.Hour]) + useVal;
                        todayUse = todayUse + useVal;
                    }
                }
                else
                {
                    useVal = lastVal;
                    useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero);
                    //
                    List <decimal> todayList = new List <decimal>();
                    if (rr.TryGetValue(CommFunc.ConvertDBNullToString(curDr["FunType"]), out todayList) == true)
                    {
                        todayList[tagTime.Hour] = CommFunc.ConvertDBNullToDecimal(todayList[tagTime.Hour]) > useVal?CommFunc.ConvertDBNullToDecimal(todayList[tagTime.Hour]) : useVal;

                        todayUse = todayUse > useVal ? todayUse : useVal;
                    }
                }
            }
            List <object> dd = new List <object>();

            foreach (var ss in rr)
            {
                dd.Add(new { funType = ss.Key, list = ss.Value });
            }
            return(dd);
        }
Esempio n. 16
0
 public DataTable GetRptStationList(int areaId, DateTime start, DateTime end, int stationTypeId)
 {
     #region 表结构
     DataTable dtRst = new DataTable();
     dtRst.Columns.Add("StationId", typeof(System.Int32));        // 机房ID号
     dtRst.Columns.Add("StationNo", typeof(System.String));       // 机房编号
     dtRst.Columns.Add("StationTypeId", typeof(System.Int32));    // 机房类型id
     dtRst.Columns.Add("Start", typeof(System.DateTime));         //当前开始时间
     dtRst.Columns.Add("End", typeof(System.DateTime));           //当前结束时间
     dtRst.Columns.Add("StationName", typeof(System.String));     // 机房名称
     dtRst.Columns.Add("StrcName", typeof(System.String));        // 所属区域
     dtRst.Columns.Add("Address", typeof(System.String));         // 机房地址
     dtRst.Columns.Add("StationTypeName", typeof(System.String)); // 机房类型名称
     dtRst.Columns.Add("UseVal", typeof(System.Decimal));         //使用电值
     dtRst.Columns.Add("LastTime", typeof(System.String));        // 最后录入时间
     #endregion
     #region 填充基础数据
     StringBuilder splitMdQuery = new StringBuilder();
     DataTable     dtSource     = dal.GetRptStationData(areaId, stationTypeId);
     dtRst.PrimaryKey    = new DataColumn[] { dtRst.Columns["StationId"] };
     dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] };
     foreach (DataRow dr in dtSource.Rows)
     {
         if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitMdQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["Module_id"]), ",")))
         {
             if (!string.IsNullOrEmpty(splitMdQuery.ToString()))
             {
                 splitMdQuery.Append(",");
             }
             splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"]));
         }
         DataRow addDr = dtRst.Rows.Find(new object[] { dr["Parent_id"] });
         if (addDr == null)
         {
             addDr = dtRst.NewRow();
             addDr["StationId"]       = dr["Parent_id"];
             addDr["StationNo"]       = dr["CoNo"];
             addDr["StationTypeId"]   = dr["StationType"];
             addDr["Start"]           = start;
             addDr["End"]             = end;
             addDr["StationName"]     = dr["CoName"];
             addDr["StrcName"]        = dr["CoStrcName"];
             addDr["Address"]         = dr["CustAddr"];
             addDr["StationTypeName"] = dr["StationTypeName"];
             dtRst.Rows.Add(addDr);
         }
     }
     #endregion
     #region 填充采集数据
     DataTable dtUse = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), start, end, "day");
     foreach (DataRow dr in dtUse.Rows)
     {
         DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] });
         if (curDr == null)
         {
             continue;
         }
         int      scale     = CommFunc.ConvertDBNullToInt32(curDr["Scale"]);
         int      stationId = CommFunc.ConvertDBNullToInt32(curDr["Parent_id"]);
         decimal  multiply  = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]);
         DateTime tagtime   = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]);
         decimal  firstVal  = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]);
         decimal  lastVal   = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]);
         decimal  useVal    = (lastVal - firstVal) * multiply;
         scale  = scale == 0 ? 2 : scale;
         useVal = Math.Round(useVal, scale, MidpointRounding.AwayFromZero);
         DataRow addDr = dtRst.Rows.Find(new object[] { stationId });
         if (addDr == null)
         {
             continue;
         }
         addDr["UseVal"] = CommFunc.ConvertDBNullToDecimal(addDr["UseVal"]) + useVal;
         if (CommFunc.ConvertDBNullToDateTime(addDr["LastTime"]) < CommFunc.ConvertDBNullToDateTime(dr["LastTime"]))
         {
             addDr["LastTime"] = dr["LastTime"];
         }
     }
     #endregion
     return(dtRst);
 }
Esempio n. 17
0
        /// <summary>
        /// 获取采集信息
        /// </summary>
        /// <param name="mm_id">类型ID号</param>
        /// <param name="ModuleType">设备类型</param>
        /// <returns></returns>
        public APIRst GetYdModelsOfEditOnList(int mm_id, string ModuleType)
        {
            APIRst rst = new APIRst();

            try
            {
                DataTable dtSource = XMLCofig.GetDrive(ModuleType);
                dtSource.Clear();
                dtSource.Columns.Add("RowId", typeof(System.Int32));
                dtSource.Columns.Add("Fun_id", typeof(System.Int32));
                dtSource.Columns.Add("Mm_id", typeof(System.Int32));
                dtSource.Columns.Add("DataValue", typeof(System.String));
                dtSource.Columns.Add("Disabled", typeof(System.Int32));
                DataTable dtDb  = bll.GetYdModelsOfEditOnList(mm_id);
                int       rowId = 0;
                foreach (DataRow dr in dtSource.Rows)
                {
                    dr["RowId"]  = ++rowId;
                    dr["Fun_id"] = 0;
                    dr["Mm_id"]  = mm_id;
                    foreach (DataRow drDb in dtDb.Select("FunType='" + CommFunc.ConvertDBNullToString(dr["FunType"]) + "'"))
                    {
                        drDb["nAct"]    = 2;
                        dr["Fun_id"]    = drDb["Fun_id"];
                        dr["FunName"]   = drDb["FunName"];
                        dr["DataValue"] = drDb["DataValue"];
                        dr["Disabled"]  = drDb["Disabled"];
                    }
                }
                foreach (DataRow dr in dtDb.Select("nAct=0"))
                {
                    DataRow addDr = dtSource.NewRow();
                    addDr["RowId"] = ++rowId;
                    addDr["Type"]  = ModuleType;
                    foreach (DataColumn dc in dtDb.Columns)
                    {
                        if (dtSource.Columns.Contains(dc.ColumnName))
                        {
                            addDr[dc.ColumnName] = dr[dc.ColumnName];
                        }
                    }
                    dtSource.Rows.Add(addDr);
                }
                int total = dtSource.Rows.Count;
                var res1  = from s1 in dtSource.AsEnumerable()
                            select new
                {
                    RowId      = CommFunc.ConvertDBNullToInt32(s1["RowId"]),
                    Fun_id     = CommFunc.ConvertDBNullToInt32(s1["Fun_id"]),
                    Mm_id      = CommFunc.ConvertDBNullToInt32(s1["Mm_id"]),
                    FunName    = CommFunc.ConvertDBNullToString(s1["FunName"]),
                    FunType    = CommFunc.ConvertDBNullToString(s1["FunType"]),
                    DataValue  = CommFunc.ConvertDBNullToString(s1["DataValue"]),
                    Disabled   = CommFunc.ConvertDBNullToInt32(s1["Disabled"]),
                    Action     = CommFunc.ConvertDBNullToInt32(s1["Action"]),
                    DataType   = CommFunc.ConvertDBNullToInt32(s1["DataType"]),
                    Scale      = CommFunc.ConvertDBNullToInt32(s1["Scale"]),
                    OrdNo      = CommFunc.ConvertDBNullToInt32(s1["OrdNo"]),
                    @checked   = CommFunc.ConvertDBNullToInt32(s1["Disabled"]),
                    Protocol   = CommFunc.ConvertDBNullToString(s1["Protocol"]),
                    OrdGrp     = CommFunc.ConvertDBNullToInt32(s1["OrdGrp"]),
                    Unit       = CommFunc.ConvertDBNullToString(s1["Unit"]),
                    PointType  = CommFunc.ConvertDBNullToInt32(s1["PointType"]),
                    AlarmModel = CommFunc.ConvertDBNullToInt32(s1["AlarmModel"]),
                    SubTab     = CommFunc.ConvertDBNullToString(s1["SubTab"]),
                };
                rst.data = res1.ToList();
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("获取充值参数信息错误:" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Esempio n. 18
0
        private string GetYdCollectOnExport(string jsonDataTable)
        {
            string fn       = "/XTemp/采集历史报表.xls";
            string filePath = System.Web.HttpContext.Current.Server.MapPath(@"/XTemp");

            if (System.IO.Directory.Exists(filePath) == false)
            {
                System.IO.Directory.CreateDirectory(filePath);
            }
            string filename = System.Web.HttpContext.Current.Server.MapPath(fn);

            if (System.IO.File.Exists(filename))/*先删除已存在的文件,再汇出Excel*/
            {
                System.IO.File.Delete(filename);
            }
            DataTable dtSource = new DataTable();

            if (jsonDataTable.Length > 10)
            {
                dtSource = JsonHelper.ToDataTable(jsonDataTable);
            }
            string funType = dtSource.Rows.Count == 0 ? "" : funType = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["FunType"]);
            string content = "";

            System.Reflection.FieldInfo info = typeof(V0Fun).GetField(funType);
            if (info != null)
            {
                var obj = info.GetCustomAttributes(typeof(Describe), false);
                if (obj != null)
                {
                    foreach (Describe md in obj)
                    {
                        content = md.describe;
                    }
                }
            }

            Excel.ExcelCellStyle columnCellStyle0 = new Excel.ExcelCellStyle();
            columnCellStyle0 = new Excel.ExcelCellStyle()
            {
                DataFormart         = "0.00",
                HorizontalAlignment = NPOI.SS.UserModel.HorizontalAlignment.RIGHT
            };
            Excel.ExcelCellStyle columnCellStyle1 = new Excel.ExcelCellStyle();
            columnCellStyle1 = new Excel.ExcelCellStyle()
            {
                DataFormart = "yyyy-MM-dd HH:mm:ss",
            };
            Excel.ExcelColumnCollection columns = new Excel.ExcelColumnCollection();
            columns.Add(new Excel.ExcelColumn("序号", "RowId", 5)
            {
                IsSetWith = true
            });
            columns.Add(new Excel.ExcelColumn("建筑", "CoStrcName", 15)
            {
                IsSetWith = true
            });
            columns.Add(new Excel.ExcelColumn("房间", "CoName", 15)
            {
                IsSetWith = true
            });
            columns.Add(new Excel.ExcelColumn("电表地址", "ModuleAddr", 15)
            {
                IsSetWith = true
            });
            columns.Add(new Excel.ExcelColumn("采集时间", "TagTime", 20)
            {
                IsSetWith = true
            });
            columns.Add(new Excel.ExcelColumn("读数", "LastVal", 15)
            {
                IsSetWith = true
            });
            Excel.ExcelOparete excel = new Excel.ExcelOparete("采集历史报表");
            excel.SetObjectValue("采集历史报表" + (content == "" ? "" : ":" + content), 0, 0, 3);
            excel.SetColumnName(columns, 1, 0);
            excel.SetColumnValue(columns, dtSource.Select(), 2, 0);
            excel.SaveExcelByFullFileName(filename);
            return(fn);
        }
Esempio n. 19
0
        public int SetYdModelsOnSave(v0_moduleVModel mm, DataTable v0_fun)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Clear();
            DataTable obj = null;

            strSql.Append("select count(*) from v0_module where Ledger=@Ledger and Mm_id!=@Mm_id and ModuleType=@ModuleType");
            obj = SQLHelper.Query(strSql.ToString(), new { Ledger = this.Ledger, Mm_id = mm.Mm_id, ModuleType = mm.ModuleType });
            int cnt = 0;

            if (CommFunc.ConvertDBNullToInt32(obj.Rows[0]["count(*)"]) > 0)
            {
                throw new Exception("已存在此型号:" + mm.ModuleType);
            }
            if (mm.Mm_id == 0)
            {
                strSql.Clear();
                strSql.Append("select max(Mm_id) from v0_module where Ledger=@Ledger");
                obj      = SQLHelper.Query(strSql.ToString(), new { Ledger = this.Ledger });
                mm.Mm_id = obj.Rows.Count > 0 ? CommFunc.ConvertDBNullToInt32(obj.Rows[0]["max(Mm_id)"]) + 1 : 1;
                //mm.Mm_id = CommFunc.ConvertDBNullToInt32(obj.Rows[0]["max(Mm_id)"]) + 1;
                //
                strSql.Clear();
                strSql.Append("insert into v0_module(");
                strSql.Append("Ledger,Mm_id,ModuleName,ModuleType,Disabled,ModulePwd,ModuleUid,Level,Spec,Fty_prod,IsCharg,Protocol)");
                strSql.Append(" values (");
                strSql.Append("@Ledger,@Mm_id,@ModuleName,@ModuleType,@Disabled,@ModulePwd,@ModuleUid,@Level,@Spec,@Fty_prod,@IsCharg,@Protocol)");
                cnt = cnt + SQLHelper.Execute(strSql.ToString(), new { Ledger = this.Ledger, Mm_id = mm.Mm_id, ModuleName = mm.ModuleName, ModuleType = mm.ModuleType, Disabled = mm.Disabled, ModulePwd = mm.ModulePwd, ModuleUid = mm.ModuleUid, Level = mm.Level, Spec = mm.Spec, Fty_prod = mm.Fty_prod, IsCharg = mm.IsCharg, Protocol = mm.Protocol });
            }
            else
            {
                strSql.Clear();
                strSql.Append("update v0_module set ");
                strSql.Append("ModuleName=@ModuleName,");
                strSql.Append("ModuleType=@ModuleType,");
                strSql.Append("Disabled=@Disabled,");
                strSql.Append("ModulePwd=@ModulePwd,");
                strSql.Append("ModuleUid=@ModuleUid,");
                strSql.Append("Level=@Level,");
                strSql.Append("Spec=@Spec,");
                strSql.Append("Fty_prod=@Fty_prod,");
                strSql.Append("IsCharg=@IsCharg,");
                strSql.Append("Protocol=@Protocol");
                strSql.Append(" where Ledger=@Ledger and Mm_id=@Mm_id;");
                cnt = cnt + SQLHelper.Execute(strSql.ToString(), new { Ledger = this.Ledger, Mm_id = mm.Mm_id, ModuleName = mm.ModuleName, ModuleType = mm.ModuleType, Disabled = mm.Disabled, ModulePwd = mm.ModulePwd, ModuleUid = mm.ModuleUid, Level = mm.Level, Spec = mm.Spec, Fty_prod = mm.Fty_prod, IsCharg = mm.IsCharg, Protocol = mm.Protocol });
            }

            foreach (DataRow dr in v0_fun.Rows)
            {
                dr["Mm_id"] = mm.Mm_id;
                int action = CommFunc.ConvertDBNullToInt32(dr["Action"]);
                if (action != 1)
                {
                    dr["DataValue"] = "";
                }
                else
                {
                    if (CommFunc.ConvertDBNullToString(dr["FunType"]).Equals(V0Fun.IsRelay.ToString()))
                    {
                        if (CommFunc.ConvertDBNullToInt32(dr["DataValue"]) >= 2)
                        {
                            dr["DataValue"] = "129";
                        }
                        else
                        {
                            dr["DataValue"] = CommFunc.ConvertDBNullToInt32(dr["DataValue"]);
                        }
                    }
                }
                cnt = cnt + this.YdModelsOnSaveInFun(dr);
            }
            return(cnt);
        }
Esempio n. 20
0
        public APIRst SendYdMailContent(string email, string crmName, DateTime lastTime, string coName, string syAmt, decimal syVal)
        {
            APIRst rst = new APIRst();
            string msg = "";

            if (string.IsNullOrEmpty(email))
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = "无邮箱地址,不能发送邮件";
                return(rst);
            }
            object obj = new
            {
                CrmName  = crmName,
                DateTime = lastTime,
                CoName   = coName,
                SyAmt    = syAmt,
                SyVal    = syVal
            };

            try
            {
                EmailConfig cc       = new EmailConfig();
                DataTable   dtSource = bll.GetMailInfo();
                if (dtSource.Rows.Count > 0)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (CommFunc.ConvertDBNullToString(dtSource.Rows[i]["CfKey"]) == "MailFrom")
                        {
                            cc.MailFrom = CommFunc.ConvertDBNullToString(dtSource.Rows[i]["CfValue"]);
                        }
                        if (CommFunc.ConvertDBNullToString(dtSource.Rows[i]["CfKey"]) == "MailSmtpHost")
                        {
                            cc.MailSmtpHost = CommFunc.ConvertDBNullToString(dtSource.Rows[i]["CfValue"]);
                        }
                        if (CommFunc.ConvertDBNullToString(dtSource.Rows[i]["CfKey"]) == "MailSmtpPassword")
                        {
                            cc.MailSmtpPassword = CommFunc.ConvertDBNullToString(dtSource.Rows[i]["CfValue"]);
                        }
                        if (CommFunc.ConvertDBNullToString(dtSource.Rows[i]["CfKey"]) == "MailSmtpUser")
                        {
                            cc.MailSmtpUser = CommFunc.ConvertDBNullToString(dtSource.Rows[i]["CfValue"]);
                        }
                    }
                }
                EmailUtilities.EmConfig = cc;

                List <string> list = new List <string>();
                list.Add(email);
                bool sue = this.SendEmail(list, crmName, coName, lastTime, syVal, out msg);
                rst.rst     = sue;
                rst.err.msg = (sue == false ? "发送失败请重试!" : "");
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("发送信息错误 (SendYdMailContent)", ex.Message + ex.StackTrace);
            }
            return(rst);
        }
Esempio n. 21
0
        // 回调
        public APIRst YdPrepPayInMdRecallPay(int pId, int pMid, string pTrade_no)
        {
            long     log_id       = CommFunc.ConvertDBNullToLong(pId);
            int      module_id    = CommFunc.ConvertDBNullToInt32(pMid);
            string   out_trade_no = CommFunc.ConvertDBNullToString(pTrade_no);
            APIRst   rst          = new APIRst();
            string   msg          = "";
            string   status       = "";
            bool     result       = false;
            bool     pass         = true;
            bool     upSb         = true;
            bool     upDb         = false;
            DateTime dtNow        = DateTime.Now;
            long     cmd_log_id   = 0;

            #region 检查支付结果并更新数据库
            System.Threading.Thread.Sleep(1000);/*一秒检查一次*/
            object row   = "";
            object osObj = new { upSb = false, upDb = false, msg = "" };
            try
            {
                if (string.IsNullOrEmpty(out_trade_no))
                {
                    result = bll.YdPrePayInMdOnRecallPay(log_id, 1, "", out msg, out cmd_log_id);
                }
                else
                {
                    lock (ObjLock)
                    {/*每次只能单独运行,目的是防止重复更新数据库的充值信息(重要事情)*/
                        pass = new WxPayAPI.WxPay().GetResult(out_trade_no, out status);
                        if (pass == true)
                        {
                            result = bll.YdPrePayInMdOnRecallPay(log_id, 1, "", out msg, out cmd_log_id);
                        }
                    }
                }
                //
                if (result == true)
                {
                    string msg2 = "";
                    if (cmd_log_id != 0) //立刻发送命令到网关
                    {                    /*充值命令*/
                        upSb = false;
                        upSb = new YdToGw(user.Ledger, user.Uid).YdToGwAgain(cmd_log_id, out upDb, out msg2);
                    }
                    else
                    {
                        upDb = true;/*是否下发命令网关*/
                    }
                    //#region 发送命令到网关(这款用于河北工业大学的SB设备,特殊定制化)
                    //DataTable cmdPay = bll.GetGwPayData(module_id);
                    //foreach (DataRow dr in cmdPay.Rows)
                    //{
                    //    decimal sbRdVal = CommFunc.ConvertDBNullToDecimal(dr["RdVal"]);
                    //    decimal sbSyZsVal = CommFunc.ConvertDBNullToDecimal(dr["SyZsVal"]);

                    //    CommandVModel cmd = ModelHandler<CommandVModel>.FillModel(dr);
                    //    cmd.Fun_id = 0;
                    //    cmd.FunType = "PaySb1";
                    //    cmd.FunName = "充电";
                    //    cmd.DataValue = (sbRdVal - sbSyZsVal).ToString("f2");
                    //    cmd.Descr = "充电";
                    //    cmd.IsUI = true;
                    //    cmd.IsNDb = true;
                    //    new YdToGw(user.Ledger, user.Uid).SendCmd(cmd);
                    //    //
                    //    cmd = ModelHandler<CommandVModel>.FillModel(dr);
                    //    cmd.Fun_id = 0;
                    //    cmd.FunType = "PaySb2";
                    //    cmd.FunName = "增电";
                    //    cmd.DataValue = sbSyZsVal.ToString("f2");
                    //    cmd.Descr = "增电";
                    //    cmd.IsUI = true;
                    //    cmd.IsNDb = true;
                    //    new YdToGw(user.Ledger, user.Uid).SendCmd(cmd);
                    //}
                    //#endregion


                    //#region 发送短信
                    //bll.SendSms(log_id);
                    //#endregion
                    v4_pay_logVModel vpay = bll.GetV4_pay_log(log_id);

                    osObj = new { upSb = upSb, upDb = upDb, msg = msg2 };
                    decimal   chrgVal = 0, useVal = 0, rdVal = 0, syZsVal = 0;
                    DataTable dtSource = bll.GetYdPostPayInMdOnList(module_id);
                    if (dtSource.Rows.Count > 0)
                    {
                        chrgVal = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["ChrgVal"]);
                        useVal  = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["UseVal"]);
                        rdVal   = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["RdVal"]);
                        syZsVal = CommFunc.ConvertDBNullToDecimal(dtSource.Rows[0]["SyZsVal"]);
                    }
                    row = new { ChrgVal = chrgVal.ToString("f2"), UseVal = useVal.ToString("f2"), RdVal = rdVal.ToString("f2"), SyVal = (rdVal - syZsVal).ToString("f2"), SyZsVal = syZsVal.ToString("f2") };

                    //判断是否拉闸
                    YDS6000.BLL.Exp.Syscont.ParameterBLL sysBll = new YDS6000.BLL.Exp.Syscont.ParameterBLL(user.Ledger, user.Uid);
                    var dt = sysBll.GetAlarmCfg();
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        decimal odValue  = CommFunc.ConvertDBNullToDecimal(dt.Rows[0]["CfValue"]);
                        int     isClosed = CommFunc.ConvertDBNullToInt32(dt.Rows[0]["Rule"]);
                        if (isClosed == 1)
                        {
                            if (rdVal <= odValue)
                            {
                                if (!YdBatchControlOfSsr("Ssr", "1", module_id.ToString()))
                                {
                                    FileLog.WriteLog("拉闸失败(YdPrepPayInMdRecallPay)", "拉闸失败");
                                }
                            }
                            else
                            {
                                if (vpay.PayType == (int)PayType.pay)
                                {/*充值动作才能合闸*/
                                    if (!YdBatchControlOfSsr("Ssr", "0", module_id.ToString()))
                                    {
                                        FileLog.WriteLog("合闸失败(YdPrepPayInMdRecallPay)", "合闸失败");
                                    }
                                }
                            }
                        }
                    }
                }
                object obj = new { pass = pass, row = row, osObj = osObj };
                rst.rst     = result;
                rst.data    = obj;
                rst.err.msg = msg;
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("预付费错误(YdPrepPayInMdRecallPay)", ex.Message + ex.StackTrace);
            }
            #endregion
            return(rst);
        }
Esempio n. 22
0
        /// <summary>
        /// 赠电
        /// </summary>
        /// <returns></returns>
        public bool BaseVal()
        {
            DateTime  month     = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
            DataTable dtSyscont = this.GetSyscont();

            if (dtSyscont.Rows.Count != 1)
            {
                return(false);
            }
            decimal mthBaseVal = CommFunc.ConvertDBNullToDecimal(dtSyscont.Rows[0]["MthBaseRoom"]);
            decimal mthBaseCrm = CommFunc.ConvertDBNullToDecimal(dtSyscont.Rows[0]["MthBaseCrm"]);
            string  exCfg      = CommFunc.ConvertDBNullToString(dtSyscont.Rows[0]["ExCfg"]);
            //月份白名单过滤
            string s = "m" + month.Month.ToString().PadLeft(2, '0') + ":1";

            if (!exCfg.Contains(s))
            {
                return(false);
            }

            if (mthBaseVal == 0 && mthBaseCrm == 0)
            {
                return(false);
            }

            DataTable dtSource = this.GetRaValList();

            foreach (DataRow dr in dtSource.Rows)
            {
                int     module_id  = CommFunc.ConvertDBNullToInt32(dr["Module_id"]);
                int     fun_id     = CommFunc.ConvertDBNullToInt32(dr["Fun_id"]);
                string  moduleAddr = CommFunc.ConvertDBNullToString(dr["ModuleAddr"]);
                int     co_id      = CommFunc.ConvertDBNullToInt32(dr["Co_id"]);
                string  subTab     = CommFunc.ConvertDBNullToString(dr["SubTab"]);
                decimal multiply   = CommFunc.ConvertDBNullToDecimal(dr["Multiply"]);
                decimal price      = CommFunc.ConvertDBNullToDecimal(dr["Price"]);
                int     yt_id      = CommFunc.ConvertDBNullToInt32(dr["YT_id"]);
                decimal lastVal    = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]);
                if (mthBaseCrm != 0 && mthBaseVal == 0)
                {
                    int cc = this.GetUserCnt(co_id);
                    mthBaseVal = CommFunc.ConvertDBNullToDecimal(mthBaseCrm) * cc;
                }
                if (mthBaseVal == 0)
                {
                    continue;
                }

                if (GetIsBaseVal(month, module_id, fun_id, moduleAddr, co_id, subTab) == true)
                {
                    continue;
                }

                using (IDbConnection dbConnection = SQLHelper.GetDBConnection())
                {
                    try
                    {
                        dbConnection.Open();
                        IDbTransaction trans = dbConnection.BeginTransaction();
                        this.AddRaValStep1(dbConnection, month, module_id, fun_id, moduleAddr, co_id, subTab);
                        this.AddRaValStep2(dbConnection, month, module_id, fun_id, moduleAddr, co_id, yt_id, subTab, lastVal, mthBaseVal, price, multiply);
                        trans.Commit();
                    }
                    catch (Exception ex)
                    {
                        this.AddErrLog(month, module_id, fun_id, moduleAddr, co_id, mthBaseVal, price, ex.Message);
                    }
                }
            }

            return(true);
        }
Esempio n. 23
0
        /// <summary>
        /// 获取分项统计
        /// </summary>
        /// <param name="co_id">支路ID号</param>
        /// <param name="time">时间</param>
        /// <param name="dataType">类型 日=day月=month年year</param>
        /// <returns></returns>
        public object GetEnergyUseVal(int co_id, DateTime time, string dataType, string moduleName)
        {
            DataTable dtRst = this.GetEnergyUseValTabSchema();
            int       cnt = 24;
            DateTime  fm = time, to = time;

            if (dataType.ToLower().Equals("day"))
            {
                fm       = new DateTime(time.Year, time.Month, time.Day);
                to       = new DateTime(time.Year, time.Month, time.Day, 23, 59, 0);
                cnt      = 24;
                dataType = "hour";
            }
            else if (dataType.ToLower().Equals("month"))
            {
                fm       = new DateTime(time.Year, time.Month, 1);
                to       = fm.AddMonths(1).AddDays(-1);
                cnt      = to.Day;
                dataType = "day";
            }
            else if (dataType.ToLower().Equals("year"))
            {
                fm       = new DateTime(time.Year, 1, 1);
                to       = new DateTime(time.Year, 12, 1);
                cnt      = 12;
                dataType = "month";
            }
            else
            {
                throw new Exception("查询类型错误");
            }
            DataTable dtSource = dal.GetEnergyUseVal(co_id, moduleName);

            dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] };
            dtRst.PrimaryKey    = new DataColumn[] { dtRst.Columns["Module_id"], dtRst.Columns["Fun_id"] };
            //
            StringBuilder splitMdQuery = new StringBuilder();
            StringBuilder splitTyQuery = new StringBuilder();

            foreach (DataRow dr in dtSource.Rows)
            {
                if (!string.IsNullOrEmpty(splitMdQuery.ToString()))
                {
                    splitMdQuery.Append(",");
                }
                splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"]));

                if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitTyQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["FunType"]), ",")))
                {
                    if (!string.IsNullOrEmpty(splitTyQuery.ToString()))
                    {
                        splitTyQuery.Append(",");
                    }
                    splitTyQuery.Append(CommFunc.ConvertDBNullToString(dr["FunType"]));
                }

                DataRow addDr = dtRst.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] });
                if (addDr == null)
                {
                    addDr = dtRst.NewRow();
                    addDr["Module_id"]  = dr["Module_id"];
                    addDr["Fun_id"]     = dr["Fun_id"];
                    addDr["Cnt"]        = cnt;
                    addDr["ModuleName"] = dr["ModuleName"];
                    dtRst.Rows.Add(addDr);
                }
            }
            #region 获取存储数据
            DataTable dtUse = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), fm, to, dataType, splitTyQuery.ToString());
            foreach (DataRow dr in dtUse.Rows)
            {
                DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] });
                if (curDr == null)
                {
                    continue;
                }

                int     scale    = CommFunc.ConvertDBNullToInt32(curDr["Scale"]);
                decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]);
                scale = scale == 0 ? 2 : scale;

                DataRow addDr = dtRst.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] });
                if (addDr == null)
                {
                    continue;
                }
                DateTime tagTime  = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]);
                decimal  firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]);
                decimal  lastVal  = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]);
                decimal  useVal   = lastVal - firstVal;

                useVal = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero);

                if (dataType.Equals("hour"))
                {
                    addDr["V" + (tagTime.Hour + 1).ToString().PadLeft(2, '0')] = CommFunc.ConvertDBNullToDecimal(addDr["V" + (tagTime.Hour + 1).ToString().PadLeft(2, '0')]) + useVal;
                }
                else if (dataType.Equals("day"))
                {
                    addDr["V" + tagTime.Day.ToString().PadLeft(2, '0')] = CommFunc.ConvertDBNullToDecimal(addDr["V" + tagTime.Day.ToString().PadLeft(2, '0')]) + useVal;
                }
                else if (dataType.Equals("month"))
                {
                    addDr["V" + tagTime.Month.ToString().PadLeft(2, '0')] = CommFunc.ConvertDBNullToDecimal(addDr["V" + tagTime.Month.ToString().PadLeft(2, '0')]) + useVal;
                }
                addDr["UseVal"] = CommFunc.ConvertDBNullToDecimal(addDr["UseVal"]) + useVal;
            }
            #endregion
            #region 获取结果集数据
            var res1 = from s1 in dtRst.AsEnumerable()
                       select new
            {
                ModuleName = CommFunc.ConvertDBNullToString(s1["ModuleName"]),
                Cnt        = CommFunc.ConvertDBNullToInt32(s1["Cnt"]),
                V01        = CommFunc.ConvertDBNullToDecimal(s1["V01"]),
                V02        = CommFunc.ConvertDBNullToDecimal(s1["V02"]),
                V03        = CommFunc.ConvertDBNullToDecimal(s1["V03"]),
                V04        = CommFunc.ConvertDBNullToDecimal(s1["V04"]),
                V05        = CommFunc.ConvertDBNullToDecimal(s1["V05"]),
                V06        = CommFunc.ConvertDBNullToDecimal(s1["V06"]),
                V07        = CommFunc.ConvertDBNullToDecimal(s1["V07"]),
                V08        = CommFunc.ConvertDBNullToDecimal(s1["V08"]),
                V09        = CommFunc.ConvertDBNullToDecimal(s1["V09"]),
                V10        = CommFunc.ConvertDBNullToDecimal(s1["V10"]),
                V11        = CommFunc.ConvertDBNullToDecimal(s1["V11"]),
                V12        = CommFunc.ConvertDBNullToDecimal(s1["V12"]),
                V13        = CommFunc.ConvertDBNullToDecimal(s1["V13"]),
                V14        = CommFunc.ConvertDBNullToDecimal(s1["V14"]),
                V15        = CommFunc.ConvertDBNullToDecimal(s1["V15"]),
                V16        = CommFunc.ConvertDBNullToDecimal(s1["V16"]),
                V17        = CommFunc.ConvertDBNullToDecimal(s1["V17"]),
                V18        = CommFunc.ConvertDBNullToDecimal(s1["V18"]),
                V19        = CommFunc.ConvertDBNullToDecimal(s1["V19"]),
                V20        = CommFunc.ConvertDBNullToDecimal(s1["V20"]),
                V21        = CommFunc.ConvertDBNullToDecimal(s1["V21"]),
                V22        = CommFunc.ConvertDBNullToDecimal(s1["V22"]),
                V23        = CommFunc.ConvertDBNullToDecimal(s1["V23"]),
                V24        = CommFunc.ConvertDBNullToDecimal(s1["V24"]),
                V25        = CommFunc.ConvertDBNullToDecimal(s1["V25"]),
                V26        = CommFunc.ConvertDBNullToDecimal(s1["V26"]),
                V27        = CommFunc.ConvertDBNullToDecimal(s1["V27"]),
                V28        = CommFunc.ConvertDBNullToDecimal(s1["V28"]),
                V29        = CommFunc.ConvertDBNullToDecimal(s1["V29"]),
                V30        = CommFunc.ConvertDBNullToDecimal(s1["V30"]),
                V31        = CommFunc.ConvertDBNullToDecimal(s1["V31"]),
            };
            return(res1.ToList());

            #endregion
        }
Esempio n. 24
0
        public object GetEnergyForDayX261()
        {
            DateTime       fm = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
            DateTime       to = DateTime.Now.AddHours(-1);
            List <decimal> dd = new List <decimal>();
            int            nn = to.Hour;

            while (nn-- >= 0)
            {
                dd.Add(0);
            }
            DataTable dtRst = new DataTable();

            dtRst.Columns.Add("ModuleAddr", typeof(System.String));
            dtRst.Columns.Add("ModuleName", typeof(System.String));
            dtRst.Columns.Add("ParentName", typeof(System.String));
            dtRst.Columns.Add("UseVal", typeof(System.Decimal));
            dtRst.Columns.Add("UseObj", typeof(System.Object));
            dtRst.Rows.Add("R6B2.X261.ⅠE", "X261 OP30/40", "焊接X261 OP30/40", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd)));
            dtRst.Rows.Add("R6B1.1#.LJ", "1# X261 OP30/40", "焊接X261 OP30/40", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd)));
            dtRst.Rows.Add("R6B1.2#.LJ", "2# X261 OP30/40", "焊接X261 OP30/40", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd)));

            dtRst.Rows.Add("R6B2.X261.ⅡE", "X261 OP45/50", "焊接X261 OP45/50", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd)));
            dtRst.Rows.Add("R6B1.3#.LJ", "3# X261 OP45/50", "焊接X261 OP45/50", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd)));
            dtRst.Rows.Add("R6B1.4#.LJ", "4# X261 OP45/50", "焊接X261 OP45/50", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd)));

            dtRst.Rows.Add("R6B2.X261.ⅢE", "X261 OP60/70", "焊接X261 OP60/70", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd)));
            dtRst.Rows.Add("R6B1.5#.LJ", "5# X261 OP60/70", "焊接X261 OP60/70", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd)));
            dtRst.Rows.Add("R6B1.6#.LJ", "6# X261 OP60/70", "焊接X261 OP60/70", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd)));

            dtRst.Rows.Add("R6B2.X261.ⅣE", "X261 OP80/85", "焊接X261 OP80/85", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd)));
            dtRst.Rows.Add("R6B1.7#.LJ", "7# X261 OP80/85", "焊接X261 OP80/85", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd)));
            dtRst.Rows.Add("R6B1.8#.LJ", "8# X261 OP80/85", "焊接X261 OP80/85", 0, JsonHelper.Deserialize <List <decimal> >(JsonHelper.Serialize(dd)));
            StringBuilder strAddrs = new StringBuilder();

            foreach (DataRow dr in dtRst.Rows)
            {
                if (!string.IsNullOrEmpty(strAddrs.ToString()))
                {
                    strAddrs.Append(",");
                }
                strAddrs.Append(CommFunc.ConvertDBNullToString(dr["ModuleAddr"]));
            }
            //
            DataTable dtSource = dal.GetEnergyForDayX261(strAddrs.ToString());

            dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] };
            dtRst.PrimaryKey    = new DataColumn[] { dtRst.Columns["ModuleAddr"] };
            //
            StringBuilder splitMdQuery = new StringBuilder();
            StringBuilder splitTyQuery = new StringBuilder();

            foreach (DataRow dr in dtSource.Rows)
            {
                if (!string.IsNullOrEmpty(splitMdQuery.ToString()))
                {
                    splitMdQuery.Append(",");
                }
                splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"]));
                if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitTyQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["FunType"]), ",")))
                {
                    if (!string.IsNullOrEmpty(splitTyQuery.ToString()))
                    {
                        splitTyQuery.Append(",");
                    }
                    splitTyQuery.Append(CommFunc.ConvertDBNullToString(dr["FunType"]));
                }
            }
            DataTable dtUse = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), fm, to, "hour", splitTyQuery.ToString());

            foreach (DataRow dr in dtUse.Rows)
            {
                DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] });
                if (curDr == null)
                {
                    continue;
                }
                int     scale    = CommFunc.ConvertDBNullToInt32(curDr["Scale"]);
                decimal multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]);
                scale = scale == 0 ? 2 : scale;
                DataRow addDr = dtRst.Rows.Find(curDr["ModuleAddr"]);
                if (addDr == null)
                {
                    continue;
                }

                DateTime tagTime  = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]);
                decimal  firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]);
                decimal  lastVal  = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]);
                decimal  useVal   = lastVal - firstVal;
                useVal          = Math.Round(useVal * multiply, scale, MidpointRounding.AwayFromZero);
                addDr["UseVal"] = CommFunc.ConvertDBNullToDecimal(addDr["UseVal"]) + useVal;
                List <decimal> rr = addDr["UseObj"] as List <decimal>;
                if (rr == null)
                {
                    continue;
                }
                rr[tagTime.Hour] = rr[tagTime.Hour] + useVal;
                addDr["UseObj"]  = rr;
            }
            var res1 = from s1 in dtRst.AsEnumerable()
                       group s1 by new { ParentName = CommFunc.ConvertDBNullToString(s1["ParentName"]) } into g1
                select new {
                ParentName = g1.Key.ParentName,
                UseVal     = g1.Sum(p => CommFunc.ConvertDBNullToDecimal(p["UseVal"]))
            };
            List <object> result = new List <object>();

            foreach (var s1 in res1)
            {
                var res2 = from s2 in dtRst.AsEnumerable()
                           where CommFunc.ConvertDBNullToString(s2["ParentName"]).Equals(s1.ParentName)
                           select new
                {
                    name = CommFunc.ConvertDBNullToString(s2["ModuleName"]),
                    data = s2["UseObj"] as List <decimal>,
                };
                result.Add(new { name = s1.ParentName, data = res2.ToList() });
            }
            return(result);
        }
Esempio n. 25
0
        public DataTable GetYdModuleUseValList(int co_id, int meter_id, DateTime time, string dataType)
        {
            DateTime start = time, end = time;
            int      cnt = dataType.Equals("hour") ? 24 : dataType.Equals("day") ? cnt = time.AddMonths(1).AddDays(-1).Day : 12;

            if (dataType.Equals("hour"))
            {
                start = new DateTime(time.Year, time.Month, time.Day);
                end   = new DateTime(time.Year, time.Month, time.Day, 23, 59, 59);
                cnt   = 24;
            }
            else if (dataType.Equals("day"))
            {
                start = new DateTime(time.Year, time.Month, 1);
                end   = start.AddMonths(1).AddDays(-1);
                cnt   = end.Day;
            }
            else
            {
                start = new DateTime(time.Year, 1, 1);
                end   = start.AddYears(1).AddDays(-1);
                cnt   = 12;
            }
            StringBuilder splitMdQuery = new StringBuilder();
            DataTable     dtRst        = this.GetYdModuleUseValTabSchema();
            DataTable     dtSource     = dal.GetYdModuleListParams(co_id, meter_id);

            dtRst.PrimaryKey    = new DataColumn[] { dtRst.Columns["Module_id"], dtRst.Columns["ModuleAddr"] };
            dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] };
            foreach (DataRow dr in dtSource.Rows)
            {
                if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitMdQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["Module_id"]), ",")))
                {
                    if (!string.IsNullOrEmpty(splitMdQuery.ToString()))
                    {
                        splitMdQuery.Append(",");
                    }
                    splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"]));
                }
            }
            DataTable dtUse = WholeBLL.GetCoreQueryData(this.Ledger, splitMdQuery.ToString(), start, end, dataType);

            foreach (DataRow dr in dtUse.Rows)
            {
                DataRow curDr = dtSource.Rows.Find(new object[] { dr["Module_id"], dr["Fun_id"] });
                if (curDr == null)
                {
                    continue;
                }
                int scale = CommFunc.ConvertDBNullToInt32(curDr["Scale"]);
                scale = scale == 0 ? 2 : scale;
                decimal  multiply = CommFunc.ConvertDBNullToDecimal(curDr["Multiply"]);
                DateTime tagtime  = CommFunc.ConvertDBNullToDateTime(dr["TagTime"]);
                decimal  firstVal = CommFunc.ConvertDBNullToDecimal(dr["FirstVal"]);
                decimal  lastVal  = CommFunc.ConvertDBNullToDecimal(dr["LastVal"]);
                decimal  useVal   = (lastVal - firstVal) * multiply;
                useVal = Math.Round(useVal, scale, MidpointRounding.AwayFromZero);
                DataRow addDr = dtRst.Rows.Find(new object[] { dr["Module_id"], dr["ModuleAddr"] });
                if (addDr == null)
                {
                    addDr = dtRst.NewRow();
                    addDr["Module_id"]  = dr["Module_id"];
                    addDr["ModuleAddr"] = dr["ModuleAddr"];
                    addDr["Cnt"]        = cnt;
                    addDr["ModuleName"] = curDr["ModuleName"];
                    addDr["RoomName"]   = curDr["CoName"];
                    addDr["StrcName"]   = curDr["CoStrcName"];
                    dtRst.Rows.Add(addDr);
                }
                string clsName = "V" + (dataType.Equals("hour") ? tagtime.Hour + 1 : dataType.Equals("day") ? tagtime.Day : tagtime.Month).ToString().PadLeft(2, '0');
                addDr[clsName] = CommFunc.ConvertDBNullToDecimal(addDr[clsName]) + useVal;
            }
            return(dtRst);
        }
Esempio n. 26
0
        public object GetPduEnergy(int co_id)
        {
            DateTime  today2 = DateTime.Now.AddHours(-1); DateTime today1 = new DateTime(today2.Year, today2.Month, today2.Day);
            DataTable dtSource = dal.GetPduFunTypes(co_id, "E");

            dtSource.PrimaryKey = new DataColumn[] { dtSource.Columns["Module_id"], dtSource.Columns["Fun_id"] };
            StringBuilder splitMdQuery = new StringBuilder();
            StringBuilder splitTyQuery = new StringBuilder();
            string        unit         = "";

            foreach (DataRow dr in dtSource.Rows)
            {
                unit = CommFunc.ConvertDBNullToString(dr["Unit"]);
                if (string.IsNullOrEmpty(splitMdQuery.ToString()))
                {
                    splitMdQuery.Append(CommFunc.ConvertDBNullToString(dr["Module_id"]));
                }
                if (!System.Text.RegularExpressions.Regex.IsMatch(string.Format("{0}{1}{2}", ",", splitTyQuery.ToString(), ","), string.Format("{0}{1}{2}", ",", CommFunc.ConvertDBNullToString(dr["FunType"]), ",")))
                {
                    if (!string.IsNullOrEmpty(splitTyQuery.ToString()))
                    {
                        splitTyQuery.Append(",");
                    }
                    splitTyQuery.Append(CommFunc.ConvertDBNullToString(dr["FunType"]));
                }
            }
            decimal todayUse = this.GetPduEnergy(dtSource, splitMdQuery.ToString(), today1, today2, "hour", splitTyQuery.ToString());
            decimal ysdayUse = this.GetPduEnergy(dtSource, splitMdQuery.ToString(), today1.AddDays(-1), today2.AddDays(-1), "hour", splitTyQuery.ToString());
            decimal monthUse = this.GetPduEnergy(dtSource, splitMdQuery.ToString(), today1, today2, "month", splitTyQuery.ToString());
            decimal yearUse  = this.GetPduEnergy(dtSource, splitMdQuery.ToString(), new DateTime(today1.Year, 1, 1), new DateTime(today1.Year, 12, 1), "month", splitTyQuery.ToString());
            decimal ystb     = Math.Round((ysdayUse == 0 ? 0 : ((todayUse - ysdayUse) / ysdayUse)) * 100, 2, MidpointRounding.AwayFromZero);

            return(new { todayUse = todayUse, monthUse = monthUse, yearUse = yearUse, ystb = ystb.ToString("f2") + "%", unit = unit });
        }
Esempio n. 27
0
 public APIRst Login(HomeLogin obj)
 {
     return(infoHelper.Login(CommFunc.ConvertDBNullToInt32(obj.ledger), CommFunc.ConvertDBNullToString(obj.name), CommFunc.ConvertDBNullToString(obj.pwd)));
 }
Esempio n. 28
0
        /// <summary>
        /// 获取告警数据
        /// </summary>
        /// <returns></returns>
        public object GetPduAlarm(int co_id)
        {
            DataTable dtSource = dal.GetPduAlarm(co_id);
            int       mth = dtSource.Rows.Count;
            int       day = dtSource.Select("CDate=#" + DateTime.Now.ToString("yyyy-MM-dd", System.Globalization.DateTimeFormatInfo.InvariantInfo) + "#").Count();
            string    code = "", type = "", time = "", name = "";

            if (mth > 0)
            {
                code = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["Module_id"]).PadLeft(5, '0') + CommFunc.ConvertDBNullToString(dtSource.Rows[0]["Fun_id"]).PadLeft(3, '0');
                type = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["FunName"]) + "越限";
                time = CommFunc.ConvertDBNullToDateTime(dtSource.Rows[0]["CollectTime"]).ToString("yyyy-MM-dd");
                name = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["ModuleName"]);
            }
            return(new { mth = mth, day = day, code = code, type = type, time = time, name = name });
        }
Esempio n. 29
0
        /// <summary>
        /// 获取数据列表
        /// </summary>
        /// <param name="CoStrcName"></param>
        /// <param name="CoName"></param>
        /// <param name="Ssr"></param>
        /// <returns></returns>
        public DataTable GetYdMonitorOnList(int module_id, string CoStrcName, string CoName, string Ssr, int co_id)
        {
            StringBuilder strSql = new StringBuilder();

            if (string.IsNullOrEmpty(CoStrcName) || CoStrcName == "{strcName}" || CoStrcName == "null")
            {
                CoStrcName = string.Empty;
            }
            if (string.IsNullOrEmpty(CoName) || CoName == "{coName}" || CoName == "null")
            {
                CoName = string.Empty;
            }
            if (string.IsNullOrEmpty(Ssr) || Ssr == "{ssr}" || Ssr == "null")
            {
                Ssr = string.Empty;
            }
            string AreaPowerStr     = "";
            bool   IsCheckAreaPower = WHoleDAL.GetAreaPower(this.Ledger, this.SysUid, out AreaPowerStr);
            string ids = "";

            if (co_id != 0)
            {
                strSql.Clear();
                strSql.Append("select GetCoChildList(@Ledger,@Co_id)as ids");
                object obj = SQLHelper.ExecuteScalar(strSql.ToString(), new { Ledger = this.Ledger, Co_id = co_id });
                ids = CommFunc.ConvertDBNullToString(obj);
            }
            object params01 = new {
                Ledger         = this.Ledger,
                Module_id      = module_id,
                CoStrcName     = "%" + CoStrcName + "%",
                CoName         = "%" + CoName + "%",
                Ssr            = Ssr,
                SplitException = WHoleDAL.splitException,
                AreaPowerStr   = AreaPowerStr,
                MdItems        = WHoleDAL.MdItems,
                Ids            = ids,
            };

            strSql.Clear();
            strSql.Append("select a.Ledger,a.Module_id,a.ModuleAddr,a.ModuleName,a.Co_id,a.Multiply,b.LastVal as CurVal,");
            strSql.Append("round(b.RdVal * a.Multiply,b.Scale)as RdVal,round(b.SyZsVal * a.Multiply,b.Scale)as SyZsVal,");
            strSql.Append("round(b.LastVal * a.Multiply,b.Scale)as LastVal,a.ModuleType,");
            strSql.Append("b.LastTime,c1.CoName,c1.CoStrcName,''as Ssr,s1.FrMd,b.MemcachKey,a.HandledBY,");
            strSql.Append("case when TIMESTAMPDIFF(MINUTE,b.LastTime,NOW()) < s1.FrMd then 1 else 0 end as `OnLine`,mp.IsAlarm,");
            strSql.Append("case when ifnull(mp.Price,0)=0 then s1.Price else mp.Price end as Price,fp.LpszDbVarName as CachComm");
            strSql.Append(" from vp_mdinfo as a");
            strSql.Append(" left join vp_v2info as b on a.Ledger=b.Ledger and a.Co_id=b.Co_id and a.Module_id=b.Module_id and a.ModuleAddr=b.ModuleAddr and a.Mm_id=b.Mm_id and b.FunType='E' and b.Hist_id=0");
            strSql.Append(" left join vp_coinfo as c1 on a.Ledger=c1.Ledger and a.Co_id=c1.Co_id");
            strSql.Append(" left join syscont as s1 on a.Ledger=s1.Ledger");
            strSql.Append(" left join v1_gateway_esp_module_info as mp on a.Ledger=mp.Ledger and a.Module_id=mp.Module_id");
            strSql.Append(" left join vp_funinfo as fp on a.Ledger=fp.Ledger and a.Module_id=fp.Module_id and a.Mm_id=fp.Mm_id and fp.FunType='Comm' and fp.Disabled=0");/*在线状态*/
            strSql.Append(" where a.Ledger=@Ledger and not FIND_IN_SET(a.ModuleType,@SplitException) and a.IsDefine = 100");
            if (module_id != 0)
            {
                strSql.Append(" and a.Module_id=@Module_id");
            }
            if (IsCheckAreaPower == true)
            {
                strSql.Append(" and FIND_IN_SET(a.Co_id,@AreaPowerStr)");
            }
            if (!string.IsNullOrEmpty(WHoleDAL.MdItems))
            {
                strSql.Append(" and FIND_IN_SET(a.IsDefine,@MdItems)");
            }
            //strSql.Append(string.Format(" and a.IsDefine in ({0})", WHoleDAL.MdItems));
            strSql.Append(" and ifnull(c1.CoStrcName,'') like @CoStrcName ");
            strSql.Append(" and ifnull(c1.CoName,'') like @CoName ");
            if (!string.IsNullOrEmpty(ids))
            {
                strSql.Append(" and FIND_IN_SET(a.Co_id,@Ids)");
            }
            return(SQLHelper.Query(strSql.ToString(), params01));
        }
Esempio n. 30
0
        /// <summary>
        /// 获取新增页面内的时段设置的表格
        /// </summary>
        /// <param name="nAct">1=增加,2=修改,3=删除</param>
        /// <param name="Psi_id"></param>
        /// <returns></returns>
        public APIRst GetsiSSR(int nAct, int Psi_id)
        {
            APIRst rst  = new APIRst();
            string json = "";
            object obj  = null;

            try
            {
                if (nAct == 1)
                {
                    DataTable dtSource = bll.GetTable(json);
                    int       total    = dtSource.Rows.Count;
                    var       res1     = from s1 in dtSource.AsEnumerable()
                                         select new
                    {
                        t00 = CommFunc.ConvertDBNullToString(s1["t00"]),
                        d01 = CommFunc.ConvertDBNullToString(s1["d01"]),
                        d02 = CommFunc.ConvertDBNullToString(s1["d02"]),
                        d03 = CommFunc.ConvertDBNullToString(s1["d03"]),
                        d04 = CommFunc.ConvertDBNullToString(s1["d04"]),
                        d05 = CommFunc.ConvertDBNullToString(s1["d05"]),
                        d06 = CommFunc.ConvertDBNullToString(s1["d06"]),
                        d07 = CommFunc.ConvertDBNullToString(s1["d07"]),
                        d08 = CommFunc.ConvertDBNullToString(s1["d08"])
                    };
                    obj = new { total = dtSource.Rows.Count, rows = res1.ToList() };
                }
                else
                {
                    if (Psi_id == 0)
                    {
                        throw new Exception("Psi_id不能为空");
                    }
                    DataTable dtSource = bll.GetYdm_si_ssr(Psi_id, "");
                    if (dtSource.Rows.Count > 0)
                    {
                        json = CommFunc.ConvertDBNullToString(dtSource.Rows[0]["siSSR"]);
                    }
                    DataTable dt    = bll.GetTable(json);
                    int       total = dt.Rows.Count;
                    var       res1  = from s1 in dt.AsEnumerable()
                                      select new
                    {
                        t00 = CommFunc.ConvertDBNullToString(s1["t00"]),
                        d01 = CommFunc.ConvertDBNullToString(s1["d01"]),
                        d02 = CommFunc.ConvertDBNullToString(s1["d02"]),
                        d03 = CommFunc.ConvertDBNullToString(s1["d03"]),
                        d04 = CommFunc.ConvertDBNullToString(s1["d04"]),
                        d05 = CommFunc.ConvertDBNullToString(s1["d05"]),
                        d06 = CommFunc.ConvertDBNullToString(s1["d06"]),
                        d07 = CommFunc.ConvertDBNullToString(s1["d07"]),
                        d08 = CommFunc.ConvertDBNullToString(s1["d08"])
                    };
                    obj = new { total = dtSource.Rows.Count, rows = res1.ToList() };
                }

                rst.data = obj;
            }
            catch (Exception ex)
            {
                rst.rst      = false;
                rst.err.code = (int)ResultCodeDefine.Error;
                rst.err.msg  = ex.Message;
                FileLog.WriteLog("获取新增页面内的时段设置的表格错误:" + ex.Message + ex.StackTrace);
            }
            return(rst);
        }