Пример #1
0
 //CRUD
 public void Creating(RecordLine _cellBook)
 {
     using (connection = new OdbcConnection(connectionString))
     {
         try
         {
             connection.Open();
             string query = "INSERT INTO PhoneBookTable(LastName, FirstName, MidleName, Phone, Email) " +
                            "VALUES(?, ?, ?, ?, ?)";
             using (OdbcCommand creatingCellBook = new OdbcCommand(query, connection))
             {
                 creatingCellBook.Parameters.Add("LastName", OdbcType.VarChar).Value  = _cellBook.LastName;
                 creatingCellBook.Parameters.Add("FirstName", OdbcType.VarChar).Value = _cellBook.FirstName;
                 creatingCellBook.Parameters.Add("MidleName", OdbcType.VarChar).Value = _cellBook.MiddleName;
                 creatingCellBook.Parameters.Add("Phone", OdbcType.VarChar).Value     = _cellBook.Phone;
                 creatingCellBook.Parameters.Add("Email", OdbcType.VarChar).Value     = _cellBook.Email;
                 try { creatingCellBook.ExecuteNonQuery(); }
                 catch (OdbcException ex)
                 {
                     Debug.WriteLine(ex.Message + "\n\n" + "StackTrace[Creating() => ExecuteNonQuery()]: \n\n" + ex.StackTrace);
                     return;
                 }
             }
         }
         catch (OdbcException ex)
         {
             Debug.WriteLine(ex.Message + "\n\n" + "StackTrace[Creating() => connection]: \n\n" + ex.StackTrace);
         }
     }
 }
Пример #2
0
 public void Updating(RecordLine _cellBook)
 {
     using (connection = new OdbcConnection(connectionString))
     {
         try
         {
             connection.Open();
             string query = "UPDATE PhoneBookTable SET (LastName, FirstName, MidleName, Phone, Email) = " +
                            "(?, ?, ?, ?, ?) WHERE id = ?";
             using (OdbcCommand updatingCellBook = new OdbcCommand(query, connection))
             {
                 updatingCellBook.Parameters.Add("LastName", OdbcType.VarChar).Value  = _cellBook.LastName;
                 updatingCellBook.Parameters.Add("FirstName", OdbcType.VarChar).Value = _cellBook.FirstName;
                 updatingCellBook.Parameters.Add("MidleName", OdbcType.VarChar).Value = _cellBook.MiddleName;
                 updatingCellBook.Parameters.Add("Phone", OdbcType.VarChar).Value     = _cellBook.Phone;
                 updatingCellBook.Parameters.Add("Email", OdbcType.VarChar).Value     = _cellBook.Email;
                 updatingCellBook.Parameters.Add("id", OdbcType.Int).Value            = _cellBook.Id;
                 try { updatingCellBook.ExecuteNonQuery(); }
                 catch (OdbcException ex)
                 {
                     Debug.WriteLine(ex.Message + "\n\n" + "StackTrace[Updating() => ExecuteNonQuery()]: \n\n" + ex.StackTrace);
                     return;
                 }
             }
         }
         catch (OdbcException ex)
         {
             Debug.WriteLine(ex.Message + "\n\n" + "StackTrac" +
                             "e[Updating() => connection]: \n\n" + ex.StackTrace);
         }
     }
 }
Пример #3
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack)
     {
         RecordLine tmpRecordLine = new RecordLine();
         if (TryUpdateModel(tmpRecordLine, new FormValueProvider(ModelBindingExecutionContext)))
         {
             RecordLineRepository.GetRepository().Creating(tmpRecordLine);
             Page.Response.Redirect(Page.Request.Url.ToString(), true);
         }
     }
 }
Пример #4
0
 public void WriteRecordLine(RecordLine line)
 {
     if (_state != State.Record)
     {
         throw new InvalidOperationException("Invalid in current state");
     }
     _writer.WriteLine(LineBegin);
     foreach (var tuple in line.GetProperties())
     {
         _writer.WriteLine($"-{tuple.Key}: {tuple.Value}");
     }
 }
Пример #5
0
 public static RecordSetView LoadRecordLine(RecordLine line, string directory)
 {
     if (line is RecordLineStream1D)
     {
         return(new RecordSetView((RecordLineStream1D)line, directory));
     }
     else if (line is RecordLineStream2D)
     {
         return(new RecordSetView((RecordLineStream2D)line, directory));
     }
     else
     {
         return(null);
     }
 }
