Exemplo n.º 1
0
        /// <summary>
        /// 获取新增页面内的时段设置的表格1
        /// </summary>
        /// <param name="siSSR"></param>
        /// <returns></returns>
        public DataTable GetTable(string siSSR)
        {
            DataTable dtSource = new DataTable();

            dtSource.Columns.Add("t00", typeof(System.String));
            dtSource.Columns.Add("d01", typeof(System.String));
            dtSource.Columns.Add("d02", typeof(System.String));
            dtSource.Columns.Add("d03", typeof(System.String));
            dtSource.Columns.Add("d04", typeof(System.String));
            dtSource.Columns.Add("d05", typeof(System.String));
            dtSource.Columns.Add("d06", typeof(System.String));
            dtSource.Columns.Add("d07", typeof(System.String));
            dtSource.Columns.Add("d08", typeof(System.String));
            dtSource.Rows.Add(new object[] { "第01时段定时断送电时间" });
            dtSource.Rows.Add(new object[] { "第02时段定时断送电时间" });
            dtSource.Rows.Add(new object[] { "第03时段定时断送电时间" });
            dtSource.Rows.Add(new object[] { "第04时段定时断送电时间" });
            dtSource.Rows.Add(new object[] { "第05时段定时断送电时间" });
            dtSource.Rows.Add(new object[] { "第06时段定时断送电时间" });
            dtSource.Rows.Add(new object[] { "第07时段定时断送电时间" });
            dtSource.Rows.Add(new object[] { "第08时段定时断送电时间" });
            JsonSiModel si = Models.ModelHandler <JsonSiModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(siSSR));

            StringBuilder strD = new StringBuilder();
            StringBuilder strT = new StringBuilder();

            JsonSiModel.Value value;
            int rIndex = 0;

            foreach (DataRow dr in dtSource.Rows)
            {
                rIndex = rIndex + 1;
                foreach (DataColumn dc in dtSource.Columns)
                {
                    int cIndex = CommFunc.ConvertDBNullToInt32(dc.ColumnName.Trim().Substring(1, 2));
                    if (cIndex == 0)
                    {
                        continue;
                    }
                    strD.Clear();
                    strT.Clear();
                    strD.Append("d" + cIndex.ToString().Trim().PadLeft(2, '0'));
                    strT.Append("t" + rIndex.ToString().Trim().PadLeft(2, '0'));
                    System.Reflection.PropertyInfo dInfo = si.GetType().GetProperty(strD.ToString());
                    object obj  = dInfo.GetValue(si, null);
                    Type   type = dInfo.PropertyType;
                    System.Reflection.PropertyInfo tInfo = Activator.CreateInstance(type).GetType().GetProperty(strT.ToString());
                    value             = (JsonSiModel.Value)tInfo.GetValue(obj, null);
                    dr[dc.ColumnName] = value.hm + "-" + value.sr;
                }
            }
            return(dtSource);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 设置定时电表策略
        /// </summary>
        /// <param name="nAct">1=增加,2=修改,3=删除</param>
        /// <param name="si_id">策略Id,修改和删除需要,新增时传0即可</param>
        /// <param name="pRemark">描述</param>
        /// <param name="pIsClosed">是否启用:1=启用,0=不启用</param>
        /// <param name="pcT">日时区策略</param>
        /// <param name="pcM">日时区策略-定时段表号</param>
        /// <param name="pcW">星期策略</param>
        /// <param name="pcD">特殊日期策略</param>
        /// <param name="pcB">特殊日期策略-定时段表号</param>
        /// <param name="Timing"></param>
        /// <returns></returns>
        public APIRst SetTiming(int nAct, int si_id, string pRemark, int pIsClosed, string pcT, string pcM, string pcW, string pcD, string pcB, DataModels Timing)
        {
            APIRst rst = new APIRst();
            string pcT1, pcT2, pcT3, pcT4, pcT5, pcT6, pcT7, pcM1, pcM2, pcM3, pcM4, pcM5, pcM6, pcM7, pcW1, pcW2, pcW3, pcW4, pcW5, pcW6, pcW7, pcD1, pcD2, pcD3, pcD4, pcD5, pcD6, pcD7, pcB1, pcB2, pcB3, pcB4, pcB5, pcB6, pcB7 = null;

            try
            {
                String[] pcTss = pcT.Split(','); //日时区策略
                pcT1 = pcTss[0];
                pcT2 = pcTss[1];
                pcT3 = pcTss[2];
                pcT4 = pcTss[3];
                pcT5 = pcTss[4];
                pcT6 = pcTss[5];
                pcT7 = pcTss[6];

                String[] pcMss = pcM.Split(',');  //日时区策略-定时段表号
                pcM1 = pcMss[0];
                pcM2 = pcMss[1];
                pcM3 = pcMss[2];
                pcM4 = pcMss[3];
                pcM5 = pcMss[4];
                pcM6 = pcMss[5];
                pcM7 = pcMss[6];

                String[] pcWss = pcW.Split(','); //星期策略
                pcW1 = pcWss[0];
                pcW2 = pcWss[1];
                pcW3 = pcWss[2];
                pcW4 = pcWss[3];
                pcW5 = pcWss[4];
                pcW6 = pcWss[5];
                pcW7 = pcWss[6];

                String[] pcDWss = pcD.Split(',');  //特殊日期策略
                pcD1 = pcDWss[0];
                pcD2 = pcDWss[1];
                pcD3 = pcDWss[2];
                pcD4 = pcDWss[3];
                pcD5 = pcDWss[4];
                pcD6 = pcDWss[5];
                pcD7 = pcDWss[6];

                String[] pcBWss = pcB.Split(',');  //特殊日期策略-定时段表号
                pcB1 = pcBWss[0];
                pcB2 = pcBWss[1];
                pcB3 = pcBWss[2];
                pcB4 = pcBWss[3];
                pcB5 = pcBWss[4];
                pcB6 = pcBWss[5];
                pcB7 = pcBWss[6];


                v1_si_ssrVModel si_ssr = new v1_si_ssrVModel();
                if (nAct != 1 && nAct != 2 && nAct != 3)
                {
                    throw new Exception("执行操作类型错误");
                }
                JsonSiModel si = ModelHandler <JsonSiModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(si_ssr.siSSR));

                JsonSiMdModel md = ModelHandler <JsonSiMdModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(si_ssr.md));

                JsonSiWkModel wk = ModelHandler <JsonSiWkModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(si_ssr.wk));

                JsonSiTsModel ts = ModelHandler <JsonSiTsModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(si_ssr.ts));

                si_ssr.descr    = pRemark;   //描述
                si_ssr.disabled = pIsClosed; //是否启用
                ////----8个时段的JSON值怎样获取----////
                //string data1 = pData1;
                DataTable djson = ToDataTable(Timing.Data);

                //var djson = CreateTable<ExpTimingModels>();
                //djson = FillData(djson, Timing);

                StringBuilder     strD = new StringBuilder();
                StringBuilder     strT = new StringBuilder();
                JsonSiModel.Value value;
                int      rIndex = 0;
                string[] arrValue;
                object   dObj;
                foreach (DataRow dr in djson.Rows)
                {
                    rIndex = rIndex + 1;
                    foreach (DataColumn dc in djson.Columns)
                    {
                        int cIndex = CommFunc.ConvertDBNullToInt32(dc.ColumnName.Trim().Substring(1, 2));
                        if (cIndex == 0)
                        {
                            continue;
                        }
                        //arrValue = CommFunc.ConvertDBNullToString(cell.Value).Trim().Split(new char[2] { ':', '-' }, StringSplitOptions.RemoveEmptyEntries);
                        arrValue = CommFunc.ConvertDBNullToString(dr[dc]).Trim().Split('-');
                        strD.Clear();
                        strT.Clear();
                        strD.Append("d" + cIndex.ToString().Trim().PadLeft(2, '0'));
                        strT.Append("t" + rIndex.ToString().Trim().PadLeft(2, '0'));
                        System.Reflection.PropertyInfo dInfo = si.GetType().GetProperty(strD.ToString());
                        dObj = dInfo.GetValue(si, null);
                        System.Reflection.PropertyInfo tInfo = dObj.GetType().GetProperty(strT.ToString());
                        value    = (JsonSiModel.Value)tInfo.GetValue(dObj, null);
                        value.hm = arrValue[0];
                        value.sr = arrValue[1];
                        //value.sr = arrValue[2];
                    }
                }

                /////
                #region
                md.md01.md = "0000";
                md.md02.md = "0000";
                md.md03.md = "0000";
                md.md04.md = "0000";
                md.md05.md = "0000";
                md.md06.md = "0000";
                md.md07.md = "0000";
                string ss;
                string a;
                a = pcT1;
                if (a.Length > 4 || a.Length < 4)
                {
                    ss = (CommFunc.ConvertDBNullToDateTime(pcT1)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (ss != "19000101" && ss != "00010101")
                    {
                        md.md01.md = ss.Substring(4, 4);
                    }
                }
                else
                {
                    md.md01.md = a;
                }
                a = pcT2;
                if (a.Length > 4 || a.Length < 4)
                {
                    ss = (CommFunc.ConvertDBNullToDateTime(pcT2)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (ss != "19000101" && ss != "00010101")
                    {
                        md.md02.md = ss.Substring(4, 4);
                    }
                }
                else
                {
                    md.md02.md = a;
                }
                a = pcT3;
                if (a.Length > 4 || a.Length < 4)
                {
                    ss = (CommFunc.ConvertDBNullToDateTime(pcT3)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (ss != "19000101" && ss != "00010101")
                    {
                        md.md03.md = ss.Substring(4, 4);
                    }
                }
                else
                {
                    md.md03.md = a;
                }
                a = pcT4;
                if (a.Length > 4 || a.Length < 4)
                {
                    ss = (CommFunc.ConvertDBNullToDateTime(pcT4)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (ss != "19000101" && ss != "00010101")
                    {
                        md.md04.md = ss.Substring(4, 4);
                    }
                }
                else
                {
                    md.md04.md = a;
                }
                a = pcT5;
                if (a.Length > 4 || a.Length < 4)
                {
                    ss = (CommFunc.ConvertDBNullToDateTime(pcT5)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (ss != "19000101" && ss != "00010101")
                    {
                        md.md05.md = ss.Substring(4, 4);
                    }
                }
                else
                {
                    md.md05.md = a;
                }
                a = pcT6;
                if (a.Length > 4 || a.Length < 4)
                {
                    ss = (CommFunc.ConvertDBNullToDateTime(pcT6)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (ss != "19000101" && ss != "00010101")
                    {
                        md.md06.md = ss.Substring(4, 4);
                    }
                }
                else
                {
                    md.md06.md = a;
                }
                a = pcT7;
                if (a.Length > 4 || a.Length < 4)
                {
                    ss = (CommFunc.ConvertDBNullToDateTime(pcT7)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (ss != "19000101" && ss != "00010101")
                    {
                        md.md07.md = ss.Substring(4, 4);
                    }
                }
                else
                {
                    md.md07.md = a;
                }
                ////
                md.md01.si = pcM1;
                md.md02.si = pcM2;
                md.md03.si = pcM3;
                md.md04.si = pcM4;
                md.md05.si = pcM5;
                md.md06.si = pcM6;
                md.md07.si = pcM7;
                /////

                wk.si01 = pcW1;
                wk.si02 = pcW2;
                wk.si03 = pcW3;
                wk.si04 = pcW4;
                wk.si05 = pcW5;
                wk.si06 = pcW6;
                wk.si07 = pcW7;
                /////
                ts.ts01.dt = "00000000";
                ts.ts02.dt = "00000000";
                ts.ts03.dt = "00000000";
                ts.ts04.dt = "00000000";
                ts.ts05.dt = "00000000";
                ts.ts06.dt = "00000000";
                ts.ts07.dt = "00000000";
                string sd = "";
                string st = "";
                st = pcD1;
                if (st.Contains("-"))
                {
                    sd = (CommFunc.ConvertDBNullToDateTime(pcD1)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (sd != "19000101" && sd != "00010101")
                    {
                        ts.ts01.dt = sd;
                    }
                }
                else if (st != "")
                {
                    ts.ts01.dt = st;
                }
                st = pcD2;
                if (st.Contains("-"))
                {
                    sd = (CommFunc.ConvertDBNullToDateTime(pcD2)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (sd != "19000101" && sd != "00010101")
                    {
                        ts.ts02.dt = sd;
                    }
                }
                else if (st != "")
                {
                    ts.ts02.dt = st;
                }
                st = pcD3;
                if (st.Contains("-"))
                {
                    sd = (CommFunc.ConvertDBNullToDateTime(pcD3)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (sd != "19000101" && sd != "00010101")
                    {
                        ts.ts03.dt = sd;
                    }
                }
                else if (st != "")
                {
                    ts.ts03.dt = st;
                }
                st = pcD4;
                if (st.Contains("-"))
                {
                    sd = (CommFunc.ConvertDBNullToDateTime(pcD4)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (sd != "19000101" && sd != "00010101")
                    {
                        ts.ts04.dt = sd;
                    }
                }
                else if (st != "")
                {
                    ts.ts04.dt = st;
                }
                st = pcD5;
                if (st.Contains("-"))
                {
                    sd = (CommFunc.ConvertDBNullToDateTime(pcD5)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (sd != "19000101" && sd != "00010101")
                    {
                        ts.ts05.dt = sd;
                    }
                }
                else if (st != "")
                {
                    ts.ts05.dt = st;
                }
                st = pcD6;
                if (st.Contains("-"))
                {
                    sd = (CommFunc.ConvertDBNullToDateTime(pcD6)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (sd != "19000101" && sd != "00010101")
                    {
                        ts.ts06.dt = sd;
                    }
                }
                else if (st != "")
                {
                    ts.ts06.dt = st;
                }
                st = pcD7;
                if (st.Contains("-"))
                {
                    sd = (CommFunc.ConvertDBNullToDateTime(pcD7)).ToString("yyyyMMdd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                    if (sd != "19000101" && sd != "00010101")
                    {
                        ts.ts07.dt = sd;
                    }
                }
                else if (st != "")
                {
                    ts.ts07.dt = st;
                }
                ts.ts01.si = pcB1;
                ts.ts02.si = pcB2;
                ts.ts03.si = pcB3;
                ts.ts04.si = pcB4;
                ts.ts05.si = pcB5;
                ts.ts06.si = pcB6;
                ts.ts07.si = pcB7;
                #endregion
                /////////////////////////////////////////////////////////////////////////////////////
                si_ssr.siSSR = ModelHandler <JsonSiModel> .modelToJsonText(si);

                si_ssr.md = ModelHandler <JsonSiMdModel> .modelToJsonText(md);

                si_ssr.wk = ModelHandler <JsonSiWkModel> .modelToJsonText(wk);

                si_ssr.ts = ModelHandler <JsonSiTsModel> .modelToJsonText(ts);

                int cnt = 0;
                if (nAct != 1 && Convert.IsDBNull(si_ssr.si_id))
                {
                    throw new Exception("请选中一行");
                }
                if (nAct == 1)//新增
                {
                    cnt = bll.EditRow(si_ssr);
                }
                if (nAct == 2 || nAct == 3)
                {
                    si_ssr.si_id = si_id;//策略ID
                    if (nAct == 3)
                    {
                        bll.DelRow(si_ssr);//删除
                    }
                    else
                    {
                        bll.EditRow(si_ssr);
                    }
                }

                rst.data = cnt;
            }
            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);
        }
Exemplo n.º 3
0
        private static int IsRunSi(DateTime now, DataRow dr)
        {
            JsonSiModel siSSR = ModelHandler <JsonSiModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(dr["SiSSR"]));

            JsonSiMdModel md = ModelHandler <JsonSiMdModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(dr["Md"]));

            JsonSiWkModel wk = ModelHandler <JsonSiWkModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(dr["Wk"]));

            JsonSiTsModel ts = ModelHandler <JsonSiTsModel> .jsonTextToModel(CommFunc.ConvertDBNullToString(dr["Ts"]));

            DateTime today = CommFunc.ConvertDBNullToDateTime(now.ToString("yyyy-MM-dd", System.Globalization.DateTimeFormatInfo.InvariantInfo));
            int      dWk   = (int)now.DayOfWeek;

            if (dWk == 0)
            {
                dWk = 7;
            }
            int si = 0;

            if (si == 0)
            {/*特殊日期的策略*/
                for (int i = 1; i <= 7; i++)
                {
                    System.Reflection.PropertyInfo tsInfo = ts.GetType().GetProperty("ts" + i.ToString().PadLeft(2, '0').ToString());
                    JsonSiTsModel.Value            value  = (JsonSiTsModel.Value)tsInfo.GetValue(ts, null);
                    DateTime dtTs = DateTime.Now.AddDays(-300);
                    DateTime.TryParseExact(value.dt, "yyyyMMdd", null, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out dtTs);
                    int dtSi = CommFunc.ConvertDBNullToInt32(value.si);
                    if (dtTs == today && dtSi != 0)
                    {
                        si = dtSi;
                        break;
                    }
                }
            }
            if (si == 0)
            { /*星期的策略*/
                System.Reflection.PropertyInfo wkDis = wk.GetType().GetProperty("di" + dWk.ToString().PadLeft(2, '0').ToString());
                object objDis = wkDis == null ? null : wkDis.GetValue(wk, null);
                //
                if (CommFunc.ConvertDBNullToInt32(objDis) == 0)
                {
                    System.Reflection.PropertyInfo wkInfo = wk.GetType().GetProperty("si" + dWk.ToString().PadLeft(2, '0').ToString());
                    object obj = wkInfo.GetValue(wk, null);
                    si = CommFunc.ConvertDBNullToInt32(obj);
                }
            }
            if (si == 0)
            {/*日期范围*/
                for (int i = 1; i <= 7; i++)
                {
                    System.Reflection.PropertyInfo mdInfo = md.GetType().GetProperty("md" + i.ToString().PadLeft(2, '0').ToString());
                    JsonSiMdModel.Value            value  = (JsonSiMdModel.Value)mdInfo.GetValue(md, null);
                    DateTime dtMd = today.AddDays(100);
                    DateTime.TryParseExact(today.Year.ToString() + value.md, "yyyyMMdd", null, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out dtMd);
                    int dtSi = CommFunc.ConvertDBNullToInt32(value.si);
                    if (today >= dtMd && dtSi != 0)
                    {
                        si = dtSi;
                        break;
                    }
                }
            }
            //
            if (si == 0)
            {
                return(0);
            }
            //
            int rstSr = 0;

            System.Reflection.PropertyInfo siInfo = siSSR.GetType().GetProperty("d" + si.ToString().PadLeft(2, '0').ToString());
            JsonSiModel.time time = (JsonSiModel.time)siInfo.GetValue(siSSR, null);
            for (int i = 8; i >= 1; i--)
            {
                System.Reflection.PropertyInfo tInfo = time.GetType().GetProperty("t" + i.ToString().PadLeft(2, '0').ToString());
                JsonSiModel.Value value = (JsonSiModel.Value)tInfo.GetValue(time, null);
                string[]          arr   = value.hm.Split(':');
                int hour   = CommFunc.ConvertDBNullToInt32(arr[0]);
                int minute = CommFunc.ConvertDBNullToInt32(arr[1]);
                int sr     = CommFunc.ConvertDBNullToInt32(value.sr);
                if (sr != 0 && (hour != 0 || minute != 0))
                {
                    DateTime siTime = new DateTime(now.Year, now.Month, now.Day, hour, minute, 0);
                    if (now >= siTime)
                    {
                        rstSr = sr;
                        break;
                    }
                }
                //if (hour == now.Hour && minute == now.Minute && sr != 0)
                //{
                //    rstSr = sr;
                //    break;
                //}
            }
            return(rstSr);
        }