private void ChooseButton_Click(object sender, EventArgs e)
 {
     var index = TemplatesListBox.SelectedIndex;
     if (index >=0 && index < SortedTemplates.Count())
     {
         ChosenTemplate = SortedTemplates[index];
         DialogResult = DialogResult.OK;
     }
     else
     {
         MessageBox.Show(this, "未选择任何模板。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
        public TemplateOptionsForm(Template tpl)
            : this()
        {
            template = tpl;

            var typeIndex = GangTaoTypeComboBox.Items.IndexOf(template.Type);
            GangTaoTypeComboBox.SelectedIndex = typeIndex;
            var itemIndex = WeldingItemComboBox.Items.IndexOf(template.Item);
            WeldingItemComboBox.SelectedIndex = itemIndex;
            var history = (from h in histories where h.Id == template.History.Id select h).ToList().First();
            var historyIndex = histories.IndexOf(history);
            HistoriesListBox.SelectedIndex = historyIndex;
        }
Beispiel #3
0
 public void updateTemplate(Template tpl)
 {
     using (var conn = new SQLiteConnection(DataSource))
     {
         conn.Open();
         using (SQLiteCommand command = new SQLiteCommand(conn))
         {
             command.CommandText = "UPDATE Template SET `type` = @type, `item` = @item, `history_id` = @history_id WHERE `id` = @tid";
             var typeParam = SQLiteHelper.CreateParameter("@type", tpl.Type, DbType.String);
             var itemParam = SQLiteHelper.CreateParameter("@item", tpl.Item, DbType.String);
             var historyIdParam = SQLiteHelper.CreateParameter("@history_id", tpl.History.Id, DbType.Int64);
             var tIdParam = SQLiteHelper.CreateParameter("@tid", tpl.Id, DbType.Int64);
             command.Parameters.Add(typeParam);
             command.Parameters.Add(itemParam);
             command.Parameters.Add(historyIdParam);
             command.Parameters.Add(tIdParam);
             command.ExecuteNonQuery();
         }
     }
 }
Beispiel #4
0
        public List<Template> TemplateList()
        {
            var templateList = new List<Template>();
            using (var conn = new SQLiteConnection(DataSource))
            {
                conn.Open();
                using (SQLiteCommand command = new SQLiteCommand(conn))
                {
                    var sql = "SELECT * FROM Template ORDER BY `id` DESC";
                    command.CommandText = sql;
                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        var dict = new Dictionary<string, object>();
                        dict["type"] = reader.GetValue(1);
                        dict["item"] = reader.GetValue(2);
                        var history_id = reader.GetInt64(3);

                        var history = historyOfId(history_id);
                        var template = new Template(dict);
                        template.Id = reader.GetInt64(0);
                        template.History = history;

                        templateList.Add(template);
                    }
                }
            }

            return templateList;
        }
Beispiel #5
0
        public long saveTemplate(Template tpl)
        {
            using (var conn = new SQLiteConnection(DataSource))
            {
                conn.Open();
                using (SQLiteCommand command = new SQLiteCommand(conn))
                {
                    command.CommandText = "INSERT INTO Template ('type', 'item', 'history_id') values (@type, @item, @history_id)";
                    var typeParam = SQLiteHelper.CreateParameter("@type", tpl.Type, DbType.String);
                    var itemParam = SQLiteHelper.CreateParameter("@item", tpl.Item, DbType.String);
                    var historyIdParam = SQLiteHelper.CreateParameter("@history_id", tpl.History.Id, DbType.Int64);
                    command.Parameters.Add(typeParam);
                    command.Parameters.Add(itemParam);
                    command.Parameters.Add(historyIdParam);
                    command.ExecuteNonQuery();

                    // signal id
                    long tplId = -1;
                    var sql = "SELECT * FROM Template ORDER BY `id` DESC LIMIT 1"; // Not thread safe.
                    command.CommandText = sql;
                    var reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        tplId = reader.GetInt64(0);
                    }
                    reader.Close();
                    return tplId;
                }
            }
        }
Beispiel #6
0
 public void deleteTemplate(Template tpl)
 {
     using (var conn = new SQLiteConnection(DataSource))
     {
         conn.Open();
         using (SQLiteCommand command = new SQLiteCommand(conn))
         {
             command.CommandText = "DELETE FROM Template WHERE `id` = @tid";
             var tIdParam = SQLiteHelper.CreateStringParameter("@tid", tpl.Id);
             command.Parameters.Add(tIdParam);
             command.ExecuteNonQuery();
         }
     }
 }
 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;
     }
 }