Пример #6
0
        private int FindAbsAdrLnNum(string hexAdr)
        {
            hexAdr = hexAdr.ToUpper();

            if (hexAdr.Length == 4)
            {
                var lnCtr = 1;
                foreach (var line in File.ReadLines(_hexFilename))
                {
                    var record = new RecordLine(line);
                    if (record.AddressList.Contains(hexAdr))
                    {
                        return(lnCtr);
                    }

                    lnCtr++;
                }
            }
            else if (hexAdr.Length == 8)
            {
                var extendedAddress = hexAdr.Substring(0, 4);
                var lineAdr         = hexAdr.Substring(4, 4);

                var extAdrLine = GenerateHexLine(SpecialRecAdr, RecordType.ExtendedLinearAddress, extendedAddress);

                var foundFlag = false;
                var lnCtr     = 1;
                foreach (var line in File.ReadLines(_hexFilename))
                {
                    if (line.ToUpper() == extAdrLine)
                    {
                        foundFlag = true;
                    }

                    if (foundFlag)
                    {
                        var record = new RecordLine(line);
                        if (record.AddressList.Contains(lineAdr))
                        {
                            return(lnCtr);
                        }
                    }

                    lnCtr++;
                }
            }
            return(0);
        }
Пример #7
0
        public void AddRecordedFileToSet(RecordLine line)
        {
            lock (_setLock) {
                if (_firstSetWrite)
                {
                    BeginSetWrite();
                    _firstSetWrite = false;
                }

                _setWriter.BeginRecord();
                _setWriter.WriteRecordLine(line);
                _setWriter.EndRecord();

                _writeCount++;
            }
        }
Пример #8
0
 public IEnumerable <RecordLine> ReadingAll()
 {
     using (connection = new OdbcConnection(connectionString))
     {
         try
         {
             connection.Open();
             string query = "SELECT * FROM phonebooktable ORDER BY id";
             using (OdbcCommand readingCellBook = new OdbcCommand(query, connection))
             {
                 try
                 {
                     List <RecordLine> cellsBook = new List <RecordLine>();
                     RecordLine        tmp;
                     OdbcDataReader    reader = readingCellBook.ExecuteReader(CommandBehavior.CloseConnection);
                     while (reader.Read() == true)
                     {
                         tmp            = new RecordLine();
                         tmp.Id         = reader.GetString(0);
                         tmp.LastName   = reader.GetString(1);
                         tmp.FirstName  = reader.GetString(2);
                         tmp.MiddleName = reader.GetString(3);
                         tmp.Phone      = reader.GetString(4);
                         tmp.Email      = reader.GetString(5);
                         cellsBook.Add(tmp);
                     }
                     return(cellsBook);
                 }
                 catch (OdbcException ex)
                 {
                     Debug.WriteLine(ex.Message + "\n\n" + "StackTrace[ReadingAll() => ExecuteReader()]: \n\n" + ex.StackTrace);
                     return(null);
                 }
             }
         }
         catch (OdbcException ex)
         {
             Debug.WriteLine(ex.Message + "\n\n" + "StackTrace[ReadingAll() => connection]: \n\n" + ex.StackTrace);
             return(null);
         }
     }
 }
Пример #9
0
 public RecordLine ReadingById(int _id)
 {
     using (connection = new OdbcConnection(connectionString))
     {
         try
         {
             connection.Open();
             string query = "SELECT * FROM phonebooktable WHERE id = ?";
             using (OdbcCommand readingCellBook = new OdbcCommand(query, connection))
             {
                 readingCellBook.Parameters.Add("id", OdbcType.Int).Value = _id;
                 try
                 {
                     RecordLine     tmpCellBook = new RecordLine();
                     OdbcDataReader reader      = readingCellBook.ExecuteReader(CommandBehavior.CloseConnection);
                     reader.Read();
                     tmpCellBook.Id         = reader.GetString(0);
                     tmpCellBook.LastName   = reader.GetString(1);
                     tmpCellBook.FirstName  = reader.GetString(2);
                     tmpCellBook.MiddleName = reader.GetString(3);
                     tmpCellBook.Phone      = reader.GetString(4);
                     tmpCellBook.Email      = reader.GetString(5);
                     return(tmpCellBook);
                 }
                 catch (OdbcException ex)
                 {
                     Debug.WriteLine(ex.Message + "\n\n" + "StackTrace[ReadingById() => ExecuteReader]: \n\n" + ex.StackTrace);
                     return(null);
                 }
             }
         }
         catch (OdbcException ex)
         {
             Debug.WriteLine(ex.Message + "\n\n" + "StackTrac" +
                             "e[ReadingById() => connection]: \n\n" + ex.StackTrace);
             return(null);
         }
     }
 }
Пример #10
0
 public void AddRecordedFileToSet(RecordLine line)
 {
     //
 }
