public static void EditFallidasRemoteServer(DataSet dt, ref int? codigoError, bool grabarFallidas) { MySqlTransaction tr = null; try { MySqlConnection SqlConnection1 = DALBase.GetRemoteConnection(); SqlConnection1.Open(); DAL.FondoCajaDAL.GrabarDB(dt, SqlConnection1); SqlConnection1.Close(); BL.FallidasBLL.BorrarFondoCajaFallidasByAccion("Modified"); } catch (MySqlException ex) { if (ex.Number == 1042) //no se pudo abrir la conexion por falta de internet { dt.RejectChanges(); codigoError = 1042; } else { dt.RejectChanges(); if (tr != null) { tr.Rollback(); } codigoError = ex.Number; } } catch (TimeoutException) { } }
public static void InsertRemotos(DataSet dt, MySqlConnection conn, MySqlTransaction tr) { try { MySqlDataAdapter da = AdaptadorInsert(conn, tr); da.Update(dt, "AlicuotasIva"); } catch (MySqlException ex) { MessageBox.Show(ex.ToString(), "Trend", MessageBoxButtons.OK, MessageBoxIcon.Information); dt.RejectChanges(); } }
public static void GrabarDB(DataSet dt, MySqlConnection SqlConnection1) { try { MySqlDataAdapter da = AdaptadorABM(SqlConnection1); da.Update(dt, "FondoCaja"); } catch (MySqlException) { // MessageBox.Show(ex.ToString(), "Trend", MessageBoxButtons.OK, MessageBoxIcon.Information); dt.RejectChanges(); } }
public static void InsertarRemotos(DataSet dt) { MySqlTransaction tr = null; try { MySqlConnection SqlConnection1 = DALBase.GetConnection(); SqlConnection1.Open(); tr = SqlConnection1.BeginTransaction(); DAL.ArticulosDAL.InsertarRemotos(dt, SqlConnection1, tr); tr.Commit(); SqlConnection1.Close(); } catch (MySqlException ex) { MessageBox.Show(ex.ToString(), "Trend", MessageBoxButtons.OK, MessageBoxIcon.Information); dt.RejectChanges(); tr.Rollback(); } }
public static void GrabarVentasFallidas(DataSet dt, MySqlConnection conn) { try { MySqlDataAdapter da = AdaptadorVentasFallidas(conn); da.Update(dt, "VentasFallidas"); } catch (MySqlException ex) { MessageBox.Show(ex.ToString(), "Trend", MessageBoxButtons.OK, MessageBoxIcon.Information); dt.RejectChanges(); } }
public string NewsEditSet(string tbl, int wh, string title, byte[] zipContents, string imageMode, byte[] buffer, string ext, string legal) { string msg = string.Empty; if (tLegal == legal.Trim() && isDaysLeft) { tbl = tbl.Trim(); title = title.Trim(); string body = Zipper.DecompressToStrng(zipContents).Trim(); ext = ext.Trim(); string sqlStr = "SELECT * FROM " + tbl; try { OleDbConnection cnn = new OleDbConnection(Base.cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); OleDbCommand cmd = new OleDbCommand(sqlStr, cnn); OleDbDataReader drr = cmd.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); dt = ds.Tables[tbl]; for (int i = 0; i < dt.Rows.Count; i++) { dr = dt.Rows[i]; if (Convert.ToInt32(dr["id"]) == wh) { dr.BeginEdit(); dr["header"] = EncDec.Encrypt(title.Trim(), Base.hashKey); dr["body"] = EncDec.Encrypt(body.Trim(), Base.hashKey); switch (imageMode) { case "old": break; case "clean": if (dr["pic"].ToString().Trim() != string.Empty) { msg = RemoveImages(new string[] { dr["pic"].ToString().Trim() }); if (msg != "Removed") return msg; dr["pic"] = string.Empty; } break; case "new": if (dr["pic"].ToString().Trim() != string.Empty) { msg = RemoveImages(new string[] { dr["pic"].ToString().Trim() }); if (msg != "Removed") return msg; dr["pic"] = string.Empty; } //msg = CatchImages("{" + tbl + "}/{" + wh + "}", new byte[][] { buffer }, new string[] { ext }, true); msg = CatchImages(tbl , new byte[][] { buffer }, new string[] { ext }, true); if (msg != "Created") return msg; dr["pic"] = pgImages[0]; break; default: break; } dr.EndEdit(); break; } } if (oda.Update(ds, tbl) == 1) { ds.AcceptChanges(); msg = "Updated"; } else { ds.RejectChanges(); msg = "Rejected"; } cnn.Close(); drr.Close(); ds.Dispose(); cmd.Dispose(); drr.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); dt.Dispose(); ds = null; ocb = null; oda = null; dr = null; dt = null; cmd = null; drr = null; cnn = null; } catch (Exception ex) { msg = ex.Message; } finally { tbl = null; sqlStr = null; } } else msg = errInvalidLegal; return msg; }
private void SaveProxy() { string tbl = "proxy"; string sqlStr = "SELECT * FROM " + tbl; try { OleDbConnection cnn = new OleDbConnection(Base.cnnStrLocal); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); dt = ds.Tables[tbl]; dr = dt.Rows[0]; dr.BeginEdit(); dr["useie"] = Base.proxyUseDefault; if (Base.proxyUseDefault) { dr["addr"] = "{IE}"; dr["port"] = "{IE}"; } else { dr["addr"] = Base.proxyAddr; dr["port"] = Base.proxyPort; } dr.EndEdit(); oda.UpdateCommand = ocb.GetUpdateCommand(); if (oda.Update(ds, tbl) == 1) { ds.AcceptChanges(); MessageBox.Show("تنظیمات پراکسی اعمال شد", Base.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1); } else { ds.RejectChanges(); } cnn.Close(); ds.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); dt.Dispose(); ds = null; ocb = null; oda = null; dr = null; dt = null; cnn = null; } catch (Exception ex) { MessageBox.Show(Base.errPrefix + ex.Message, Base.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { tbl = null; sqlStr = null; } }
public static void GrabarDB(DataSet dt, DataTable tblFallidas ,ref int? codigoError, bool grabarFallidas) { try { if (grabarFallidas == false) { DataSet dsRemoto; dsRemoto = dt.GetChanges(); DAL.ClientesDAL.GrabarDB(dt, grabarFallidas); lock (_sync) { Thread t = new Thread(() => ThreadSaveEnRemoteServer(dsRemoto, tblFallidas)); t.Start(); } } else { DAL.ClientesDAL.GrabarDB(dt, grabarFallidas); } } catch (MySqlException ex) { if (ex.Number == 1042) //no se pudo abrir la conexion por falta de internet { dt.RejectChanges(); ; codigoError = 1042; } else { dt.RejectChanges(); codigoError = ex.Number; } } }
public void RuleTest () { DataSet ds = new DataSet ("testds"); DataTable parent = ds.Tables.Add ("parent"); DataTable child = ds.Tables.Add ("child"); parent.Columns.Add ("id", typeof (int)); parent.Columns.Add ("name", typeof (string)); parent.PrimaryKey = new DataColumn [] {parent.Columns ["id"]} ; child.Columns.Add ("id", typeof (int)); child.Columns.Add ("parent", typeof (int)); child.Columns.Add ("name", typeof (string)); child.PrimaryKey = new DataColumn [] {child.Columns ["id"]} ; DataRelation relation = ds.Relations.Add ("parent_child", parent.Columns ["id"], child.Columns ["parent"]); parent.Rows.Add (new object [] {1, "mono test 1"}); parent.Rows.Add (new object [] {2, "mono test 2"}); parent.Rows.Add (new object [] {3, "mono test 3"}); child.Rows.Add (new object [] {1, 1, "mono child test 1"}); child.Rows.Add (new object [] {2, 2, "mono child test 2"}); child.Rows.Add (new object [] {3, 3, "mono child test 3"}); ds.AcceptChanges (); parent.Rows [0] ["name"] = "mono changed test 1"; Assert.AreEqual (DataRowState.Unchanged, parent.Rows [0].GetChildRows (relation) [0].RowState, "#RT1 child should not be modified"); ds.RejectChanges (); parent.Rows [0] ["id"] = "4"; DataRow childRow = parent.Rows [0].GetChildRows (relation) [0]; Assert.AreEqual (DataRowState.Modified, childRow.RowState, "#RT2 child should be modified"); Assert.AreEqual (4, (int) childRow ["parent"], "#RT3 child should point to modified row"); }
public static void InsertFallidasRemoteServer(DataSet dt, ref int? codigoError, bool grabarFallidas) { try { DAL.TesoreriaMovimientosDAL.GrabarDB(dt, grabarFallidas); DAL.FallidasDAL.BorrarTesoreriaFallidasByAccion("Added"); } catch (MySqlException ex) { if (ex.Number == 1042) //no se pudo abrir la conexion por falta de internet { dt.RejectChanges(); ; codigoError = 1042; } else { dt.RejectChanges(); codigoError = ex.Number; } } catch (TimeoutException) { } }
public string PreferencesSet(string tag, string val, string legal) { string msg = string.Empty; if (tLegal == legal.Trim() && isDaysLeft) { tag = tag.Trim(); val = val.Trim(); string tbl = "preferences"; string sqlStr = "SELECT * FROM " + tbl; try { OleDbConnection cnn = new OleDbConnection(Base.cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); OleDbCommand cmd = new OleDbCommand(sqlStr, cnn); cnn.Open(); OleDbDataReader drr = cmd.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); dt = ds.Tables[tbl]; for (int i = 0; i < dt.Rows.Count; i++) { dr = dt.Rows[i]; if (dr["tag"].ToString().Trim() == tag) { dr.BeginEdit(); dr["val"] = val; dr.EndEdit(); oda.UpdateCommand = ocb.GetUpdateCommand(); if (oda.Update(ds, tbl) == 1) { ds.AcceptChanges(); msg = "OK"; } else { ds.RejectChanges(); msg = "Rejected"; } break; } } drr.Close(); cnn.Close(); cmd.Dispose(); drr.Dispose(); ds.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); dt.Dispose(); cmd = null; drr = null; ds = null; ocb = null; oda = null; dr = null; dt = null; cnn = null; } catch(Exception ex) { msg = ex.Message; } finally { tbl = null; sqlStr = null; } } return msg; }
private bool CleanTable(string tbl) { bool success = true; try { string sqlStr = "SELECT * FROM " + tbl; OleDbConnection cnn = new OleDbConnection(Base.cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); oda.Fill(ds, tbl); dt = ds.Tables[tbl]; foreach (DataRow dr in dt.Rows) dr.Delete(); oda.DeleteCommand = ocb.GetDeleteCommand(); if (oda.Update(ds, tbl) == 1) ds.AcceptChanges(); else ds.RejectChanges(); cnn.Close(); dt.Dispose(); ds.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); dt = null; ds = null; ocb = null; oda = null; cnn = null; sqlStr = null; } catch { success = false; } finally { } return success; }
public string GoogleErase(string mailbox, string legal) { string msg = string.Empty; if (tLegal == legal.Trim() && isDaysLeft) { mailbox = mailbox.Trim(); string tbl = "google"; string sqlStr = "SELECT * FROM " + tbl; try { OleDbConnection cnn = new OleDbConnection(Base.cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); bool found = false; dt = ds.Tables[tbl]; mailbox = EncDec.Encrypt(mailbox, Base.hashKey); for (int i = 0; i < dt.Rows.Count; i++) { dr = dt.Rows[i]; if (dr["mailbox"].ToString().Trim() == mailbox) { found = true; dr.Delete(); oda.DeleteCommand = ocb.GetDeleteCommand(); if (oda.Update(ds, tbl) == 1) { msg = CleanPageImages(tbl + "\\" + mailbox); if (msg != "Cleaned") return msg; ds.AcceptChanges(); msg = "Erased"; } else { ds.RejectChanges(); msg = "Rejected"; } break; } } if (!found) msg = "Not Found"; cnn.Close(); ds.Dispose(); dt.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); ds = null; ocb = null; oda = null; dr = null; dt = null; cnn = null; } catch (Exception ex) { msg = ex.Message; } finally { tbl = null; sqlStr = null; } } else msg = errInvalidLegal; return msg; }
public string GoogleEdit(string mailbox, string newMailbox, string legal) { string msg = string.Empty; if (tLegal == legal.Trim() && isDaysLeft) { mailbox = mailbox.Trim(); newMailbox = newMailbox.Trim(); string tbl = "google"; string sqlStr = "SELECT * FROM " + tbl; try { OleDbConnection cnn = new OleDbConnection(Base.cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); OleDbCommand cmd = new OleDbCommand(sqlStr, cnn); OleDbDataReader drr = cmd.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); bool found = false; bool duplicate = false; mailbox = EncDec.Encrypt(mailbox, Base.hashKey); newMailbox = EncDec.Encrypt(newMailbox, Base.hashKey); while (drr.Read()) { if (drr["mailbox"].ToString().Trim() == mailbox) found = true; else if (drr["mailbox"].ToString().Trim() == newMailbox) duplicate = true; } if (found && !duplicate) { dt = ds.Tables[tbl]; for (int i = 0; i < dt.Rows.Count; i++) { dr = dt.Rows[i]; if (dr["mailbox"].ToString().Trim() == mailbox) { dr.BeginEdit(); dr["mailbox"] = newMailbox; dr.EndEdit(); oda.UpdateCommand = ocb.GetUpdateCommand(); if (oda.Update(ds, tbl) == 1) { msg = ReNewPageImages(tbl + "\\" + mailbox, tbl + "\\" + newMailbox); if (msg != "ReNewed") return msg; ds.AcceptChanges(); msg = "Updated"; } else { ds.RejectChanges(); msg = "Rejected"; } break; } } } else if (duplicate) msg = "Duplicate Error"; else msg = "Not Found"; cnn.Close(); drr.Close(); ds.Dispose(); cmd.Dispose(); drr.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); dt.Dispose(); ds = null; ocb = null; oda = null; dr = null; dt = null; cmd = null; drr = null; cnn = null; } catch (Exception ex) { msg = ex.Message; } finally { tbl = null; sqlStr = null; } } else msg = errInvalidLegal; return msg; }
public string GoogleAdd(string mailbox, string legal) { string msg = string.Empty; if (tLegal == legal.Trim() && isDaysLeft) { mailbox = mailbox.Trim(); string tbl = "google"; string sqlStr = "SELECT * FROM " + tbl; try { OleDbConnection cnn = new OleDbConnection(Base.cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); OleDbCommand cmd = new OleDbCommand(sqlStr, cnn); OleDbDataReader drr = cmd.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); bool found = false; mailbox = EncDec.Encrypt(mailbox, Base.hashKey); while (drr.Read()) { if (drr["mailbox"].ToString().Trim() == mailbox) { found = true; break; } } if (!found) { dt = ds.Tables[tbl]; dr = dt.NewRow(); dr["mailbox"] = mailbox; dt.Rows.Add(dr); oda.InsertCommand = ocb.GetInsertCommand(); if (oda.Update(ds, tbl) == 1) { ds.AcceptChanges(); msg = "Added"; } else { ds.RejectChanges(); msg = "Rejected"; } } else msg = "Already Exist"; cnn.Close(); drr.Close(); ds.Dispose(); dt.Dispose(); cmd.Dispose(); drr.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); ds = null; ocb = null; oda = null; dr = null; dt = null; cmd = null; drr = null; cnn = null; } catch (Exception ex) { msg = ex.Message; } finally { tbl = null; sqlStr = null; } } else msg = errInvalidLegal; return msg; }
public string CalendarEdit(string month, string day, string title, string newTitle, string body, string tbl, string legal) { string msg = string.Empty; if (tLegal == legal.Trim() && isDaysLeft) { month = month.Trim(); day = day.Trim(); title = title.Trim(); newTitle = newTitle.Trim(); body = body.Trim(); tbl = tbl.Trim(); string sqlStr = "SELECT * FROM " + tbl; try { OleDbConnection cnn = new OleDbConnection(Base.cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); OleDbCommand cmd = new OleDbCommand(sqlStr, cnn); OleDbDataReader drr = cmd.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); bool found = false; bool duplicate = false; bool isTitleChanged = title == newTitle ? false : true; while (drr.Read()) { if (EncDec.Decrypt(drr["title"].ToString(), Base.hashKey).Trim() == title) found = true; else if (EncDec.Decrypt(drr["title"].ToString().Trim(), Base.hashKey) == newTitle && isTitleChanged) duplicate = true; if (found && !isTitleChanged) { duplicate = false; break; } } if (found && !duplicate) { dt = ds.Tables[tbl]; for (int i = 0; i < dt.Rows.Count; i++) { dr = dt.Rows[i]; if (EncDec.Decrypt(dr["title"].ToString(), Base.hashKey).Trim() == title) { dr.BeginEdit(); dr["month"] = month; dr["day"] = day; if (isTitleChanged) dr["title"] = EncDec.Encrypt(newTitle, Base.hashKey); dr["body"] = EncDec.Encrypt(body, Base.hashKey); dr.EndEdit(); oda.UpdateCommand = ocb.GetUpdateCommand(); if (oda.Update(ds, tbl) == 1) { ds.AcceptChanges(); msg = "Updated"; } else { ds.RejectChanges(); msg = "Rejected"; } break; } } } else if (duplicate) msg = "Duplicate Error"; else msg = "Not Found"; cnn.Close(); drr.Close(); ds.Dispose(); cmd.Dispose(); drr.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); dt.Dispose(); ds = null; ocb = null; oda = null; dr = null; dt = null; cmd = null; drr = null; cnn = null; } catch (Exception ex) { msg = ex.Message; } finally { tbl = null; sqlStr = null; } } else msg = errInvalidLegal; return msg; }
public string AdminPwSet(string pw, string npw, string legal) { string msg = string.Empty; if (tLegal == legal.Trim() && isDaysLeft) { string tbl = "admin"; string sqlStr = "SELECT * FROM " + tbl; try { OleDbConnection cnn = new OleDbConnection(Base.cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); OleDbCommand cmd = new OleDbCommand(sqlStr, cnn); cnn.Open(); OleDbDataReader drr = cmd.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); while (drr.Read()) { string tPw = EncDec.Decrypt(drr["pw"].ToString(), Base.hashKey); if (tPw == pw.Trim()) msg = "OK"; else msg = "invalid"; break; } if (msg == "OK") { dt = ds.Tables[tbl]; dr = dt.Rows[0]; dr.BeginEdit(); dr["pw"] = EncDec.Encrypt(npw.Trim(), Base.hashKey); dr.EndEdit(); oda.UpdateCommand = ocb.GetUpdateCommand(); if (oda.Update(ds, tbl) == 1) { ds.AcceptChanges(); } else { ds.RejectChanges(); msg = "Rejected"; } } drr.Close(); cnn.Close(); cmd.Dispose(); drr.Dispose(); ds.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); dt.Dispose(); cmd = null; drr = null; ds = null; ocb = null; oda = null; dr = null; dt = null; cnn = null; } catch (Exception ex) { msg = ex.Message; } finally { tbl = null; sqlStr = null; } } else msg = errInvalidLegal; return msg; }
public string NodesAdd(string node, string parent, string fullPath, int zIndex, string tbl, string legal) { string msg = string.Empty; if (tLegal == legal.Trim() && isDaysLeft) { node = node.Trim(); parent = parent.Trim(); fullPath = fullPath.Trim(); tbl = tbl.Trim(); string sqlStr = "SELECT * FROM " + tbl; try { OleDbConnection cnn = new OleDbConnection(Base.cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); OleDbCommand cmd = new OleDbCommand(sqlStr, cnn); OleDbDataReader drr = cmd.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); bool found = false; while (drr.Read()) { if (drr["fullpath"].ToString().Trim() == fullPath) { found = true; break; } } if (!found) { dt = ds.Tables[tbl]; dr = dt.NewRow(); dr["pg"] = node.Trim(); dr["parent"] = parent.Trim(); dr["fullpath"] = fullPath.Trim(); dr["zindex"] = zIndex; dr["body"] = EncDec.Encrypt(" ", Base.hashKey); if (parent != "root") dr["viewcount"] = 0; else dr["viewcount"] = -1; dt.Rows.Add(dr); oda.InsertCommand = ocb.GetInsertCommand(); if (oda.Update(ds, tbl) == 1) { ds.AcceptChanges(); msg = "Added"; } else { ds.RejectChanges(); msg = "Rejected"; } } else msg = "Already Exist"; cnn.Close(); drr.Close(); ds.Dispose(); dt.Dispose(); cmd.Dispose(); drr.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); ds = null; ocb = null; oda = null; dr = null; dt = null; cmd = null; drr = null; cnn = null; } catch (Exception ex) { msg = ex.Message; } finally { tbl = null; sqlStr = null; } } else msg = errInvalidLegal; return msg; }
public static void GrabarDB(DataSet dt, ref int? codigoError, bool grabarFallidas) { try { if (grabarFallidas == false) { DataSet dsRemoto; dsRemoto = dt.GetChanges(); DAL.TesoreriaMovimientosDAL.GrabarDB(dt, grabarFallidas); lock (_sync) { Thread t = new Thread(() => bckWrk_DoWork(dsRemoto)); t.Start(); } } else { DAL.TesoreriaMovimientosDAL.GrabarDB(dt, grabarFallidas); } } catch (MySqlException ex) { if (ex.Number == 1042) //no se pudo abrir la conexion por falta de internet { dt.RejectChanges(); ; codigoError = 1042; } else { dt.RejectChanges(); codigoError = ex.Number; } } }
private void GenerateReport(DataTable dtReports) { Base.CleanTable(Base.tblReports, Base.cnnStrReports); try { DataRow drReports; string sqlStr = "SELECT * FROM " + Base.tblReports; OleDbConnection cnn = new OleDbConnection(Base.cnnStrReports); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; oda.Fill(ds, Base.tblReports); dt = ds.Tables[Base.tblReports]; for (int i = 0; i < dtReports.Rows.Count; i++) { dr = dt.NewRow(); drReports = dtReports.Rows[i]; dr[0] = drReports[0]; dr[1] = drReports[1]; dt.Rows.Add(dr); } oda.DeleteCommand = ocb.GetDeleteCommand(); if (oda.Update(ds, Base.tblReports) == 1) ds.AcceptChanges(); else ds.RejectChanges(); sqlStr = null; cnn.Close(); dt.Dispose(); ds.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); dr = null; dt = null; ds = null; ocb = null; oda = null; cnn = null; this.Activate(); rptViewCount.Focus(); rptViewCount.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.FullPage; this.PageRanksTableAdapter.Fill(this.reportsDataSet.PageRanks); this.rptViewCount.RefreshReport(); Base.CleanTable(Base.tblReports, Base.cnnStrReports); } catch (Exception ex) { MessageBox.Show(errReport + ex.Message, errReportHeader, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign); Base.Loading(this, false); return; } finally { } }
public void ChangePass(string UserName, string Pass) { adminDO = new AdminDO(); dsUser = adminDO.GetUser(UserName); DataRow dr = dsUser.Tables[0].Rows[0]; SetUserData(ref dr); string str = WorkingContext.LangManager.GetString("frmChangePass_Thongbao1"); int ret = 0; try { ret = adminDO.ChangePass(dsUser); } catch { } if (ret != 0) { string str1 = WorkingContext.LangManager.GetString("frmChangePass_Thongbao1_Title"); //MessageBox.Show("Cập nhật mật khẩu thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show(str1, str, MessageBoxButtons.OK, MessageBoxIcon.Information); dsUser.AcceptChanges(); this.Close(); } else { string str2 = WorkingContext.LangManager.GetString("frmChangePass_Thongbao2_Title"); //MessageBox.Show("Cập nhật mật khẩu thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(str2, str, MessageBoxButtons.OK, MessageBoxIcon.Information); dsUser.RejectChanges(); this.Close(); } }
public static void CleanTable(string tbl, string cnnStr) { try { string sqlStr = "SELECT * FROM " + tbl; OleDbConnection cnn = new OleDbConnection(cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); oda.Fill(ds, tbl); dt = ds.Tables[tbl]; foreach (DataRow dr in dt.Rows) dr.Delete(); oda.DeleteCommand = ocb.GetDeleteCommand(); if (oda.Update(ds, tbl) == 1) ds.AcceptChanges(); else ds.RejectChanges(); cnn.Close(); dt.Dispose(); ds.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); dt = null; ds = null; ocb = null; oda = null; cnn = null; sqlStr = null; } catch { } finally { } }
public void GetChanges_Relations_DifferentRowStatesTest () { DataSet ds = new DataSet ("ds"); DataTable parent = ds.Tables.Add ("parent"); DataTable child = ds.Tables.Add ("child"); parent.Columns.Add ("id", typeof (int)); parent.Columns.Add ("name", typeof (string)); child.Columns.Add ("id", typeof (int)); child.Columns.Add ("parent", typeof (int)); child.Columns.Add ("name", typeof (string)); parent.Rows.Add (new object [] { 1, "mono parent 1" } ); parent.Rows.Add (new object [] { 2, "mono parent 2" } ); parent.Rows.Add (new object [] { 3, "mono parent 3" } ); parent.Rows.Add (new object [] { 4, "mono parent 4" } ); parent.AcceptChanges (); child.Rows.Add (new object [] { 1, 1, "mono child 1" } ); child.Rows.Add (new object [] { 2, 2, "mono child 2" } ); child.Rows.Add (new object [] { 3, 3, "mono child 3" } ); child.AcceptChanges (); DataRelation relation = ds.Relations.Add ("parent_child", parent.Columns ["id"], child.Columns ["parent"]); // modify the parent and get changes child.Rows [1]["parent"] = 4; DataSet changes = ds.GetChanges (); DataRow row = changes.Tables ["parent"].Rows[0]; Assert.AreEqual ((int) parent.Rows [3][0], (int) row [0], "#RT1"); Assert.AreEqual (1, changes.Tables ["parent"].Rows.Count, "#RT2 only get parent row with current version"); ds.RejectChanges (); // delete a child row and get changes. child.Rows [0].Delete (); changes = ds.GetChanges (); Assert.AreEqual (changes.Tables.Count, 2, "#RT3 Should import parent table as well"); Assert.AreEqual (1, changes.Tables ["parent"].Rows.Count, "#RT4 only get parent row with original version"); Assert.AreEqual (1, (int) changes.Tables ["parent"].Rows [0][0], "#RT5 parent row based on original version"); }
public static void GrabarDB(DataSet dt, ref int? codigoError, bool grabarFallidas) { MySqlTransaction tr = null; try { if (grabarFallidas == false) { DataSet dsRemoto = dt.GetChanges(); MySqlConnection SqlConnection1 = DALBase.GetConnection(); SqlConnection1.Open(); DAL.FondoCajaDAL.GrabarDB(dt, SqlConnection1); SqlConnection1.Close(); lock (_sync) { Thread t = new Thread(() => bckWrk_DoWork(dsRemoto)); t.Start(); } } else { MySqlConnection SqlConnection1 = DALBase.GetRemoteConnection(); SqlConnection1.Open(); DAL.FondoCajaDAL.GrabarDB(dt, SqlConnection1); SqlConnection1.Close(); } } catch (MySqlException ex) { if (ex.Number == 1042) //no se pudo abrir la conexion por falta de internet { dt.RejectChanges(); codigoError = 1042; } else { dt.RejectChanges(); if (tr != null) { tr.Rollback(); } codigoError = ex.Number; } } }
public static void GrabarFallidasRemoteServer(DataSet dt, ref int? codigoError, bool grabarFallidas, string accionFallidas) { try { DAL.ClientesDAL.GrabarDB(dt, grabarFallidas); DAL.ClientesDAL.BorrarClienteFallidasByAccion(accionFallidas); } catch (MySqlException ex) { if (ex.Number == 1042) //no se pudo abrir la conexion por falta de internet { dt.RejectChanges(); ; codigoError = 1042; } else { dt.RejectChanges(); codigoError = ex.Number; } } catch (TimeoutException) { } }
public string NewsSetArchive(string tbl, int wh, string legal) { string msg = string.Empty; if (tLegal == legal.Trim() && isDaysLeft) { tbl = tbl.Trim(); string sqlStr = "SELECT * FROM " + tbl; try { OleDbConnection cnn = new OleDbConnection(Base.cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); OleDbCommand cmd = new OleDbCommand(sqlStr, cnn); OleDbDataReader drr = cmd.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); dt = ds.Tables[tbl]; for (int i = 0; i < dt.Rows.Count; i++) { dr = dt.Rows[i]; if (Convert.ToInt32(dr["id"]) == wh) { dr.BeginEdit(); dr["archived"] = !Convert.ToBoolean(dr["archived"]); dr.EndEdit(); break; } } oda.UpdateCommand = ocb.GetUpdateCommand(); if (oda.Update(ds, tbl) == 1) { ds.AcceptChanges(); msg = "Updated"; } else { ds.RejectChanges(); msg = "Rejected"; } cnn.Close(); drr.Close(); ds.Dispose(); cmd.Dispose(); drr.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); dt.Dispose(); ds = null; ocb = null; oda = null; dr = null; dt = null; cmd = null; drr = null; cnn = null; } catch (Exception ex) { msg = ex.Message; } finally { tbl = null; sqlStr = null; } } else msg = errInvalidLegal; return msg; }
[Test] public void RejectChanges() { DataSet ds1,ds2 = new DataSet(); ds2.Tables.Add(DataProvider.CreateParentDataTable()); ds1 = ds2.Copy(); //create changes ds2.Tables[0].Rows[0][0] = "70"; ds2.Tables[0].Rows[1].Delete(); ds2.Tables[0].Rows.Add(new object[] {9,"string1","string2"}); // RejectChanges ds2.RejectChanges(); Assert.AreEqual(ds2.GetXml(), ds1.GetXml(), "DS345"); }
public static void GrabarTesoreriaFallidas(DataSet dt) { try { SqlConnection1 = DALBase.GetConnection(); MySqlDataAdapter da = AdaptadorTesoreriaFallidas(SqlConnection1); da.Update(dt, "TesoreriaMovimientosFallidas"); SqlConnection1.Close(); } catch (MySqlException ex) { MessageBox.Show(ex.ToString(), "Trend", MessageBoxButtons.OK, MessageBoxIcon.Information); dt.RejectChanges(); } }
public string NewsAdd(string tbl, string title, byte[] zipContents, byte[] buffer, string ext, string legal) { string msg = string.Empty; if (tLegal == legal.Trim() && isDaysLeft) { tbl = tbl.Trim(); title = title.Trim(); string body = Zipper.DecompressToStrng(zipContents).Trim(); ext = ext.Trim(); string sqlStr = "SELECT * FROM " + tbl; try { OleDbConnection cnn = new OleDbConnection(Base.cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); OleDbCommand cmd = new OleDbCommand(sqlStr, cnn); OleDbDataReader drr = cmd.ExecuteReader(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); dt = ds.Tables[tbl]; dr = dt.NewRow(); int id = dt.Rows.Count + 1; if (buffer.Length > 0) { //msg = CatchImages("{" + tbl + "}/{" + id + "}", new byte[][] { buffer }, new string[] { ext }, true); msg = CatchImages(tbl , new byte[][] { buffer }, new string[] { ext }, true); if (msg != "Created") return msg; dr["pic"] = pgImages[0]; } dr["id"] = id; dr["header"] = EncDec.Encrypt(title.Trim(), Base.hashKey); dr["body"] = EncDec.Encrypt(body.Trim(), Base.hashKey); dr["archived"] = false; string date = string.Empty; if (tbl == "newsfa") date = Base.GetPersianDate(); else if (tbl == "newsen") date = Base.GetGregorianDate(); else if (tbl == "newsar") date = Base.GetHijriDate(); dr["date"] = Base.FormatDateToRaw(date); dt.Rows.Add(dr); oda.InsertCommand = ocb.GetInsertCommand(); if (oda.Update(ds, tbl) == 1) { ds.AcceptChanges(); msg = "Added"; } else { ds.RejectChanges(); msg = "Rejected"; } cnn.Close(); drr.Close(); ds.Dispose(); dt.Dispose(); cmd.Dispose(); drr.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); ds = null; ocb = null; oda = null; dr = null; dt = null; cmd = null; drr = null; cnn = null; } catch (Exception ex) { msg = ex.Message; } finally { tbl = null; sqlStr = null; } } else msg = errInvalidLegal; return msg; }
public string NewsErase(string tbl, int wh, string legal) { string msg = string.Empty; if (tLegal == legal.Trim() && IsDaysLeft()) { tbl = tbl.Trim(); string sqlStr = "SELECT * FROM " + tbl; try { OleDbConnection cnn = new OleDbConnection(Base.cnnStr); OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn); OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda); cnn.Open(); DataSet ds = new DataSet(); DataTable dt = new DataTable(); DataRow dr; ocb.QuotePrefix = "["; ocb.QuoteSuffix = "]"; oda.Fill(ds, tbl); bool found = false; bool isDeleted = false; dt = ds.Tables[tbl]; for (int i = 0; i < dt.Rows.Count; i++) { dr = dt.Rows[i]; if (isDeleted) { dr.BeginEdit(); dr["id"] = i + 1; dr.EndEdit(); oda.UpdateCommand = ocb.GetUpdateCommand(); if (oda.Update(ds, tbl) == 1) { ds.AcceptChanges(); msg = "Erased"; } else { ds.RejectChanges(); msg = "Rejected"; break; } } else if (Convert.ToInt32(dr["id"]) == wh) { found = true; if (dr["pic"].ToString().Trim() != string.Empty) { msg = RemoveImages(new string[] { dr["pic"].ToString().Trim() }); if (msg != "Removed") return msg; } dr.Delete(); oda.DeleteCommand = ocb.GetDeleteCommand(); if (oda.Update(ds, tbl) == 1) { ds.AcceptChanges(); msg = "Erased"; } else { ds.RejectChanges(); msg = "Rejected"; break; } dt = ds.Tables[tbl]; isDeleted = true; --i; } } if (!found) msg = "Not Found"; cnn.Close(); ds.Dispose(); dt.Dispose(); ocb.Dispose(); oda.Dispose(); cnn.Dispose(); ds = null; ocb = null; oda = null; dr = null; dt = null; cnn = null; } catch (Exception ex) { msg = ex.Message; } finally { tbl = null; sqlStr = null; } } else msg = errInvalidLegal; return msg; }