private async Task <PushResponse> SendRecord(WebformData webdata, EbMobileForm Form, EbDataTable Dt, EbDataRow DataRow, int RowIndex) { PushResponse response = null; try { ClearWebFormData(webdata); SingleTable SingleTable = new SingleTable(); int localid = Convert.ToInt32(DataRow["id"]); SingleRow row = this.GetRow(Form, Dt, DataRow, RowIndex); SingleTable.Add(row); webdata.MultipleTables.Add(Form.TableName, SingleTable); await Form.UploadFiles(localid, webdata); this.GetLinesEnabledData(localid, Form, webdata); if (FormService.Instance == null) { new FormService(); } response = await FormService.Instance.SendFormDataAsync(null, webdata, 0, Form.WebFormRefId, row.LocId); response.LocalRowId = localid; } catch (Exception ex) { EbLog.Error("SyncServices.PushRow---" + ex.Message); } return(response); }
private void GetLinesEnabledData(int localid, EbMobileForm form, WebformData formData) { try { Dictionary <string, EbMobileControl> controls = form.ChildControls.ToControlDictionary(); foreach (var ctrl in controls.Values) { if (ctrl is ILinesEnabled Ilines) { SingleTable st = new SingleTable(); formData.MultipleTables.Add(Ilines.TableName, st); EbDataTable data = Ilines.GetLocalData(form.TableName, localid); foreach (var dr in data.Rows) { SingleRow row = new SingleRow { LocId = Convert.ToInt32(dr["eb_loc_id"]) }; row.Columns.AddRange(Ilines.GetColumnValues(data.Columns, dr)); st.Add(row); } } } } catch (Exception ex) { EbLog.Error(ex.Message); } }
public WebformData ToWebFormData() { WebformData wd = new WebformData(this.MasterTable); foreach (MobileTable table in this.Tables) { wd.MultipleTables.Add(table.TableName, new SingleTable()); foreach (var row in table) { var srow = new SingleRow { RowId = row.RowId, LocId = App.Settings.CurrentLocId, IsUpdate = (row.RowId > 0) }; foreach (var col in row.Columns) { srow.Columns.Add(new SingleColumn { Name = col.Name, Value = col.Value, Type = (int)col.Type }); } wd.MultipleTables[table.TableName].Add(srow); } } return(wd); }
private SingleRow GetRow(EbMobileForm Form, EbDataTable Dt, EbDataRow DataRow, int RowIndex) { SingleRow row = new SingleRow { RowId = 0, IsUpdate = false, LocId = Convert.ToInt32(DataRow["eb_loc_id"]), }; row.Columns.AddRange(Form.GetColumnValues(Dt, RowIndex)); return(row); }
private string DeleteIfExists(ref int i) { string insUpQ = string.Empty; SingleRow RowBkUp = this.TableBkUp.Find(e => e.RowId <= 0); if (RowBkUp != null) { insUpQ = this.GetMyActionDeleteQry(ref i, Convert.ToInt32(RowBkUp[FormConstants.eb_my_actions_id])); } if (this.TableBkUp.Count > 0) { insUpQ += this.GetApprovalUpdateQry(null, true, false); insUpQ += this.GetApprovalLinesDeleteQry(); } return(insUpQ); }
public _FG_Review(EbReview CtrlObj, SingleTable Table) { this.Name = CtrlObj.Name; this.CtrlObj = CtrlObj; this.Table = Table; SingleRow _Row = null; foreach (SingleRow Row in this.Table) { if (Row.RowId <= 0 && Row.Columns.Count > 0) { _Row = Row; break; } } this.stages = new Dictionary <string, _FG_Review_Stage>(); foreach (ReviewStageAbstract stage in this.CtrlObj.FormStages) { EbReviewStage _eb_stage = stage as EbReviewStage; List <_FG_Review_Action> fg_actions = new List <_FG_Review_Action>(); foreach (ReviewActionAbstract action in _eb_stage.StageActions) { fg_actions.Add(new _FG_Review_Action((action as EbReviewAction).Name)); } if (_Row != null && Convert.ToString(_Row["stage_unique_id"]) == _eb_stage.EbSid) { EbReviewAction eb_curAct = (EbReviewAction)_eb_stage.StageActions.Find(e => (e as EbReviewAction).EbSid == Convert.ToString(_Row["action_unique_id"])); _FG_Review_Action fg_curAct = null; if (eb_curAct != null) { fg_curAct = fg_actions.Find(e => e.name == eb_curAct.Name); } this.stages.Add(_eb_stage.Name, new _FG_Review_Stage(_eb_stage.Name, fg_actions, fg_curAct)); this.currentStage = this.stages[_eb_stage.Name]; } else { this.stages.Add(_eb_stage.Name, new _FG_Review_Stage(_eb_stage.Name, fg_actions, null)); } } }
private static FG_Review GetReviewGlobal(EbReview Rev, SingleTable Table, SingleTable TableBkUp) { Dictionary <string, FG_Review_Stage> stages = new Dictionary <string, FG_Review_Stage>(); FG_Review_Stage currentStage = null; SingleRow Row = null; foreach (SingleRow _Row in Table) { if (_Row.RowId <= 0 && _Row.Columns.Count > 0) { Row = _Row; break; } } foreach (EbReviewStage stage in Rev.FormStages) { List <FG_Review_Action> actions = new List <FG_Review_Action>(); foreach (EbReviewAction action in stage.StageActions) { actions.Add(new FG_Review_Action(action.Name)); } if (Row != null && Convert.ToString(Row["stage_unique_id"]) == stage.EbSid) { EbReviewAction curAct = stage.StageActions.Find(e => e.EbSid == Convert.ToString(Row["action_unique_id"])); FG_Review_Action fg_curAct = null; if (curAct != null) { fg_curAct = actions.Find(e => e.name == curAct.Name); } stages.Add(stage.Name, new FG_Review_Stage(stage.Name, actions, fg_curAct)); currentStage = stages[stage.Name]; } else { stages.Add(stage.Name, new FG_Review_Stage(stage.Name, actions, null)); } } return(new FG_Review(stages, currentStage)); }
private void CheckDGUniqe(SingleRow Row, ColumnSchema _column, TableSchema _table, List <string> Vals, EbWebForm WebForm) { if (Row.IsDelete) { return; } SingleColumn cField = Row.GetColumn(_column.ColumnName); if (cField == null || cField.Value == null || (Double.TryParse(Convert.ToString(cField.Value), out double __val) && __val == 0)) { return; } if (Vals.Contains(Convert.ToString(cField.Value))) { string msg2 = $" {(WebForm == MasterForm ? "" : "(DataPusher)")} {(cField.Control.Hidden ? "[Hidden]" : "")}"; string msg1 = $"Value in the '{(cField.Control as EbDGColumn).Title ?? cField.Control.Name}' column ({_table.Title ?? _table.ContainerName} Grid) must be unique" + msg2; msg2 = $"DG column is not unique. Control name: {_table.ContainerName}.{cField.Control.Name}" + msg2; throw new FormException(msg1, (int)HttpStatusCode.BadRequest, msg2, "EbWebFormCollection -> ExecUniqueCheck"); } Vals.Add(Convert.ToString(cField.Value)); }
public void SingleRow_Get_SetTests() { // Set value SingleRow singleRow = new SingleRow() { Name = "Name", City = "City", Id = "Id", ObjectState = ObjectState.Added }; //Get Value SingleRow singleRowSet = new SingleRow() { Name = singleRow.Name, City = singleRow.City, Id = singleRow.Id, ObjectState = singleRow.ObjectState }; Assert.IsTrue(true, singleRowSet.Name); }
public void ExecDGUniqueCheck() { foreach (EbWebForm WebForm in this) { if (WebForm.DataPusherConfig?.AllowPush == false) { continue; } foreach (TableSchema _table in WebForm.FormSchema.Tables.FindAll(e => e.TableType == WebFormTableTypes.Grid)) { if (!(WebForm.FormData.MultipleTables.TryGetValue(_table.TableName, out SingleTable Table) && Table.Count > 0)) { continue; } foreach (ColumnSchema _column in _table.Columns.FindAll(e => e.Control.Unique)) { List <string> Vals = new List <string>(); foreach (SingleRow Row in Table) { CheckDGUniqe(Row, _column, _table, Vals, WebForm); } if (WebForm.FormDataBackup != null && WebForm.FormDataBackup.MultipleTables.TryGetValue(_table.TableName, out SingleTable TableBkUp) && TableBkUp.Count > 0) { foreach (SingleRow RowBkUp in TableBkUp) { SingleRow Row = Table.Find(e => e.RowId == RowBkUp.RowId); if (Row == null) { CheckDGUniqe(RowBkUp, _column, _table, Vals, WebForm); } } } } } } }
private string UpdateMyAction(ref int i) { bool permissionGranted = false; if (this.TableBkUp.Count > 0) { SingleRow Row = this.TableBkUp.Find(e => e.RowId <= 0); if (Row != null && Convert.ToString(Row[FormConstants.eb_my_actions_id]) == Convert.ToString(this.Table[0][FormConstants.eb_my_actions_id])) { permissionGranted = true; } } if (!permissionGranted) { throw new FormException("Access denied to execute review", (int)HttpStatusCode.Unauthorized, $"Following entry is not present in FormDataBackup. eb_my_actions_id: {this.Table[0][FormConstants.eb_my_actions_id]} ", "From GetMyActionInsertUpdateQuery"); } string insUpQ = this.GetMyActionUpdateQry(i); this.param.Add(this.DataDB.GetNewParameter($"eb_my_actions_id_{i++}", EbDbTypes.Int32, this.Table[0][FormConstants.eb_my_actions_id])); Console.WriteLine("Will try to UPDATE eb_my_actions"); return(insUpQ); }
private void Pb_AddData_STK_Close_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; string[] Row = tb_AddData_Data.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None); DataTable STK = new DataTable(); DataRow STKRow; Data_Import.Singleton().Load_TxtToDataTable2(ref STK, "STK"); foreach (string SingleRow in Row) { string[] Part = SingleRow.Split('\t'); if (Part.Length > 1) { Part[0] = Part[0].Replace(" ", ""); STKRow = STK.Select(string.Format("ANC LIKE '%{0}%'", Part[0])).FirstOrDefault(); if (STKRow != null) { STKRow[Year.ToString()] = "01/00/" + Year.ToString(); STKRow["STK/" + Year.ToString()] = Part[1]; } else { STKRow = STK.NewRow(); STKRow["ANC"] = Part[0].ToString(); STKRow[Year.ToString()] = "01/00/" + Year.ToString(); STKRow["STK/" + Year.ToString()] = Part[1]; STK.Rows.Add(STKRow); } } } Data_Import.Singleton().Save_DataTableToTXT2(ref STK, "STK"); this.Close(); Cursor.Current = Cursors.Default; }
private static FG_DataGrid GetDataGridGlobal(EbDataGrid DG, SingleTable Table, SingleRow RowModel) { List <FG_Row> Rows = new List <FG_Row>(); Dictionary <string, object> Metas = null; foreach (SingleRow Row in Table) { if (Row.IsDelete) { continue; } FG_Row fG_Row = new FG_Row() { id = Convert.ToInt32(Row[FormConstants.id]) }; foreach (EbControl _control in DG.Controls) { if (_control is EbDGPowerSelectColumn) { Metas = new Dictionary <string, object>() { { FG_Constants.Columns, Row.GetColumn(_control.Name).R } } } ; else { Metas = null; } fG_Row.Controls.Add(new FG_Control(_control.Name, _control.ObjType, Row[_control.Name], Metas)); } Rows.Add(fG_Row); } FG_Row fG_RowModel = new FG_Row(); foreach (EbControl _control in DG.Controls) { if (_control is EbDGPowerSelectColumn) { Metas = new Dictionary <string, object>() { { FG_Constants.Columns, RowModel.GetColumn(_control.Name).R } } } ; else { Metas = null; } fG_RowModel.Controls.Add(new FG_Control(_control.Name, _control.ObjType, RowModel[_control.Name], Metas)); } return(new FG_DataGrid(DG.Name, Rows, fG_RowModel)); }
public int Execute() { try { if (RetrieveSchemaIndex == 0) { starting_point = SingleCol + SingleRow.ToString(); ending_point = SingleCol + SingleRow.ToString(); } if (RetrieveSchemaIndex == 1) { starting_point = RangeStartsatCol + RangeStartsatRow.ToString(); ending_point = RangeEndssatCol + RangeEndssatRow.ToString(); } MExcel.Worksheet excelSheet = VariableStorage.ExcelVar[ExcelFileToReadVar].Item2.ActiveWorkbook.ActiveSheet; MExcel.Range rng = (MExcel.Range)excelSheet.get_Range(starting_point, ending_point); Object[,] myvalues = (Object[, ])rng.Cells.Value; DataTable dt = new DataTable(); for (int dimension = 0; dimension < myvalues.Rank; dimension++) { dt.Columns.Add("Column" + (dimension + 1)); } for (int element = 0; element < (myvalues.Length / myvalues.Rank); element++) { DataRow row = dt.NewRow(); for (int dimension = 0; dimension < myvalues.Rank; dimension++) { string str = "Column" + (dimension + 1).ToString(); row[str] = myvalues[element + 1, dimension + 1]; } dt.Rows.Add(row); } if (VariableStorage.ExcelDataVar.ContainsKey(ExcelStoreVar)) { VariableStorage.ExcelDataVar.Remove(ExcelStoreVar); } VariableStorage.ExcelDataVar.Add(ExcelStoreVar, Tuple.Create(this.ID, dt)); DataTable dtt = dt; return(1); } catch (Exception ex) { return(0); } }
private List <AuditTrailEntry> GetTrailEntries(EbWebForm _webForm, TableSchema _table, SingleRow Row, SingleRow RowBkup) { string _newVal, _oldVal; bool isUpdate = RowBkup != null && Row != null; List <AuditTrailEntry> trailEntries = new List <AuditTrailEntry>(); string relation = string.Concat(_webForm.TableRowId, "-", Row != null ? Row.RowId : RowBkup.RowId); if (_webForm.FormSchema.MasterTable.Equals(_table.TableName)) { relation = _webForm.TableRowId.ToString(); } if (_table.TableType == WebFormTableTypes.Normal) { foreach (ColumnSchema _column in _table.Columns) { if (_column.Control.DoNotPersist) { continue; } _newVal = null; _oldVal = null; if (Row != null) { _newVal = Row[_column.ColumnName]?.ToString() ?? null; } if (RowBkup != null) { _oldVal = RowBkup[_column.ColumnName]?.ToString() ?? null; } if (isUpdate && _newVal == _oldVal) { continue; } trailEntries.Add(new AuditTrailEntry { Name = _column.ColumnName, NewVal = _newVal, OldVal = _oldVal, DataRel = relation, TableName = _table.TableName }); } } else { bool isChangeFound = false; Dictionary <string, string> dict4new = new Dictionary <string, string>(); Dictionary <string, string> dict4old = new Dictionary <string, string>(); foreach (ColumnSchema _column in _table.Columns) { if (_column.Control.DoNotPersist) { continue; } if (Row != null) { dict4new.Add(_column.ColumnName, Row[_column.ColumnName]?.ToString() ?? null); } if (RowBkup != null) { dict4old.Add(_column.ColumnName, RowBkup[_column.ColumnName]?.ToString() ?? null); } if (isUpdate && dict4new[_column.ColumnName] != dict4old[_column.ColumnName]) { isChangeFound = true; } } if (isUpdate && !isChangeFound)//no changes { return(trailEntries); } _newVal = null; _oldVal = null; if (Row != null) { _newVal = JsonConvert.SerializeObject(dict4new); } if (RowBkup != null) { _oldVal = JsonConvert.SerializeObject(dict4old); } trailEntries.Add(new AuditTrailEntry { Name = "RowData", NewVal = _newVal, OldVal = _oldVal, DataRel = relation, TableName = _table.TableName }); } return(trailEntries); }
private void Pb_AddData_Close_Click(object sender, EventArgs e) { //Action action = new Action(); Cursor.Current = Cursors.WaitCursor; string[] row = tb_AddData_Data.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None); int DuplicateCount = 0; bool IFCalc = false; if (row[0] != "") { if (Jak == "PNC") { DataGridView dg_PNC = (DataGridView)MainProgram.Self.TabControl.Controls.Find("dg_PNC", true).First(); if (dg_PNC.Rows.Count > 1) { DialogResult result = MessageBox.Show("Do you want replace all PNC in this Action ?", "Warning!", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { dg_PNC.Rows.Clear(); dg_PNC.Columns.Clear(); dg_PNC.Columns.Add("PNC", "PNC"); dg_PNC.Columns["PNC"].Width = 63; dg_PNC.Columns["PNC"].SortMode = DataGridViewColumnSortMode.NotSortable; IFCalc = true; } else if (result == DialogResult.No) { DialogResult result2 = MessageBox.Show("Do you want add this PNC to exisitng PNC for this Action ?", "Warning!", MessageBoxButtons.YesNo); if (result2 == DialogResult.Yes) { IFCalc = true; } else if (result2 == DialogResult.No) { IFCalc = false; } } } else { dg_PNC.Rows.Clear(); dg_PNC.Columns.Clear(); dg_PNC.Columns.Add("PNC", "PNC"); dg_PNC.Columns["PNC"].Width = 63; dg_PNC.Columns["PNC"].SortMode = DataGridViewColumnSortMode.NotSortable; IFCalc = true; } if (IFCalc) { foreach (string OneRow in row) { if (OneRow != "") { var Row = dg_PNC.Rows.Cast <DataGridViewRow>().Where(u => u.Cells["PNC"].Value.ToString().Equals(OneRow)).FirstOrDefault(); if (Row == null) { dg_PNC.Rows.Add(OneRow); } else { DuplicateCount++; } } } } this.Close(); Cursor.Current = Cursors.Default; if (DuplicateCount > 0) { MessageBox.Show($"Was remove {DuplicateCount} Duplicate Value", "Duplicate counter"); } return; } if (Jak == "PNCSpec") { DataGridView dg_PNC = (DataGridView)MainProgram.Self.TabControl.Controls.Find("dg_PNC", true).First(); if (dg_PNC.Rows.Count > 1) { DialogResult result = MessageBox.Show("Do you want replace all PNC in this Action ?", "Warning!", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { dg_PNC.Rows.Clear(); dg_PNC.Columns.Clear(); dg_PNC.Columns.Add("PNC", "PNC"); dg_PNC.Columns.Add("OLD ANC", "OLD ANC"); dg_PNC.Columns.Add("OLD Q", "Q"); dg_PNC.Columns.Add("NEW ANC", "NEW ANC"); dg_PNC.Columns.Add("NEW Q", "Q"); dg_PNC.Columns["PNC"].Width = 80; dg_PNC.Columns["OLD ANC"].Width = 65; dg_PNC.Columns["OLD ANC"].DefaultCellStyle.ForeColor = Color.Red; dg_PNC.Columns["OLD Q"].Width = 35; dg_PNC.Columns["OLD Q"].DefaultCellStyle.ForeColor = Color.Red; dg_PNC.Columns["NEW ANC"].Width = 65; dg_PNC.Columns["NEW ANC"].DefaultCellStyle.ForeColor = Color.Green; dg_PNC.Columns["NEW Q"].Width = 35; dg_PNC.Columns["NEW Q"].DefaultCellStyle.ForeColor = Color.Green; dg_PNC.Columns["PNC"].SortMode = DataGridViewColumnSortMode.NotSortable; dg_PNC.Columns["OLD ANC"].SortMode = DataGridViewColumnSortMode.NotSortable; dg_PNC.Columns["OLD Q"].SortMode = DataGridViewColumnSortMode.NotSortable; dg_PNC.Columns["NEW ANC"].SortMode = DataGridViewColumnSortMode.NotSortable; dg_PNC.Columns["NEW Q"].SortMode = DataGridViewColumnSortMode.NotSortable; IFCalc = true; } else if (result == DialogResult.No) { DialogResult result2 = MessageBox.Show("Do you want add this PNC to exisitng PNC for this Action ?", "Warning!", MessageBoxButtons.YesNo); if (result2 == DialogResult.Yes) { IFCalc = true; } else if (result2 == DialogResult.No) { IFCalc = false; } } } else { dg_PNC.Rows.Clear(); dg_PNC.Columns.Clear(); dg_PNC.Columns.Add("PNC", "PNC"); dg_PNC.Columns.Add("OLD ANC", "OLD ANC"); dg_PNC.Columns.Add("OLD Q", "Q"); dg_PNC.Columns.Add("NEW ANC", "NEW ANC"); dg_PNC.Columns.Add("NEW Q", "Q"); dg_PNC.Columns["PNC"].Width = 80; dg_PNC.Columns["OLD ANC"].Width = 65; dg_PNC.Columns["OLD ANC"].DefaultCellStyle.ForeColor = Color.Red; dg_PNC.Columns["OLD Q"].Width = 35; dg_PNC.Columns["OLD Q"].DefaultCellStyle.ForeColor = Color.Red; dg_PNC.Columns["NEW ANC"].Width = 65; dg_PNC.Columns["NEW ANC"].DefaultCellStyle.ForeColor = Color.Green; dg_PNC.Columns["NEW Q"].Width = 35; dg_PNC.Columns["NEW Q"].DefaultCellStyle.ForeColor = Color.Green; dg_PNC.Columns["PNC"].SortMode = DataGridViewColumnSortMode.NotSortable; dg_PNC.Columns["OLD ANC"].SortMode = DataGridViewColumnSortMode.NotSortable; dg_PNC.Columns["OLD Q"].SortMode = DataGridViewColumnSortMode.NotSortable; dg_PNC.Columns["NEW ANC"].SortMode = DataGridViewColumnSortMode.NotSortable; dg_PNC.Columns["NEW Q"].SortMode = DataGridViewColumnSortMode.NotSortable; IFCalc = true; } if (IFCalc) { foreach (string SingleRow in row) { if (SingleRow == string.Empty) { continue; } string[] SelectedRow = SingleRow.Split(';'); string PNC = SelectedRow[0]; string ECCC = string.Empty; int Limit = ((SelectedRow.Length - 3) / 2); if (SelectedRow[1].ToString() != string.Empty) { ECCC = "ECCC(" + SelectedRow[1] + ")"; } dg_PNC.Rows.Add(PNC, ECCC, string.Empty); dg_PNC.Rows[dg_PNC.Rows.Count - 1].DefaultCellStyle.BackColor = Color.LightBlue; dg_PNC.Rows[dg_PNC.Rows.Count - 1].DefaultCellStyle.Font = new Font(dg_PNC.Font, FontStyle.Bold); dg_PNC.Rows[dg_PNC.Rows.Count - 1].Cells[1].Style.Font = new Font(dg_PNC.Font, FontStyle.Regular); dg_PNC.Rows[dg_PNC.Rows.Count - 1].Cells[1].Style.Font = new Font("Tahoma", 10F, GraphicsUnit.Pixel); for (int counter2 = 2; counter2 < Limit + 2; counter2++) { if (SelectedRow[counter2] != string.Empty || SelectedRow[counter2 + Limit + 1] != string.Empty) { dg_PNC.Rows.Add(string.Empty, SelectedRow[counter2], SelectedRow[counter2 + 1], SelectedRow[counter2 + Limit + 1], SelectedRow[counter2 + Limit + 2]); } counter2++; } } } this.Close(); Cursor.Current = Cursors.Default; return; } } else { this.Close(); Cursor.Current = Cursors.Default; return; } if (Jak == "BU" || Jak == "EA1" || Jak == "EA2" || Jak == "EA3") { NumericUpDown Admin_Year = (NumericUpDown)MainProgram.Self.TabControl.Controls.Find("num_Admin_YearQuantity", true).First(); CheckBox cb_AdminPNC = (CheckBox)MainProgram.Self.TabControl.Controls.Find("cb_AdminPNC", true).First(); CheckBox cb_AdminANC = (CheckBox)MainProgram.Self.TabControl.Controls.Find("cb_AdminANC", true).First(); DataTable Baza = new DataTable(); DataRow FoundRow; int ile; if (cb_AdminANC.Checked) { Data_Import.Singleton().Load_TxtToDataTable2(ref Baza, "ANC"); } if (cb_AdminPNC.Checked) { Data_Import.Singleton().Load_TxtToDataTable2(ref Baza, "PNC"); } switch (Jak) { case "BU": ile = 1; break; case "EA1": ile = 3; break; case "EA2": ile = 6; break; case "EA3": ile = 9; break; default: return; } if (Baza.Columns.Contains(Jak + "/12/" + Admin_Year.Text)) { for (int counter = ile; counter <= 12; counter++) { Baza.Columns.Remove(Jak + "/" + counter + "/" + Admin_Year.Text); } } for (int counter = ile; counter <= 12; counter++) { Baza.Columns.Add(new DataColumn(Jak + "/" + counter + "/" + Admin_Year.Text)); } foreach (string OneRow in row) { string[] row2 = OneRow.Split('\t'); if (row2[0] != "") { if (cb_AdminANC.Checked) { FoundRow = Baza.Select(string.Format("BUANC LIKE '%{0}%'", row2[0])).FirstOrDefault(); } else { FoundRow = Baza.Select(string.Format("BUPNC LIKE '%{0}%'", row2[0])).FirstOrDefault(); } int zmienna; if (FoundRow != null) { zmienna = ile; for (int counter = 1; counter <= (13 - ile); counter++) { FoundRow[Jak + "/" + zmienna + "/" + Admin_Year.Text] = row2[counter]; zmienna++; } } else { DataRow NewRow = Baza.NewRow(); NewRow[0] = row2[0]; zmienna = ile; for (int counter = 1; counter <= (13 - ile); counter++) { NewRow[Jak + "/" + zmienna + "/" + Admin_Year.Text] = row2[counter]; zmienna++; } Baza.Rows.Add(NewRow); } } } if (cb_AdminANC.Checked) { Data_Import.Singleton().Save_DataTableToTXT2(ref Baza, "ANC"); } if (cb_AdminPNC.Checked) { Data_Import.Singleton().Save_DataTableToTXT2(ref Baza, "PNC"); } this.Close(); Cursor.Current = Cursors.Default; return; } if (Jak == "AddMonthANC" || Jak == "AddMonthPNC") { NumericUpDown Admin_Year = (NumericUpDown)MainProgram.Self.TabControl.Controls.Find("num_Admin_YearMonth", true).First(); NumericUpDown Admin_Month = (NumericUpDown)MainProgram.Self.TabControl.Controls.Find("num_Admin_QuantityMonth", true).First(); DataTable Quantity = new DataTable(); DataRow FoundRow; string Miesiac = Admin_Month.Value.ToString() + "/" + Admin_Year.Value.ToString(); if (Jak == "AddMonthANC") { Data_Import.Singleton().Load_TxtToDataTable2(ref Quantity, "ANCMonth"); } if (Jak == "AddMonthPNC") { Data_Import.Singleton().Load_TxtToDataTable2(ref Quantity, "PNCMonth"); } if (Quantity.Columns.Contains(Miesiac)) { Quantity.Columns.Remove(Miesiac); } Quantity.Columns.Add(new DataColumn(Miesiac)); foreach (string OneRow in row) { string[] NewValue = OneRow.Split('\t'); if (NewValue[0] != "") { if (Jak == "AddMonthANC") { FoundRow = Quantity.Select(string.Format("ANC LIKE '%{0}%'", NewValue[0])).FirstOrDefault(); } else { FoundRow = Quantity.Select(string.Format("PNC LIKE '%{0}%'", NewValue[0])).FirstOrDefault(); } if (FoundRow != null) { FoundRow[Miesiac] = NewValue[1]; } else { DataRow NewRow = Quantity.NewRow(); NewRow[0] = NewValue[0]; NewRow[Miesiac] = NewValue[1]; Quantity.Rows.Add(NewRow); } } } if (Jak == "AddMonthANC") { Data_Import.Singleton().Save_DataTableToTXT2(ref Quantity, "ANCMonth"); } if (Jak == "AddMonthPNC") { Data_Import.Singleton().Save_DataTableToTXT2(ref Quantity, "PNCMonth"); } this.Close(); Cursor.Current = Cursors.Default; return; } }
public void Update(IDatabase DataDB, List <DbParameter> param, ref string fullqry, ref string _extqry, ref int i) { ParameterizeCtrl_Params args = new ParameterizeCtrl_Params(DataDB, param, i, _extqry); foreach (EbWebForm WebForm in this) { args.SetFormRelated(WebForm.TableName, WebForm.UserObj, WebForm); WebForm.DoRequiredCheck(WebForm == MasterForm); foreach (TableSchema _table in WebForm.FormSchema.Tables.FindAll(e => e.TableType != WebFormTableTypes.Review && !e.DoNotPersist)) { if (!WebForm.FormData.MultipleTables.ContainsKey(_table.TableName)) { continue; } foreach (SingleRow row in WebForm.FormData.MultipleTables[_table.TableName]) { args.ResetColVals(); if (row.RowId > 0) { SingleRow bkup_Row = WebForm.FormDataBackup.MultipleTables[_table.TableName].Find(e => e.RowId == row.RowId); if (bkup_Row == null) { Console.WriteLine($"Row edit request ignored(Row not in backup table). \nTable name: {_table.TableName}, RowId: {row.RowId}, RefId: {WebForm.RefId}"); continue; } string t = string.Empty; if (!row.IsDelete) { foreach (SingleColumn cField in row.Columns) { if (cField.Control != null) { SingleColumn ocF = bkup_Row.Columns.Find(e => e.Name.Equals(cField.Name)); args.UpdateSet(cField, ocF); cField.Control.ParameterizeControl(args, WebForm.CrudContext); } else { args.UpdateSet(cField); WebForm.ParameterizeUnknown(args); } } } else if (WebForm.DataPusherConfig == null && !_table.TableName.Equals(WebForm.TableName)) { List <TableSchema> _tables = WebForm.FormSchema.Tables.FindAll(e => e.IsDynamic && e.TableType == WebFormTableTypes.Grid); foreach (TableSchema _tbl in _tables) { t += $@"UPDATE {_tbl.TableName} SET eb_del = 'T', eb_lastmodified_by = @eb_modified_by, eb_lastmodified_at = {DataDB.EB_CURRENT_TIMESTAMP} WHERE {_table.TableName}_id = @{_table.TableName}_id_{args.i} AND {WebForm.TableName}_id = @{WebForm.TableName}_id AND COALESCE(eb_del, 'F') = 'F'; "; param.Add(DataDB.GetNewParameter(_table.TableName + "_id_" + args.i, EbDbTypes.Int32, row.RowId)); args.i++; } } string _qry = QueryGetter.GetUpdateQuery(WebForm, DataDB, _table.TableName, row.IsDelete); fullqry += string.Format(_qry, args._colvals, row.RowId); fullqry += t; } else { args.ResetColsAndVals(); foreach (SingleColumn cField in row.Columns) { args.InsertSet(cField); if (cField.Control != null) { cField.Control.ParameterizeControl(args, WebForm.CrudContext); } else { WebForm.ParameterizeUnknown(args); } } string _qry = QueryGetter.GetInsertQuery(WebForm, DataDB, _table.TableName, WebForm.TableRowId == 0); fullqry += string.Format(_qry, args._cols, args._vals); } fullqry += WebForm.InsertUpdateLines(_table.TableName, row, args); } } string IdParamName = WebForm.TableName + FormConstants._id + (WebForm.DataPusherConfig != null ? WebForm.CrudContext : string.Empty); param.Add(DataDB.GetNewParameter(IdParamName, EbDbTypes.Int32, WebForm.TableRowId)); if (!param.Exists(e => e.ParameterName == WebForm.TableName + FormConstants._eb_ver_id)) { param.Add(DataDB.GetNewParameter(WebForm.TableName + FormConstants._eb_ver_id, EbDbTypes.Int32, WebForm.RefId.Split(CharConstants.DASH)[4])); param.Add(DataDB.GetNewParameter(WebForm.TableName + FormConstants._refid, EbDbTypes.String, WebForm.RefId)); } } args.CopyBack(ref _extqry, ref i); }
public string GetMyActionInsertUpdateQueryxx(ref int i) { string insUpQ = string.Empty, masterId = $"@{this.webForm.TableName}_id";; bool insMyActRequired = false, entryCriteriaRslt = true; EbReviewStage nextStage = null; if (Convert.ToString(this.Table[0][FormConstants.stage_unique_id]) == FormConstants.__system_stage && Convert.ToString(this.Table[0][FormConstants.action_unique_id]) == FormConstants.__review_reset) { insUpQ += this.GetApprovalLinesInsertQry(ref i); bool hasRoleMatch = false; if (this.ebReview.ResetterRoles != null) { hasRoleMatch = this.webForm.UserObj.RoleIds.Select(x => x).Intersect(this.ebReview.ResetterRoles).Any() || this.webForm.UserObj.RoleIds.Contains((int)SystemRoles.SolutionOwner) || this.webForm.UserObj.RoleIds.Contains((int)SystemRoles.SolutionAdmin); } if (!hasRoleMatch) { throw new FormException("Access denied to reset review control", (int)HttpStatusCode.Unauthorized, $"User.RolesId does not contains any of permited roleIds[ResetterRoles]", "From GetMyActionInsertUpdateQuery"); } SingleRow RowBkUp = this.TableBkUp.Find(e => e.RowId <= 0); if (RowBkUp != null) { insUpQ += this.GetMyActionDeleteQry(ref i, Convert.ToInt32(RowBkUp[FormConstants.eb_my_actions_id])); } if (!string.IsNullOrWhiteSpace(this.ebReview.EntryCriteria?.Code)) { this.globals = GlobalsGenerator.GetCSharpFormGlobals_NEW(this.webForm, this.webForm.FormData, this.webForm.FormDataBackup, this.DataDB, null, false); object retval = this.webForm.ExecuteCSharpScriptNew(this.ebReview.EntryCriteria.Code, this.globals);//status or stage if (retval is bool) { bool.TryParse(Convert.ToString(retval), out entryCriteriaRslt); } else if (retval is FG_Review_Stage fg_stage) { nextStage = this.ebReview.FormStages.Find(e => e.Name == fg_stage.name); } } if (entryCriteriaRslt) { if (nextStage == null) { nextStage = this.ebReview.FormStages[0]; } } else if (this.TableBkUp.Find(e => e.RowId > 0) != null) { insUpQ += this.GetApprovalUpdateQry(null, true, false); insUpQ += this.GetApprovalLinesDeleteQry(); } } else { nextStage = this.ExecuteOneStage(ref insUpQ, ref i, ref insMyActRequired, true); } if (nextStage != null) { string[] _col_val = this.GetApproverEntityValues(ref i, nextStage, out _); string autoId = this.GetAutoId(masterId); string description = this.GetDescription(nextStage, autoId); insUpQ += this.GetMyActionInsertQry(_col_val, nextStage, masterId, description); if (this.DataDB.Vendor == DatabaseVendors.MYSQL) { insUpQ += "SELECT eb_persist_currval('eb_my_actions_id_seq'); "; } this.webForm.MyActNotification.Title = "Review required"; Console.WriteLine("Will try to INSERT eb_my_actions"); insUpQ += this.GetApprovalUpdateQry(null, false, true); } return(insUpQ); }
public int UpdateAuditTrail() { List <AuditTrailInsertData> auditTrails = new List <AuditTrailInsertData>(); foreach (EbWebForm _webForm in this.WebForm.FormCollection) { if (_webForm.TableRowId <= 0) { continue; } if (_webForm.FormDataBackup == null || (_webForm.DataPusherConfig != null && _webForm.FormDataBackup.MultipleTables[_webForm.TableName].Count == 0))// Created { auditTrails.Add(new AuditTrailInsertData { Action = (int)DataModificationAction.Created, Fields = new List <AuditTrailEntry>(), RefId = _webForm.RefId, TableRowId = _webForm.TableRowId }); } else if (_webForm.DataPusherConfig != null && _webForm.FormData.MultipleTables[_webForm.TableName].Count == 0) { auditTrails.Add(new AuditTrailInsertData { Action = (int)DataModificationAction.Deleted, Fields = new List <AuditTrailEntry>(), RefId = _webForm.RefId, TableRowId = _webForm.TableRowId }); } else { List <AuditTrailEntry> trailEntries = new List <AuditTrailEntry>(); List <AuditTrailEntry> entries = null; foreach (TableSchema _table in _webForm.FormSchema.Tables) { List <int> rowIds = new List <int>(); foreach (SingleRow Row in _webForm.FormData.MultipleTables[_table.TableName]) { if (Row.RowId <= 0) { continue; } rowIds.Add(Row.RowId); SingleRow RowBkup = _webForm.FormDataBackup.MultipleTables[_table.TableName].Find(e => e.RowId == Row.RowId); entries = this.GetTrailEntries(_webForm, _table, Row, RowBkup); if (entries.Count > 0) { trailEntries.AddRange(entries); } } foreach (SingleRow RowBkup in _webForm.FormDataBackup.MultipleTables[_table.TableName]) { if (!rowIds.Contains(RowBkup.RowId) && RowBkup.RowId > 0) { entries = this.GetTrailEntries(_webForm, _table, null, RowBkup); if (entries.Count > 0) { trailEntries.AddRange(entries); } } } } if (trailEntries.Count > 0) { auditTrails.Add(new AuditTrailInsertData { Action = (int)DataModificationAction.Updated, Fields = trailEntries, RefId = _webForm.RefId, TableRowId = _webForm.TableRowId }); } else { auditTrails.Add(new AuditTrailInsertData { Action = (int)DataModificationAction.Saved_with_no_changes, Fields = new List <AuditTrailEntry>(), RefId = _webForm.RefId, TableRowId = _webForm.TableRowId }); } } } return(this.UpdateAuditTrail(auditTrails)); }