Пример #11
0
        //void Test1(PLCCom);

        static void Main(string[] args)
        {
            try
            {
                int LogicalStationNum = Convert.ToInt32(ConfigurationManager.AppSettings["LogicalStationNum"]);
                Log.AddConsoleLogger(ConfigurationManager.AppSettings["LogFormatter"]);
                Log.OpenLog("PLC-Console");

                PLCCom com = new PLCCom(LogicalStationNum);
                int    ret = com.Open();
                if (0 != ret)
                {
                    throw new Exception("Open com fail.");
                }

                RecordLine line1     = new RecordLine("MD1", "D01001", "D01002");
                Record     record1_1 = new Record("D01012", "D01026");
                Record     record1_2 = new Record("D01032", "D01046");

                RecordLine line2     = new RecordLine("MD2", "D01101", "D01102");
                Record     record2_1 = new Record("D01112", "D01126");
                Record     record2_2 = new Record("D01132", "D01146");

                RecordLine line3     = new RecordLine("MD3", "D01201", "D01202");
                Record     record3_1 = new Record("D01212", "D01226");
                Record     record3_2 = new Record("D01232", "D01246");

                RecordLine line4     = new RecordLine("MD4", "D01301", "D01302");
                Record     record4_1 = new Record("D01312", "D01326");
                Record     record4_2 = new Record("D01332", "D01346");


                if (false)
                {
                    Console.WriteLine("Test read mark.");
                    while (true)
                    {
                        short lineMark1 = CommUtil.GetDevice(line1.ReadMarkDevice, com);
                        if (lineMark1 != 0)
                        {
                            Console.WriteLine(String.Format("{2},{3} -- {0}'s read mark is set to {1}.", line1.PalletizerName, lineMark1, DateTime.Now, DateTime.Now.Millisecond));
                        }

                        short lineMark2 = CommUtil.GetDevice(line2.ReadMarkDevice, com);
                        if (lineMark2 != 0)
                        {
                            Console.WriteLine(String.Format("{2},{3} -- {0}'s read mark is set to {1}.", line2.PalletizerName, lineMark2, DateTime.Now, DateTime.Now.Millisecond));
                        }

                        short lineMark3 = CommUtil.GetDevice(line3.ReadMarkDevice, com);
                        if (lineMark3 != 0)
                        {
                            Console.WriteLine(String.Format("{2},{3} -- {0}'s read mark is set to {1}.", line3.PalletizerName, lineMark3, DateTime.Now, DateTime.Now.Millisecond));
                        }

                        short lineMark4 = CommUtil.GetDevice(line4.ReadMarkDevice, com);
                        if (lineMark4 != 0)
                        {
                            Console.WriteLine(String.Format("{2},{3} -- {0}'s read mark is set to {1}.", line4.PalletizerName, lineMark4, DateTime.Now, DateTime.Now.Millisecond));
                        }
                    }
                }
                else
                {
                    while (true)
                    {
                        Console.Write("\nPush enter to write data.");
                        Console.ReadLine();

                        line1.SetPlateCode("11111111", com);
                        record1_1.SetBoxCode("1A0000000000000000000000000", com);
                        record1_1.SetAmount(11, com);
                        record1_2.SetBoxCode("1B0000000000000000000000000", com);
                        record1_2.SetAmount(12, com);
                        CommUtil.SetDevice(1, line1.ReadMarkDevice, com);

                        line2.SetPlateCode("22222222", com);
                        record2_1.SetBoxCode("2A0000000000000000000000000", com);
                        record2_1.SetAmount(21, com);
                        record2_2.SetBoxCode("2B0000000000000000000000000", com);
                        record2_2.SetAmount(22, com);
                        CommUtil.SetDevice(1, line2.ReadMarkDevice, com);

                        line3.SetPlateCode("33333333", com);
                        record3_1.SetBoxCode("3A0000000000000000000000000", com);
                        record3_1.SetAmount(31, com);
                        record3_2.SetBoxCode("3B0000000000000000000000000", com);
                        record3_2.SetAmount(32, com);
                        CommUtil.SetDevice(1, line3.ReadMarkDevice, com);

                        line4.SetPlateCode("44444444", com);
                        record4_1.SetBoxCode("4A0000000000000000000000000", com);
                        record4_1.SetAmount(41, com);
                        record4_2.SetBoxCode("4B0000000000000000000000000", com);
                        record4_2.SetAmount(42, com);
                        CommUtil.SetDevice(1, line4.ReadMarkDevice, com);
                    }
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Пример #12
0
 private RecordSetView(RecordLineStream2D line, string directory) : this()
 {
     _input     = line;
     _directory = directory;
 }
Пример #13
0
 private RecordSetView(Record set, string directory) : this()
 {
     _recording = set;
     _input     = null;
     _directory = directory;
 }