Пример #1
0
 static void OnRemove(object sender, EventArgs e)
 {
     if (QuickGTK.Confirm($"Are you sure you want to remove {sc_rec}?"))
     {
         MyDataBase.RemoveRec(sc_rec);
         Pages.Sensitive       = false;
         ButRemove.Sensitive   = false;
         ButForceMod.Sensitive = false;
         sc_rec = "";
         //QuickGTK.Info("KILL AND DESTROY!!"); // debug
     }
 }
Пример #2
0
        static void OnQIConfirm(object sender, EventArgs e)
        {
            var input = QI_Input.Text;
            var name  = input.ToUpper();

            MenuBoxInput.Hide();
            if (!QIValidName(name))
            {
                QuickGTK.Error("Invalid record name!\n\nRecord names may only contain letters, numbers and underscores!"); return;
            }
            if (MyDataBase.Record.ContainsKey(name))
            {
                if (!QuickGTK.Confirm($"A record named {name} already exists!\n\nIf you continue the old record will be destroyed and replaced by the new one!\n\nAre you sure?"))
                {
                    return;
                }
            }
            switch (want)
            {
            case "NEW":
                var newrec = new MyRecord();
                MyDataBase.Record[name] = newrec;
                foreach (string k in MyDataBase.fields.Keys)
                {
                    var uk = k.ToUpper();
                    newrec.value[k] = "";
                    switch (MyDataBase.fields[k])
                    {
                    case "int":
                    case "double":
                        newrec.value[k] = "0";
                        break;

                    case "bool":
                        newrec.value[k] = "FALSE";
                        break;

                    case "date":
                        newrec.value[k] = "19/6/1975";
                        break;

                    case "time":
                        newrec.value[k] = "00:00:00";
                        break;
                    }
                    if (MyDataBase.defaults.ContainsKey(uk))
                    {
                        newrec.value[k] = MyDataBase.defaults[uk];
                    }
                    Console.WriteLine($"Field: {MyDataBase.fields[k]} {k} = {newrec.value[k]}");
                }
                newrec.MODIFIED = true;
                MyDataBase.UpdateRecView();
                // TODO: New record should add default values if set.
                QuickGTK.Info($"Record {name} has been created!");
                break;

            case "DUPE":
                var rec = MyDataBase.Record[sc_rec];
                newrec = new MyRecord();
                MyDataBase.Record[name] = newrec;
                foreach (string k in MyDataBase.fields.Keys)
                {
                    newrec.value[k] = rec.value[k];
                }
                newrec.MODIFIED = true;
                MyDataBase.UpdateRecView();
                QuickGTK.Info($"Record {sc_rec} has been duplicated into {name}");
                break;

            case "RENAME":
                var crec = MyDataBase.Record[sc_rec];
                MyDataBase.Record.Remove(sc_rec);
                MyDataBase.Record[name] = crec;
                crec.MODIFIED           = true;
                MyDataBase.UpdateRecView();
                QuickGTK.Info($"Record {sc_rec} has been renamed to {name}\n\nWARNING!\nIf you've set MyData to record-by-record export files with the old name will remain!");
                break;

            default:
                QuickGTK.Error($"Internal error!\n\n\nInvalid input request --> {want}!");
                break;
            }
        }