Ejemplo n.º 1
0
 public void updateAutoWeldHistory(AutoWeldHistory history)
 {
     using (var conn = new SQLiteConnection(DataSource))
     {
         conn.Open();
         using (SQLiteCommand command = new SQLiteCommand(conn))
         {
             // history
             command.CommandText = "UPDATE AutoWeldHistories SET `name` = @name, `task_name` = @task_name, `gangtao_type` = @gangtao_type, `welding_item` = @welding_item, `welding_current` = @welding_current, `ar_flow` = @ar_flow, `room_temperature` = @room_temperature, `operator` = @operator, `created_at` = @created_at WHERE `id` = @hid";
             var nameParam = SQLiteHelper.CreateStringParameter("@name", history.Name);
             var taskNameParam = SQLiteHelper.CreateStringParameter("@task_name", history.TaskName);
             var gangtaoTypeParam = SQLiteHelper.CreateStringParameter("@gangtao_type", history.GangtaoType);
             var WeldingItemParam = SQLiteHelper.CreateStringParameter("@welding_item", history.WeldingItem);
             var WeldingCurrentParam = SQLiteHelper.CreateStringParameter("@welding_current", history.WeldingCurrent);
             var ARFlowParam = SQLiteHelper.CreateStringParameter("@ar_flow", history.ArFlow);
             var RoomTemperatureParam = SQLiteHelper.CreateStringParameter("@room_temperature", history.RoomTemperature);
             var OperatorParam = SQLiteHelper.CreateStringParameter("@operator", history.OperatorName);
             var CreatedAtParam = SQLiteHelper.CreateParameter("@created_at", history.CreatedAt, DbType.DateTime);
             var hIdParam = SQLiteHelper.CreateParameter("@hid", history.Id, DbType.DateTime);
             command.Parameters.Add(nameParam);
             command.Parameters.Add(taskNameParam);
             command.Parameters.Add(gangtaoTypeParam);
             command.Parameters.Add(WeldingItemParam);
             command.Parameters.Add(WeldingCurrentParam);
             command.Parameters.Add(ARFlowParam);
             command.Parameters.Add(RoomTemperatureParam);
             command.Parameters.Add(OperatorParam);
             command.Parameters.Add(CreatedAtParam);
             command.Parameters.Add(hIdParam);
             command.ExecuteNonQuery();
         }
     }
 }
Ejemplo n.º 2
0
        public long saveAutoWeldHistory(AutoWeldHistory history)
        {
            using (var conn = new SQLiteConnection(DataSource))
            {
                conn.Open();
                using (SQLiteCommand command = new SQLiteCommand(conn))
                {
                    // history
                    var interupted = history.Interupted == false ? false : true;
                    command.CommandText = "INSERT INTO AutoWeldHistories ('name', 'task_name', 'gangtao_type', 'welding_item', 'welding_current', 'ar_flow', 'room_temperature', 'operator', 'history_id', 'created_at', 'interupted') values (@name, @task_name, @gangtao_type, @welding_item, @welding_current, @ar_flow, @room_temperature, @operator, @history_id, @created_at, @interupted)";
                    var nameParam = SQLiteHelper.CreateStringParameter("@name", history.Name);
                    var taskNameParam = SQLiteHelper.CreateStringParameter("@task_name", history.TaskName);
                    var gangtaoTypeParam = SQLiteHelper.CreateStringParameter("@gangtao_type", history.GangtaoType);
                    var WeldingItemParam = SQLiteHelper.CreateStringParameter("@welding_item", history.WeldingItem);
                    var WeldingCurrentParam = SQLiteHelper.CreateStringParameter("@welding_current", history.WeldingCurrent);
                    var ARFlowParam = SQLiteHelper.CreateStringParameter("@ar_flow", history.ArFlow);
                    var RoomTemperatureParam = SQLiteHelper.CreateStringParameter("@room_temperature", history.RoomTemperature);
                    var OperatorParam = SQLiteHelper.CreateStringParameter("@operator", history.OperatorName);
                    var HistoryIdParam = SQLiteHelper.CreateStringParameter("@history_id", history.Template.Id);
                    var CreatedAtParam = SQLiteHelper.CreateParameter("@created_at", history.CreatedAt, DbType.DateTime);
                    var InteruptedParam = SQLiteHelper.CreateParameter("@interupted", interupted, DbType.Boolean);
                    command.Parameters.Add(nameParam);
                    command.Parameters.Add(taskNameParam);
                    command.Parameters.Add(gangtaoTypeParam);
                    command.Parameters.Add(WeldingItemParam);
                    command.Parameters.Add(WeldingCurrentParam);
                    command.Parameters.Add(ARFlowParam);
                    command.Parameters.Add(RoomTemperatureParam);
                    command.Parameters.Add(OperatorParam);
                    command.Parameters.Add(HistoryIdParam);
                    command.Parameters.Add(CreatedAtParam);
                    command.Parameters.Add(InteruptedParam);
                    command.ExecuteNonQuery();

                    // history id
                    long historyId = -1;

                    var sql = "SELECT * FROM AutoWeldHistories ORDER BY `created_at` DESC LIMIT 1"; // Not thread safe.
                    command.CommandText = sql;
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        historyId = reader.GetInt64(0);
                    }
                    reader.Close();
                    return historyId;
                }
            }
        }
