Exemplo n.º 1
0
 protected void SetInfo(out Model.Gateway info, SqlDataReader reader)
 {
     try
     {
         info                  = new Model.Gateway();
         info.MacAddress       = CastDBNull.To <string>(reader["MacAddress"], "");
         info.SimCard          = CastDBNull.To <string>(reader["SimCard"], "");
         info.X                = CastDBNull.To <decimal>(reader["X"], 0.0m);
         info.Y                = CastDBNull.To <decimal>(reader["Y"], 0.0m);
         info.Description      = CastDBNull.To <string>(reader["Description"], "");
         info.InstallationDate = CastDBNull.To <DateTime>(reader["InstallationDate"], DateTime.Now);
         info.MaintenanceDate  = CastDBNull.To <DateTime>(reader["MaintenanceDate"], DateTime.Now);
         info.Status           = CastDBNull.To <string>(reader["Status"], "");
         info.IPAddress        = CastDBNull.To <string>(reader["IPAddress"], "");
         info.DMZId            = CastDBNull.To <string>(reader["DMZId"], "");
         info.CityId           = CastDBNull.To <string>(reader["CityId"], "");
         info.CreatedBy        = CastDBNull.To <string>(reader["Createdby"], "");
         info.EditedBy         = CastDBNull.To <string>(reader["Editedby"], "");
         info.DocDate          = CastDBNull.To <DateTime>(reader["DocDate"], DateTime.Now);
         info.Show             = CastDBNull.To <int>(reader["Show"], 1);
         info.LockCount        = CastDBNull.To <int>(reader["LockCount"], 1);
         info.IsNew            = false;
         info.IsDirty          = true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 2
0
        public ReturnInfo Create(SmartDB dbInstance, ref Model.Gateway info)
        {
            IInfo info2 = _dal.Insert(dbInstance, info);

            info.IsNew   = false;
            info.IsDirty = true;
            return(new ReturnInfo(info2.Code, info2.Message));
        }
Exemplo n.º 3
0
        private Service(string URL)
        {
            cliente = new FirebaseClient(URL);

            if (current == default(Model.Gateway))
            {
                localDB_gateway_col.Insert(new Model.Gateway());
                current = localDB_gateway_col.FindAll().FirstOrDefault();
            }
        }
Exemplo n.º 4
0
        public override IInfo GetRecord(SmartDB dbInstance, object Id)
        {
            string sQL_GET = this.SQL_GET;

            SqlParameter[] array = new SqlParameter[]
            {
                new SqlParameter(this.PARM_ID, SqlDbType.NVarChar)
            };
            array[0].Value = Id;
            Model.Gateway bizObject = null;
            IInfo         result;

            try
            {
                bool          transactionControl = dbInstance.TransactionControl;
                SqlDataReader sqlDataReader;
                if (transactionControl)
                {
                    sqlDataReader = SqlHelper.ExecuteReader(dbInstance.Transaction, CommandType.StoredProcedure, sQL_GET, array);
                }
                else
                {
                    sqlDataReader = SqlHelper.ExecuteReader(SqlHelper.MyConnectionString, CommandType.StoredProcedure, sQL_GET, array);
                }
                bool hasRows = sqlDataReader.HasRows;
                if (hasRows)
                {
                    sqlDataReader.Read();
                    this.SetInfo(out bizObject, sqlDataReader);
                    result = new ReturnInfo
                    {
                        BizObject = bizObject,
                        Code      = ErrorEnum.NoError
                    };
                }
                else
                {
                    result = new ReturnInfo(ErrorEnum.NoRecord, string.Format("No record found for ID: {0}", Id));
                }
            }
            catch (Exception ex)
            {
                result = new ReturnInfo(ErrorEnum.DataException, ex.Message);
            }
            return(result);
        }
Exemplo n.º 5
0
        public ReturnInfo Update(SmartDB dbInstance, Model.Gateway info)
        {
            IInfo      info2 = _dal.GetRecord(dbInstance, info.MacAddress);
            bool       flag  = info2.Code == ErrorEnum.NoError;
            ReturnInfo result;

            if (flag)
            {
                bool flag2 = (info2.BizObject as Model.Gateway).LockCount == info.LockCount;
                if (!flag2)
                {
                    result = new ReturnInfo(ErrorEnum.ColumnReference, "Record has been changed.");
                    return(result);
                }
                info.LockCount++;
                info2 = _dal.Update(dbInstance, info);
            }
            result = new ReturnInfo(info2.Code, info2.Message, info2.RowsAffected);
            return(result);
        }
Exemplo n.º 6
0
        public ReturnInfo IsValid(Model.Gateway info)
        {
            bool       flag = string.IsNullOrEmpty(info.MacAddress);
            ReturnInfo result;

            if (flag)
            {
                result = new ReturnInfo
                {
                    Code      = ErrorEnum.InvalidInput,
                    Message   = "Name cannot be blank.",
                    BizObject = "Name"
                };
            }
            else
            {
                result = new ReturnInfo(ErrorEnum.NoError, "");
            }
            return(result);
        }
Exemplo n.º 7
0
        public static void Import(string[] ofdFilenames, int max,
                                  ProgressBar ProgressBarImportStatus,
                                  Label LabelImported,
                                  Label LabelDuplicate)
        {
            int count = 0;

            using (SqlConnection connection =
                       new SqlConnection(new SmartDB().Connection.ConnectionString))
            {
                connection.Open();

                LabelDuplicate.Invoke((Action) delegate
                {
                    LabelDuplicate.Text = $"Number of duplicated CSV File/ s: {CSVDuplicate.Get(ofdFilenames).Count}";
                });

                foreach (var filename in ofdFilenames)
                {
                    _gw          = Path.GetFileName((Path.GetDirectoryName(filename)));
                    _csvFilename = (Path.GetFileName(filename));

                    if (!CSVDuplicate.Get(ofdFilenames).Contains(_csvFilename))
                    {
                        DataTable newMeterReading = MakeTable.RDS(filename);

                        using (SqlBulkCopy s = new SqlBulkCopy(connection))
                        {
                            s.DestinationTableName = "MeterReading";
                            s.ColumnMappings.Add("SerialNumber", "SerialNumber");
                            s.ColumnMappings.Add("ReadingDate", "ReadingDate");
                            s.ColumnMappings.Add("ReadingValue", "ReadingValue");
                            s.ColumnMappings.Add("LowBatteryAlr", "LowBatteryAlr");
                            s.ColumnMappings.Add("LeakAlr", "LeakAlr");
                            s.ColumnMappings.Add("MagneticTamperAlr", "MagneticTamperAlr");
                            s.ColumnMappings.Add("MeterErrorAlr", "MeterErrorAlr");
                            s.ColumnMappings.Add("BackFlowAlr", "BackFlowAlr");
                            s.ColumnMappings.Add("BrokenPipeAlr", "BrokenPipeAlr");
                            s.ColumnMappings.Add("EmptyPipeAlr", "EmptyPipeAlr");
                            s.ColumnMappings.Add("SpecificErr", "SpecificErr");
                            s.ColumnMappings.Add("MacAddress", "MacAddress");
                            try
                            {
                                s.WriteToServer(newMeterReading);

                                Model.GatewayLog gatewayLog = new Model.GatewayLog()
                                {
                                    RDS = 1,
                                    OMS = 0,
                                    GatewayMacAddress = _gw,
                                    CSVFilename       = _csvFilename,
                                    CreatedBy         = "2",
                                    EditedBy          = "2",
                                    DocDate           = DateTime.Now,
                                    Show      = 1,
                                    LockCount = 0
                                };

                                //UPDATE METER
                                _meter.GetMeterSyncMeterReading(new SmartDB());

                                var createGatewayLog = _gatewayLog.Create(new SmartDB(), ref gatewayLog);

                                if (!MacDuplicate.Get(ofdFilenames).Contains(_gw))
                                {
                                    Model.Gateway gatewayC = new Model.Gateway()
                                    {
                                        MacAddress       = Regex.Replace(_gw, @"^(..)(..)(..)(..)(..)(..)$", "$1:$2:$3:$4:$5:$6"),
                                        SimCard          = null,
                                        X                = 0,
                                        Y                = 0,
                                        Description      = null,
                                        InstallationDate = DateTime.Parse("06/20/1986"),
                                        MaintenanceDate  = DateTime.Parse("06/20/1986"),
                                        Status           = "Active",
                                        IPAddress        = "192.0.0.1",
                                        DMZId            = null,
                                        CityId           = null,
                                        CreatedBy        = "2",
                                        EditedBy         = "2",
                                        DocDate          = DateTime.Now,
                                        Show             = 1,
                                        LockCount        = 0
                                    };
                                    _gateway.Create(new SmartDB(), ref gatewayC);
                                }

                                //TODO ADD Meter Serial to Meter Table via stored proc REPORT METER_SYNCSERIALNUMBER_METERREADING
                                bool flag = createGatewayLog.Code == ErrorEnum.NoError;
                                if (flag)
                                {   //TODO
                                    ProgressBarImportStatus.Invoke((Action) delegate
                                    {
                                        ProgressBarImportStatus.Increment(1);
                                    });
                                    count++;
                                    if (count == max)
                                    {   //TODO
                                        //LabelImported.Invoke((Action)delegate
                                        //{
                                        //    LabelImported.Text = $"Number of imported CSV File/s: {count} Ok";
                                        //});
                                        _final = count;
                                        Console.WriteLine($"Importing was successful.");
                                    }
                                }
                                else
                                {
                                    Console.WriteLine($"Contact Admin: Gateway log error", "Import");
                                }
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine($"Contact Admin: {ex.Message}", "Import");
                            }
                        }
                    }
                }
            }
            //TODO
            LabelImported.Invoke((Action) delegate
            {
                LabelImported.Text = $"Number of imported CSV File/s: {_final} Ok";
            });
        }