public static void SaveLineLisansCFG(string key, string value) { try { var path = Path.GetDirectoryName(Application.ExecutablePath) + "\\Artez.ls"; bool writeCheck = false; if (File.Exists(path)) { string[] lines = System.IO.File.ReadAllLines(path); for (int i = 0; i < lines.Length; i++) { lines[i] = Decryption(lines[i]); } System.IO.File.WriteAllText(path, string.Empty); foreach (string line in lines) { using (var tw = new StreamWriter(path, true)) { if (line.Split(';').Length == 2 && line.Split(';')[0] == key) { tw.WriteLine(ArsLibrary.Encryption(key + ";" + value)); writeCheck = true; } else { tw.WriteLine(ArsLibrary.Encryption(line)); } } } } if (!writeCheck) { using (var tw = new StreamWriter(path, true)) { tw.WriteLine(ArsLibrary.Encryption(key + ";" + value)); } } } catch (Exception ex) { ArsMessage.ShowMessage("Hata", ex.Message); } }
private void OpenSQL() { try { if (TableName == "") { TableName = SQLText.BetweenChars('[', ']'); } if (WhereStr == "") { WhereStr = SQLText.BetweenStrings("/*WS*/", "/*WE*/"); } if (!ArsLibrary.offline) { WebService.sqlserviceSoapClient service = new WebService.sqlserviceSoapClient(); XmlNode result = service.SQLExec(apiKey, apiPassword, dbName, SQLText); foreach (XmlElement element in result.ChildNodes) { if (element.Name == "Return") { foreach (XmlElement returnElement in element.ChildNodes) { if (returnElement.Name == "Code") { errorCode = returnElement.InnerText; } else if (returnElement.Name == "Description") { description = Unzip(Convert.FromBase64String(returnElement.InnerText)); } } } else if (element.Name == "ResultXML") { resultXML = Unzip(Convert.FromBase64String(element.ChildNodes[0].InnerText)); } else if (element.Name == "ResultSchema") { schema = Unzip(Convert.FromBase64String(element.ChildNodes[0].InnerText)); } else if (element.Name == "ResultZipCode") { zipCode = Unzip(Convert.FromBase64String(element.ChildNodes[0].InnerText)); } } if (errorCode != "0") { ArsMessage.ShowMessage("Hata", "Bir Hata Oluştu.\nDetay:\n" + description); } else { XmlDecompress(); ReadXMLSchema(); } } else { if (lisansQry) { this.dbServerName = ArsLibrary.lisansDbServerName; this.dbUserName = ArsLibrary.lisansDbUserName; this.dbPassword = ArsLibrary.lisansDbPassword; this.dbName = ArsLibrary.lisansDbName; } else if (artezQry) { this.dbName = ArsLibrary.artezDbName; } if (dbServerName != "" && dbName != "" && dbUserName != "" && dbPassword != "") { SqlConnection conn = null; try { if (!ArsLibrary.isWindowsAuth) { conn = new SqlConnection("Data Source=" + dbServerName + "; Initial Catalog=" + dbName + "; User Id=" + dbUserName + "; password="******";"); } else { conn = new SqlConnection("Data Source=" + dbServerName + "; Initial Catalog=" + dbName + "; Persist Security Info=True; Integrated Security=true;"); } conn.Open(); SqlCommand command = new SqlCommand(SQLText, conn); DataTable dataTable = new DataTable(); SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(command); sqlDataAdapter.Fill(dataTable); sqlDataAdapter.Dispose(); errorCode = "0"; foreach (DataColumn column in dataTable.Columns) { tags.Add(column.ToString()); fields.Add(column.ToString()); } foreach (DataRow row in dataTable.Rows) { Dictionary <string, string> rowDic = new Dictionary <string, string>(); foreach (DataColumn column in dataTable.Columns) { rowDic.Add(column.ToString(), row[column.ToString()].ToString()); } resultSet.Add(rowDic); } dataSet.Tables.Add(dataTable); } catch (Exception e) { errorCode = "-2"; description = e.Message; } finally { if (errorCode != "0" && showErrorMessage) { ArsMessage.ShowMessage("Hata", "Bir Hata Oluştu.\nDetay:\n" + SQLText + "\n" + description); } conn.Close(); } } } } catch (Exception ex) { //ArsMessage.ShowMessage("Hata", "Bilinmeyen Bir Hata Oluştu\n" + ex.Message); } finally { } }
private void ExecSQL() { try { switch (Mode) { case EnmQryMode.Insert: string insStr = ""; bool firstFieldsCheckIns = false; if (fields.Contains("CREATE_USERNO")) { firstFieldsCheckIns = true; insStr += "INSERT INTO " + TableName + "(CREATE_USERNO, LAST_UPUSERNO, APP_VERSION"; } else { insStr += "INSERT INTO " + TableName + "("; } if (fields.Contains("SUBE_KODU")) { if (firstFieldsCheckIns) { insStr += ", SUBE_KODU"; } else { insStr += " SUBE_KODU"; } firstFieldsCheckIns = true; } bool firstFieldNameCheck = firstFieldsCheckIns; foreach (string fieldName in values.Keys) { if (firstFieldNameCheck) { insStr += ", " + fieldName; } else { insStr += " " + fieldName; firstFieldNameCheck = true; } } if (fields.Contains("CREATE_USERNO")) { insStr += ") OUTPUT INSERTED.REC_ID VALUES (" + ArsLibrary.userNo + ", " + ArsLibrary.userNo + ", '" + ArsLibrary.version + "'"; } else { insStr += ") OUTPUT INSERTED.REC_ID VALUES("; } if (fields.Contains("SUBE_KODU")) { insStr += ", '" + ArsLibrary.subeKodu + "'"; } foreach (string fieldName in values.Keys) { switch (values[fieldName]) { case string _: if (firstFieldsCheckIns) { if ((values[fieldName] as string) != "NULL") { insStr += ", '" + values[fieldName] + "'"; } else { insStr += ", NULL"; } } else { if ((values[fieldName] as string) != "NULL") { insStr += " '" + values[fieldName] + "'"; } else { insStr += " NULL"; } firstFieldsCheckIns = true; } break; case int _: if (firstFieldsCheckIns) { insStr += ", " + values[fieldName]; } else { insStr += " " + values[fieldName]; firstFieldsCheckIns = true; } break; case double _: if (firstFieldsCheckIns) { insStr += ", " + values[fieldName].ToString().Replace(',', '.'); } else { insStr += " " + values[fieldName].ToString().Replace(',', '.'); firstFieldsCheckIns = true; } break; case Image _: if (firstFieldsCheckIns) { insStr += ", 0x" + ArsLibrary.ByteArrayToString(ArsLibrary.ImageToByteArray(values[fieldName] as Image)); } else { insStr += " 0x" + ArsLibrary.ByteArrayToString(ArsLibrary.ImageToByteArray(values[fieldName] as Image)); firstFieldsCheckIns = true; } break; } } insStr += ")"; ArsSQLQry qryIns = new ArsSQLQry(); qryIns.lisansQry = lisansQry; qryIns.artezQry = artezQry; qryIns.SQLText = insStr; qryIns.Open(); if (qryIns.Found()) { insertRecID = qryIns.GetInt("REC_ID"); } execErrorCode = qryIns.errorCode; execDescription = qryIns.description; break; case EnmQryMode.Update: string updStr = ""; bool firstFieldsCheckInsUpd = false; if (fields.Contains("CREATE_USERNO")) { firstFieldsCheckInsUpd = true; updStr = "UPDATE " + TableName + " SET LAST_UPDATE = GETDATE(), LAST_UPUSERNO = " + ArsLibrary.userNo + ", APP_VERSION = '" + ArsLibrary.version + "', IS_CHANGED = 1"; } else { updStr = "UPDATE " + TableName + " SET"; } if (fields.Contains("SUBE_KODU")) { if (firstFieldsCheckInsUpd) { updStr += ", SUBE_KODU = '" + ArsLibrary.subeKodu + "'"; } else { updStr += " SUBE_KODU = '" + ArsLibrary.subeKodu + "'"; } firstFieldsCheckInsUpd = true; } foreach (string fieldName in values.Keys) { switch (values[fieldName]) { case string _: if (firstFieldsCheckInsUpd) { if ((values[fieldName] as string) != "NULL") { updStr += ", " + fieldName + " = '" + values[fieldName] + "'"; } else { updStr += ", " + fieldName + " = NULL"; } } else { if ((values[fieldName] as string) != "NULL") { updStr += " " + fieldName + " = '" + values[fieldName] + "'"; } else { updStr += " " + fieldName + " = NULL"; } firstFieldsCheckInsUpd = true; } break; case int _: if (firstFieldsCheckInsUpd) { updStr += ", " + fieldName + " = " + values[fieldName]; } else { updStr += " " + fieldName + " = " + values[fieldName]; firstFieldsCheckInsUpd = true; } break; case double _: if (firstFieldsCheckInsUpd) { updStr += ", " + fieldName + " = " + values[fieldName].ToString().Replace(',', '.'); } else { updStr += " " + fieldName + " = " + values[fieldName].ToString().Replace(',', '.'); firstFieldsCheckInsUpd = true; } break; case Image _: if (firstFieldsCheckInsUpd) { updStr += ", " + fieldName + " = 0x" + ArsLibrary.ByteArrayToString(ArsLibrary.ImageToByteArray(values[fieldName] as Image)); } else { updStr += " " + fieldName + " = 0x" + ArsLibrary.ByteArrayToString(ArsLibrary.ImageToByteArray(values[fieldName] as Image)); firstFieldsCheckInsUpd = true; } break; } } updStr += " WHERE " + WhereStr; ArsSQLQry qryUpd = new ArsSQLQry(); qryUpd.lisansQry = lisansQry; qryUpd.artezQry = artezQry; qryUpd.SQLText = updStr; qryUpd.Open(); execErrorCode = qryUpd.errorCode; execDescription = qryUpd.description; break; case EnmQryMode.Delete: string delStr = "DELETE FROM " + TableName + " WHERE " + WhereStr; ArsSQLQry qryDel = new ArsSQLQry(); qryDel.lisansQry = lisansQry; qryDel.artezQry = artezQry; qryDel.SQLText = delStr; qryDel.Open(); execErrorCode = qryDel.errorCode; execDescription = qryDel.description; break; } } catch (Exception ex) { ArsMessage.ShowMessage("Hata", "Bilinmeyen Bir Hata Oluştu\n" + ex.Message); } }
public static void SaveLineCFG(string key, string value) { var saveCheck = true; try { var path = Path.GetDirectoryName(Application.ExecutablePath) + "\\Artez.cfg"; var pathNew = Path.GetDirectoryName(Application.ExecutablePath) + "\\ArtezNew.cfg"; bool writeCheck = false; if (File.Exists(path)) { string[] lines = System.IO.File.ReadAllLines(path); for (int i = 0; i < lines.Length; i++) { lines[i] = Decryption(lines[i]); } if (File.Exists(pathNew)) { System.IO.File.WriteAllText(pathNew, string.Empty); } foreach (string line in lines) { using (var tw = new StreamWriter(pathNew, true)) { if (line.Split(';').Length >= 2 && line.Split(';')[0] == key) { tw.WriteLine(ArsLibrary.Encryption(key + ";" + value)); writeCheck = true; } else { tw.WriteLine(ArsLibrary.Encryption(line)); } } } } if (!writeCheck) { using (var tw = new StreamWriter(pathNew, true)) { tw.WriteLine(ArsLibrary.Encryption(key + ";" + value)); } } } catch (Exception ex) { ArsMessage.ShowMessage("Hata", ex.Message); saveCheck = false; }finally { if (saveCheck) { try { var path = Path.GetDirectoryName(Application.ExecutablePath) + "\\ArtezNew.cfg"; var path2 = Path.GetDirectoryName(Application.ExecutablePath) + "\\Artez.cfg"; var path3 = Path.GetDirectoryName(Application.ExecutablePath) + "\\ArtezOld.cfg"; if (File.Exists(path2)) { System.IO.File.Move(path2, Path.GetDirectoryName(Application.ExecutablePath) + "\\ArtezOld.cfg"); } System.IO.File.Move(path, Path.GetDirectoryName(Application.ExecutablePath) + "\\Artez.cfg"); System.IO.File.Delete(Path.GetDirectoryName(Application.ExecutablePath) + "\\ArtezNew.cfg"); if (File.Exists(path3)) { System.IO.File.Delete(Path.GetDirectoryName(Application.ExecutablePath) + "\\ArtezOld.cfg"); } } catch (Exception ex) { } } } }