Ejemplo n.º 3
0
 public void deleteAutoWeldHistory(AutoWeldHistory history)
 {
     using (var conn = new SQLiteConnection(DataSource))
     {
         conn.Open();
         using (SQLiteCommand command = new SQLiteCommand(conn))
         {
             // history
             command.CommandText = "DELETE FROM AutoWeldHistories WHERE `id` = @hid";
             var hIdParam = SQLiteHelper.CreateStringParameter("@hid", history.Id);
             command.Parameters.Add(hIdParam);
             command.ExecuteNonQuery();
         }
     }
 }
Ejemplo n.º 4
0
        public AutoWeldHistory autoWeldHistoryOfId(long history_id)
        {
            using (var conn = new SQLiteConnection(DataSource))
            {
                conn.Open();
                using (SQLiteCommand command = new SQLiteCommand(conn))
                {
                    var sql = "SELECT * FROM AutoWeldHistories ORDER BY `created_at` DESC WHERE [email protected]";
                    command.CommandText = sql;
                    var hIdParam = SQLiteHelper.CreateStringParameter("@hid", history_id);
                    command.Parameters.Add(hIdParam);

                    var reader = command.ExecuteReader();
                    AutoWeldHistory history = null;
                    while (reader.Read())
                    {
                        var dict = new Dictionary<string, object>();
                        dict["name"] = reader.GetValue(1);
                        dict["task_name"] = reader.GetValue(2);
                        dict["gangtao_type"] = reader.GetValue(3);
                        dict["welding_item"] = reader.GetValue(4);
                        dict["welding_current"] = reader.GetValue(5);
                        dict["ar_flow"] = reader.GetValue(6);
                        dict["room_temperature"] = reader.GetValue(7);
                        dict["operator"] = reader.GetValue(8);
                        dict["history_id"] = reader.GetValue(9);
                        dict["created_at"] = reader.GetValue(10);
                        dict["interupted"] = reader.GetValue(11);

                        history = new AutoWeldHistory(dict);
                        history.Id = reader.GetInt64(0);
                    }

                    return history;
                }
            }
        }
Ejemplo n.º 5
0
        public List<AutoWeldHistory> AutoWeldHistoryList()
        {
            var historyList = new List<AutoWeldHistory>();
            using (var conn = new SQLiteConnection(DataSource))
            {
                conn.Open();
                using (SQLiteCommand command = new SQLiteCommand(conn))
                {
                    var sql = "SELECT * FROM AutoWeldHistories ORDER BY `created_at` DESC";
                    command.CommandText = sql;
                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        var dict = new Dictionary<string, object>();
                        dict["name"] = reader.GetValue(1);
                        dict["task_name"] = reader.GetValue(2);
                        dict["gangtao_type"] = reader.GetValue(3);
                        dict["welding_item"] = reader.GetValue(4);
                        dict["welding_current"] = reader.GetValue(5);
                        dict["ar_flow"] = reader.GetValue(6);
                        dict["room_temperature"] = reader.GetValue(7);
                        dict["operator"] = reader.GetValue(8);
                        dict["history_id"] = reader.GetValue(9);
                        dict["created_at"] = reader.GetValue(10);
                        dict["interupted"] = reader.GetValue(11);

                        var autoWeldHistory = new AutoWeldHistory(dict);
                        autoWeldHistory.Id = reader.GetInt64(0);

                        historyList.Add(autoWeldHistory);
                    }
                }
            }

            return historyList;
        }
Ejemplo n.º 6
0
        private void SaveAutoWeldHistory(bool interupted = false)
        {
            //SaveRecordButton.Enabled = false; // Disable it.
            var dict = new Dictionary<string, object>();
            dict["task_name"] = TaskNameTextBox.Text.Trim();
            dict["gangtao_type"] = GangTaoTypeComboBox.Text.Trim();
            dict["welding_item"] = WeldingItemComboBox.Text.Trim();
            dict["welding_current"] = WeldingCurrentTextBox.Text.Trim();
            dict["ar_flow"] = ArGasFlowTextBox.Text.Trim();
            dict["room_temperature"] = RoomTempTextBox.Text.Trim();
            var op = OperatorNameComboBox.Text.Trim();
            dict["operator"] = op;
            dict["history_id"] = History.Id;

            if (op != "") // Valid op.
            {
                var db = new DataProcess();
                var ops = db.OperatorList();
                if (!ops.Contains(op))
                {
                    db.addOperator(op); // Save operator
                }
            }

            // If all OK, close.
            DateTime dt = DateTime.Now;
            dict["created_at"] = dt;
            try
            {
                dict["name"] = "";
                dict["interupted"] = false;
                var history = new AutoWeldHistory(dict);
                history.Signals = signalCache;
                // Decide interupted by signal count.
                // We can decide interupt by pass in argument.
                // Fixme: Which is better?
                if (history.Template.Signals.Count() == signalCache.Count())
                {
                    history.Interupted = false;
                }
                else
                {
            #if DEBUG
                    Console.WriteLine("Control signals: {0}, received signals: {1}", history.Template.Signals.Count(), signalCache.Count());
            #endif
                    history.Interupted = true;
                }
                history.Save();
            }
            catch (Exception excp)
            {
            #if DEBUG
                Console.WriteLine(excp.StackTrace);
            #endif
                throw;
            }
        }