Example #1
0
 public EditHistoryForm(History history, bool autoWeld = false)
 {
     History = history;
     isAutoWeld = autoWeld;
     InitializeComponent();
     PopulateListViewContent(autoWeld);
     DoOtherUIInitialization(autoWeld);
 }
 public WeldingControlForm(SerialPort serialPort)
 {
     InitializeComponent();
     CurrentSerialPort = serialPort;
     dataReceivedEventHandler = new SerialDataReceivedEventHandler(serialPortDataReceived);
     CurrentSerialPort.DataReceived += dataReceivedEventHandler;
     History = History.LatestHistory();
 }
 private void ChooseButton_Click(object sender, EventArgs e)
 {
     var type = GangTaoTypeComboBox.Text;
     var item = WeldingItemComboBox.Text;
     if (type == "")
     {
         MessageBox.Show(this, "请选择一个规格!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     if (item == "")
     {
         MessageBox.Show(this, "请选择一个焊接项目!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     var index = HistoriesListBox.SelectedIndex;
     if (index < 0 || index >= histories.Count())
     {
         MessageBox.Show(this, "请选择一个历史纪录作为模板!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
         return;
     }
     ChosenHistory = histories[index];
     var message = string.Format("即将使用“{0}”作为{1}({2})的焊接模板,是否正确?", ChosenHistory.ShortDescription(), item, type);
     var result = MessageBox.Show(this, message, "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     if (result == DialogResult.Yes)
     {
         //Save result and go.
         if (template != null)
         {
             template.Type = type;
             template.Item = item;
             template.History = ChosenHistory;
             template.Save();
         }
         else
         {
             var dict = new Dictionary<string, object>();
             dict["type"] = type;
             dict["item"] = item;
             var tpl = new Template(dict);
             tpl.History = ChosenHistory;
             tpl.Save();
         }
         DialogResult = DialogResult.OK;
     }
 }
Example #4
0
 public void updateHistory(History history)
 {
     using (var conn = new SQLiteConnection(DataSource))
     {
         conn.Open();
         using (SQLiteCommand command = new SQLiteCommand(conn))
         {
             // history
             command.CommandText = "UPDATE Histories 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.Int64);
             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();
         }
     }
 }
Example #5
0
        public long saveHistory(History history)
        {
            using (var conn = new SQLiteConnection(DataSource))
            {
                conn.Open();
                using (SQLiteCommand command = new SQLiteCommand(conn))
                {
                    // history
                    command.CommandText = "INSERT INTO Histories ('name', 'task_name', 'gangtao_type', 'welding_item', 'welding_current', 'ar_flow', 'room_temperature', 'operator', 'created_at') values (@name, @task_name, @gangtao_type, @welding_item, @welding_current, @ar_flow, @room_temperature, @operator, @created_at)";
                    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);
                    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.ExecuteNonQuery();

                    // history id
                    long historyId = -1;

                    var sql = "SELECT * FROM Histories 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;
                }
            }
        }
Example #6
0
        public History historyOfId(long history_id)
        {
            using (var conn = new SQLiteConnection(DataSource))
            {
                conn.Open();
                using (SQLiteCommand command = new SQLiteCommand(conn))
                {
                    var sql = "SELECT * FROM Histories WHERE `id` = @hid";
                    command.CommandText = sql;
                    var hIdParam = SQLiteHelper.CreateStringParameter("@hid", history_id);
                    command.Parameters.Add(hIdParam);

                    var reader = command.ExecuteReader();
                    History 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["created_at"] = reader.GetValue(9);

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

                    return history;
                }
            }
        }
Example #7
0
        public List<History> HistoryList()
        {
            var historyList = new List<History>();
            using (var conn = new SQLiteConnection(DataSource))
            {
                conn.Open();
                using (SQLiteCommand command = new SQLiteCommand(conn))
                {
                    var sql = "SELECT * FROM Histories 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["created_at"] = reader.GetValue(9);

                        var history = new History(dict);
                        history.Id = reader.GetInt64(0);

                        historyList.Add(history);
                    }
                }
            }

            return historyList;
        }
Example #8
0
        public void deleteHistory(History history)
        {
            using (var conn = new SQLiteConnection(DataSource))
            {
                conn.Open();
                using (SQLiteCommand command = new SQLiteCommand(conn))
                {
                    // history
                    command.CommandText = "DELETE FROM Histories WHERE `id` = @hid";
                    var hIdParam = SQLiteHelper.CreateStringParameter("@hid", history.Id);
                    command.Parameters.Add(hIdParam);
                    command.ExecuteNonQuery();

                    command.CommandText = "DELETE FROM Signal WHERE `history_id` = @hid";
                    command.Parameters.Add(hIdParam);
                    command.ExecuteNonQuery();
                }
            }
        }
 public WeldingControlForm(SerialPort serialPort, History history)
     : this(serialPort)
 {
     History = history;
 }
Example #10
0
        private void SaveSignalDataAndClose()
        {
            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;

            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
            {
                //Fixme: Generate a meaningful name.
                dict["name"] = "";
                var history = new History(dict);
                history.Signals = signalCache;
                history.Save();
                Console.WriteLine("Signal history saved.");
            }
            catch (Exception excp)
            {
                //TODO: Save Result and crash.
            #if DEBUG
                Console.WriteLine(excp.StackTrace);
            #endif
                throw;
            }

            DialogResult = DialogResult.OK;
        }
Example #11
-1
        public List<Signal> SignalListOfHistory(History history, bool auto_weld = false)
        {
            var signals = new List<Signal>();
            using (var conn = new SQLiteConnection(DataSource))
            {
                conn.Open();
                using (SQLiteCommand command = new SQLiteCommand(conn))
                {
                    var autoweld_value = auto_weld ? 1 : 0;
                    var sql = "SELECT * FROM Signal WHERE `history_id` = @hid and `auto_weld` = @autoweld ORDER BY `at` ASC ";
                    command.CommandText = sql;
                    var hIdParam = SQLiteHelper.CreateStringParameter("@hid", history.Id);
                    var autoweldParam = SQLiteHelper.CreateStringParameter("@autoweld", autoweld_value);
                    command.Parameters.Add(hIdParam);
                    command.Parameters.Add(autoweldParam);
                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        var id = reader.GetInt64(0);
                        var type = reader.GetInt32(1);
                        var step = reader.GetInt32(2);
                        var at = (DateTime)reader.GetValue(3);
                        var delta = reader.GetInt32(4);

                        var signal = new Signal(type, step, at);
                        signal.Id = id;
                        signal.Delta = delta;
                        signal.History = history;
                        signals.Add(signal);
                    }

                    return signals;
                }
            }
        }