Ejemplo n.º 1
0
        public static IDbConnection GetDBConnection(this SqlComponent self)
        {
            var db = new MySql.Data.MySqlClient.MySqlConnection(self.ConnectionString);

            db.Open();
            return(db);
        }
Ejemplo n.º 2
0
        public async static Task <RoleDbInfo> GetUserDbInfo(this SqlComponent self, int UserId)
        {
            string sql = "select * from User_Info where UserId = @UserId";

            using (var db = self.GetDBConnection())
            {
                var ret = await db.QueryFirstOrDefaultAsync <UserInfo>(sql, new { UserId });

                if (ret == null)
                {
                    return(new RoleDbInfo());
                }
                else
                {
                    RoleDbInfo role = RoleDbInfo.Parser.ParseFrom(ret.UserData);
                    return(role);
                }
            }
        }
Ejemplo n.º 3
0
        public async static Task <bool> SaveUserDbInfo(this SqlComponent self, int UserId, RoleDbInfo data)
        {
            string sql = "Update User_Info Set UserData=@UserData where UserId = @UserId";

            using (var db = self.GetDBConnection())
            {
                var param = new { UserData = data.ToByteArray(), UserId = UserId };
                var row   = await db.ExecuteAsync(sql, param);

                if (row == 0)
                {
                    sql = "Insert User_Info (UserId,UserData)values(@UserId,@UserData)";
                    row = await db.ExecuteAsync(sql, param);

                    return(row == 1);
                }
                else
                {
                    return(true);
                }
            }
        }
