protected virtual void OnButtonOkClicked(object sender, System.EventArgs e) { if (String.IsNullOrEmpty(entrTableName.Text)) { MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("please_enter_table_name"), "", Gtk.MessageType.Error, this); md.ShowDialog(); return; } if (fields.Count < 1) { MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, MainClass.Languages.Translate("no_fileds_define"), "", Gtk.MessageType.Error, this); md.ShowDialog(); return; } string tableName = entrTableName.Text; string sql = string.Format("CREATE TABLE {0}( ", tableName); for (int r = 0; r < fields.Count; r++) { string type = fields[r].Type; string defValue = fields[r].DefaultValue; sql = sql + fields[r].Name + " " + type; if (fields[r].NotNULL) { sql = sql + " " + "NOT NULL"; } if (!String.IsNullOrEmpty(defValue)) { if ((type.IndexOf("NUMERIC") > -1) || (type.IndexOf("INTEGER") > -1)) { sql = sql + " DEFAULT " + defValue; } else { sql = sql + " DEFAULT '" + defValue + "'"; } } if (r < fields.Count - 1) { sql = sql + ","; } } sql = sql + ") ;"; sqlLiteDal.RunSqlScalar(sql); //CreateTable(); this.Respond(ResponseType.Ok); }
private void DropTable() { if (!CheckSelectTable()) { return; } string sql = String.Format("DROP TABLE {0} ;", curentTable); if (sqlLiteDal.RunSqlScalar(sql)) { GetTables(); } }
/* * private string GetParams(JArray paramsArray){ * if(paramsArray == null) * return "()"; * string paramsString = "("; * foreach (JObject jo in paramsArray){ * StringBuilder param = new StringBuilder(); * string name = (string)jo["name"]; * string description = (string)jo["description"]; * string type = (string)jo["type"]; * * JValue optionalStr = (JValue)jo["optional"]; * bool optional = false; * if(optionalStr!=null){ * if (!bool.TryParse(optionalStr.ToString(),out optional)){ * optional = false; * } * } * * string optdefault = (string)jo["optdefault"]; * * JValue multipleStr = (JValue)jo["multiple"]; * bool multiple = false; * if(multipleStr!=null){ * if (!bool.TryParse(multipleStr.ToString(),out multiple)){ * multiple = false; * } * } * * param.Append(name); * * if(!String.IsNullOrEmpty(optdefault)) * param.Append("="+optdefault); * if((optional) && (String.IsNullOrEmpty(optdefault))) * param.Append("=undefined"); * * if(multiple) * param.Append(",.."); * * paramsString = paramsString + param.ToString()+","; * } * paramsString = paramsString.TrimEnd(','); * paramsString = paramsString+ ")"; * * return paramsString; * * } */ private void insertNewRow(string name, string signature, int type, string parent, string summary, string returnType) { string sql; signature = signature.Replace("'", ""); if (!String.IsNullOrEmpty(summary)) { summary = summary.Replace("'", ""); } if (String.IsNullOrEmpty(parent)) { sql = String.Format("INSERT INTO completed (name,signature,type,summary,returnType) values ( '{0}' , '{1}' , '{2}', '{3}','{4}' ) ;", name, signature, type, summary, returnType); } else { sql = String.Format("INSERT INTO completed (name,signature,type, parent,summary,returnType) values ( '{0}' , '{3}.{1}' , '{2}', '{3}', '{4}','{5}' ) ;", name, signature, type, parent, summary, returnType); } sqlLiteDal.RunSqlScalar(sql); }
protected virtual void OnBtnEditFieldClicked(object sender, System.EventArgs e) { TreeSelection ts = tvFields.Selection; TreeIter ti = new TreeIter(); ts.GetSelected(out ti); TreePath[] tp = ts.GetSelectedRows(); if (tp.Length < 1) { return; } FieldTable oldFT = (FieldTable)tvFields.Model.GetValue(ti, 4); if (oldFT == null) { return; } SqlLiteAddFiled sqlAddField = new SqlLiteAddFiled(oldFT, this); int result = sqlAddField.Run(); if (result == (int)ResponseType.Ok) { FieldTable newFT = sqlAddField.FieldTable; if (newFT != null) { string tempTable = "temp_" + tableName + "_backup"; string sqlBegin = "BEGIN TRANSACTION ;"; string sqlRename = String.Format(" ALTER TABLE {0} RENAME TO {1} ;", tableName, tempTable); string sqlReCreate = string.Format(" CREATE TABLE {0}( ", tableName); string oldColums = ""; string newColums = ""; for (int r = 0; r < fields.Count; r++) { if (fields[r].Name != oldFT.Name) { string dfltValue = fields[r].DefaultValue; string type = fields[r].Type; sqlReCreate = sqlReCreate + fields[r].Name + " " + type; if (fields[r].NotNULL) { sqlReCreate = sqlReCreate + " NOT NULL"; } if (!String.IsNullOrEmpty(dfltValue)) { if ((type.IndexOf("NUMERIC") > -1) || (type.IndexOf("INTEGER") > -1)) { sqlReCreate = sqlReCreate + " DEFAULT " + dfltValue; } else { if (!dfltValue.StartsWith("'")) { dfltValue = "'" + dfltValue; } if (!dfltValue.EndsWith("'")) { dfltValue = dfltValue + "'"; } sqlReCreate = sqlReCreate + " DEFAULT " + dfltValue; } } oldColums = oldColums + fields[r].Name; newColums = newColums + fields[r].Name; } else { string dfltValue = newFT.DefaultValue; string type = newFT.Type; sqlReCreate = sqlReCreate + newFT.Name + " " + type; if (newFT.NotNULL) { sqlReCreate = sqlReCreate + " NOT NULL"; } if (!String.IsNullOrEmpty(dfltValue)) { if ((type.IndexOf("NUMERIC") > -1) || (type.IndexOf("INTEGER") > -1)) { sqlReCreate = sqlReCreate + " DEFAULT " + dfltValue; } else { if (!dfltValue.StartsWith("'")) { dfltValue = "'" + dfltValue; } if (!dfltValue.EndsWith("'")) { dfltValue = dfltValue + "'"; } sqlReCreate = sqlReCreate + " DEFAULT " + dfltValue; } } oldColums = oldColums + fields[r].Name; newColums = newColums + newFT.Name; } if (r < fields.Count - 1) { sqlReCreate = sqlReCreate + ","; oldColums = oldColums + ","; newColums = newColums + ","; } } sqlReCreate = sqlReCreate + ") ;"; string sqlInsertInto = string.Format(" INSERT INTO {0}( {1} ) SELECT {2} FROM {3} ;", tableName, newColums, oldColums, tempTable); string sqlDropTable = string.Format(" DROP TABLE {0} ;", tempTable); string sqlEnd = "COMMIT ;"; string sql = sqlBegin + "\n" + sqlRename + "\n" + sqlReCreate + "\n" + sqlInsertInto + "\n" + sqlDropTable + "\n" + sqlEnd; //Console.WriteLine(sql); if (sqlLiteDal.RunSqlScalar(sql)) { //fields.Remove(oldFT); //fieldsStore.SetValue(ti, GetTableStructure(); } else { // nepodarilo sa vymazanie, dam naspet //fields.Add(oldFT); } } } sqlAddField.Destroy(); }
protected override void OnActivated() { MessageDialogs md = new MessageDialogs(MessageDialogs.DialogButtonType.OkCancel, "Are you sure?", "", Gtk.MessageType.Question); int result = md.ShowDialog(); if (result != (int)Gtk.ResponseType.Ok) { return; } ProgressDialog progressDialog; string filename = System.IO.Path.Combine(MainClass.Paths.ConfingDir, "completedcache"); sqlLiteDal = new SqlLiteDal(filename); string sql = ""; if (sqlLiteDal.CheckExistTable("completed")) { sql = "DROP TABLE completed ;"; sqlLiteDal.RunSqlScalar(sql); } sql = "CREATE TABLE completed (id INTEGER PRIMARY KEY, name TEXT, signature TEXT, type NUMERIC, parent TEXT,summary TEXT ,returnType TEXT ) ;"; sqlLiteDal.RunSqlScalar(sql); SyntaxMode mode = new SyntaxMode(); mode = SyntaxModeService.GetSyntaxMode("text/moscrif"); progressDialog = new ProgressDialog("Generated...", ProgressDialog.CancelButtonType.None, mode.Keywords.Count(), MainClass.MainWindow); foreach (Keywords kw in mode.Keywords) { progressDialog.Update(kw.ToString()); foreach (string wrd in kw.Words) { insertNewRow(wrd, wrd, (int)CompletionDataTyp.keywords, "", "", ""); } } Gtk.FileChooserDialog fc = new Gtk.FileChooserDialog("data.json", null, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept); fc.TransientFor = MainClass.MainWindow; fc.SetCurrentFolder(@"d:\Work\docs-api\output\"); if (fc.Run() != (int)ResponseType.Accept) { return; } string json; string fileName = fc.Filename; progressDialog.Destroy(); fc.Destroy(); progressDialog = new ProgressDialog("Generated...", ProgressDialog.CancelButtonType.None, 100, MainClass.MainWindow); using (StreamReader file = new StreamReader(fileName)) { json = file.ReadToEnd(); file.Close(); file.Dispose(); } //XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json); //doc.Save(fileName+"xml"); /*JObject jDoc= JObject.Parse(json); * //classes * Console.WriteLine("o.Count->"+jDoc.Count); * * foreach (JProperty jp in jDoc.Properties()){ * Console.WriteLine(jp.Name); * } * Console.WriteLine("------------"); * JObject classes = (JObject)jDoc["classes"]; * foreach (JProperty jp in classes.Properties()){ * Console.WriteLine(jp.Name); * JObject classDefin = (JObject)classes[jp.Name]; * string name = (string)classDefin["name"]; * string shortname = (string)classDefin["shortname"]; * string description = (string)classDefin["description"]; * //string type = (string)classDefin["type"]; * insertNewRow(name,name,(int)CompletionDataTyp.types,"",description,name); * } * Console.WriteLine("------------"); * * JArray classitems = (JArray)jDoc["classitems"]; * foreach (JObject classitem in classitems){ * * string name = (string)classitem["name"]; * Console.WriteLine(name); * * string description = (string)classitem["description"]; * string itemtype = (string)classitem["itemtype"]; * string classParent = (string)classitem["class"]; * string signature = (string)classitem["name"]; * CompletionDataTyp type = CompletionDataTyp.noting; * string returnType= classParent; * * switch (itemtype){ * case "method":{ * JArray paramsArray = (JArray)classitem["params"]; * signature = signature+ GetParams(paramsArray); * type = CompletionDataTyp.members; * JObject returnJO =(JObject)classitem["return"] ; * if(returnJO!=null){ * returnType = (string)returnJO["type"]; * } * * break; * } * case "property":{ * * string tmpType = (string)classitem["type"]; * if(!String.IsNullOrEmpty(tmpType)){ * returnType=tmpType.Replace("{","").Replace("}",""); * } * type = CompletionDataTyp.properties; * break; * } * case "event":{ * JArray paramsArray = (JArray)classitem["params"]; * signature = signature+ GetParams(paramsArray); * type = CompletionDataTyp.events; * break; * } * case "attribute":{ * continue; * break; * } * default:{ * type = CompletionDataTyp.noting; * break; * } * * } * * insertNewRow(name,signature,(int)type,classParent,description,returnType); * }*/ //classitems // string name = (string)o["project"]["name"]; // Console.WriteLine(name); progressDialog.Destroy(); md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, "Done", "", Gtk.MessageType.Info); md.ShowDialog(); return; /* * * Gtk.FileChooserDialog fc = new Gtk.FileChooserDialog("Select DOC Directory (with xml)", null, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept); * FileInfo[] xmls = new FileInfo[]{}; * * if (fc.Run() == (int)ResponseType.Accept) { * * DirectoryInfo di = new DirectoryInfo(fc.Filename); * xmls = di.GetFiles("*.xml"); * //List<string> output = new List<string>(); * * //MainClass.CompletedCache.ListTypes= listSignature.Distinct().ToList(); * //MainClass.CompletedCache.ListMembers= listMemberSignature.Distinct().ToList(); * } * progressDialog.Destroy(); * fc.Destroy(); * progressDialog = new ProgressDialog("Generated...",ProgressDialog.CancelButtonType.None,xmls.Length ,MainClass.MainWindow); * foreach (FileInfo xml in xmls) * { * try * { * progressDialog.Update(xml.Name); * if(!xml.Name.StartsWith("_")) * getObject(xml.FullName); * } * catch(Exception ex) { * Console.WriteLine(ex.Message); * Console.WriteLine(ex.StackTrace); * return; * } * } * progressDialog.Destroy(); * * md = new MessageDialogs(MessageDialogs.DialogButtonType.Ok, "Done", "", Gtk.MessageType.Info); * md.ShowDialog();*/ }