Ejemplo n.º 4
0
        public Form1()
        {
            InitializeComponent();
            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .WriteTo.File($"{AppDomain.CurrentDomain.BaseDirectory}\\log\\log-.txt",
                                       rollingInterval: RollingInterval.Day,
                                       outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
                         .CreateLogger(); //宣告Serilog初始化

            UserbarButtonItem.ImageOptions.Image    = imageCollection16x16.Images["UserDisconnected"];
            SettingbarButtonItem.ImageOptions.Image = imageCollection16x16.Images["Setting"];
            SettingbarButtonItem.Visibility         = BarItemVisibility.Never;
            #region  Json載入
            ButtonSetting      = InitialMethod.ButtonLoad();
            LogoSetting        = InitialMethod.LogoLoad();
            SqlDBSetting       = InitialMethod.SqlDBLoad();
            BankAccountSetting = InitialMethod.BankAccountLoad();
            DemoSetting        = InitialMethod.DemoLoad();
            #endregion
            ConnectionFlag = DemoSetting.ConnectionFlag;

            #region  入Logo圖片
            if (LogoSetting != null)
            {
                if (File.Exists(LogoSetting.LogoPath))
                {
                    LogopictureEdit.Image = Image.FromFile(LogoSetting.LogoPath);
                }
                else
                {
                    LogopictureEdit.Image = LogoimageCollection.Images["ewatch_logo"];
                }
            }
            else
            {
                LogopictureEdit.Image = LogoimageCollection.Images["ewatch_logo"];
            }
            #endregion

            #region  鈕載入
            NavigationFrame = new NavigationFrame()
            {
                Dock = DockStyle.Fill
            };
            NavigationFrame.Parent = DisplaypanelControl;
            ButtonControl          = new ButtonControl()
            {
                Form1 = this, navigationFrame = NavigationFrame
            };
            ButtonControl.AccordionLoad(accordionControl1, ButtonSetting);
            #endregion

            #region 資料庫方法載入
            if (SqlDBSetting != null && ConnectionFlag)
            {
                SqlMethod = new SqlMethod()
                {
                    setting = SqlDBSetting, BankAccountSetting = BankAccountSetting
                };
                SqlMethod.SQLConnect();
                if (SqlMethod.Search_DataBase())
                {
                    SQLDataBaseFlag = true;
                    GatewayConfigs  = SqlMethod.Search_GatewayConfig();  //通道資訊
                    ElectricConfigs = SqlMethod.Search_Electricconfig(); //電表設備資訊
                    SqlComponent    = new SqlComponent()
                    {
                        SqlMethod = SqlMethod, BankAccountSetting = BankAccountSetting
                    };
                    SqlComponent.MyWorkState = ConnectionFlag;
                }
                else
                {
                    SQLDataBaseFlag = false;
                }
            }
            else if (!ConnectionFlag)
            {
                SQLDataBaseFlag = true;
                GatewayConfig gateway = new GatewayConfig()
                {
                    GatewayIndex = 0, GatewayName = "通道1"
                };
                GatewayConfigs.Add(gateway);
                for (int i = 0; i < 20; i++)
                {
                    if (i == 0)
                    {
                        ElectricConfig electric = new ElectricConfig()
                        {
                            TotalMeterFlag = true, DeviceName = $"電表{i + 1}", GatewayIndex = 0, DeviceIndex = i, DeviceID = i + 1
                        };
                        ElectricConfigs.Add(electric);
                    }
                    else
                    {
                        ElectricConfig electric = new ElectricConfig()
                        {
                            TotalMeterFlag = false, DeviceName = $"電表{i + 1}", GatewayIndex = 0, DeviceIndex = i, DeviceID = i + 1
                        };
                        ElectricConfigs.Add(electric);
                    }
                }
            }
            #endregion

            #region 通訊
            if (ConnectionFlag && GatewayConfigs != null && ElectricConfigs != null)
            {
                foreach (var item in GatewayConfigs)
                {
                    GatewayEnumType = (GatewayEnumType)item.GatewayEnumType;
                    var electricconfigs = ElectricConfigs.Where(g => g.GatewayIndex == item.GatewayIndex).ToList();
                    switch (GatewayEnumType)
                    {
                    case GatewayEnumType.ModbusRTU:
                    {
                        SerialportComponent component = new SerialportComponent()
                        {
                            BankAccountSetting = BankAccountSetting, Gatewayconfig = item, ElectricConfigs = electricconfigs
                        };
                        component.MyWorkState = ConnectionFlag;
                        ModbusComponents.Add(component);
                    }
                    break;

                    case GatewayEnumType.ModbusTCP:
                    {
                        TcpComponent component = new TcpComponent()
                        {
                            BankAccountSetting = BankAccountSetting, Gatewayconfig = item, ElectricConfigs = electricconfigs
                        };
                        component.MyWorkState = ConnectionFlag;
                        ModbusComponents.Add(component);
                    }
                    break;
                    }
                }
            }
            #endregion

            #region 畫面
            foreach (var item in ButtonSetting.ButtonGroupSettings)
            {
                foreach (var Buttonitem in item.ButtonItemSettings)
                {
                    ButtonItemEnumType = (ButtonItemEnumType)Buttonitem.ButtonItemEnumType;
                    switch (ButtonItemEnumType)
                    {
                    case ButtonItemEnumType.Home:
                    {
                        ChargingPileView chargingPileView = new ChargingPileView(ElectricConfigs, SqlMethod, this, GatewayConfigs)
                        {
                            SqlMethod = SqlMethod, Dock = DockStyle.Fill
                        };
                        field4UserControls.Add(chargingPileView);
                        NavigationFrame.AddPage(chargingPileView);
                    }
                    break;

                    case ButtonItemEnumType.Report:
                    {
                        dataReportUserControl = new DataReportUserControl(ElectricConfigs)
                        {
                            SqlMethod = SqlMethod, Dock = DockStyle.Fill, Form1 = this
                        };
                        NavigationFrame.AddPage(dataReportUserControl);
                    }
                    break;

                    case ButtonItemEnumType.BillingSheet:
                    {
                        billingSheetUserControl = new BillingSheetUserControl(ElectricConfigs)
                        {
                            BankaccountSetting = BankAccountSetting, SqlMethod = SqlMethod, Dock = DockStyle.Fill, Form1 = this
                        };
                        NavigationFrame.AddPage(billingSheetUserControl);
                    }
                    break;
                    }
                }
            }
            User_ButtonItem_Visible();
            #endregion
            timer1.Interval = 1000;
            timer1.Enabled  = true;
        }
Ejemplo n.º 5
0
 public static void Awake(this SqlComponent self, string conn)
 {
     self.ConnectionString = conn;
 }