internal override void AddEntity(DataPersistance dp, object NewEntity) { if (!object.ReferenceEquals(dp, this.dp)) { return; } string strPK = BuildPKWhere(NewEntity); string Query = strPK.Length > 0 ? string.Concat(SqlQuery, " AND (", strPK, ")") : SqlQuery; IDataReader rdr = dp.ExecuteReader(Query); try { if (rdr.Read()) // Kalo PK data baru valid, tambahkan { object[] Values = new object[rdr.FieldCount]; rdr.GetValues(Values); ((DataTable)wrdt.Target).Rows.Add(Values); } } finally { rdr.Close(); } }
internal override void EditEntity(DataPersistance dp, object OldEntity, object NewEntity) { if (!object.ReferenceEquals(dp, this.dp)) { return; } string strPK = BuildPKWhere(NewEntity); string Query = strPK.Length > 0 ? string.Concat(SqlQuery, " AND (", strPK, ")") : SqlQuery; DataTable dt = (DataTable)wrdt.Target; IDataReader rdr = dp.ExecuteReader(Query); try { if (rdr.Read()) //Kalo PK Data Baru Valid { object[] Values = new object[rdr.FieldCount]; rdr.GetValues(Values); if (OldEntity == null) //Data baru tidak ada, tambahkan { dt.Rows.Add(Values); } else { // kalo data lama ada, edit strPK = BuildPKWhere(OldEntity); DataRow[] drs = dt.Select(BuildPKWhere(OldEntity)); if (drs.Length > 0) { DataRow dr = drs[0]; for (int i = 0; i < Values.Length; i++) { dr[i] = Values[i]; } } else // Data baru tidak ada, tambahkan { dt.Rows.Add(Values); } } } else // Data Baru tidak valid { // Kalo data lama ada, hapus DataRow[] drs = dt.Select(BuildPKWhere(OldEntity)); if (drs.Length > 0) { dt.Rows.Remove(drs[0]); } } } finally { rdr.Close(); } }
public bool Read() { if (rdr == null) { rdr = Dp.ExecuteReader(SqlSelect, Parameters); BuildSetter(); } if (rdr.Read()) { if (ReadOnNewEntity) { _Entity = new TEntity(); } for (int i = 0; i < Setter.Length; i++) { if (Setter[i] != null) { object obj = rdr.GetValue(i); if (obj == null || obj == DBNull.Value) { obj = GetDefaultValue(rdr.GetFieldType(i)); } if (EnumType[i] == null) { Setter[i](_Entity, obj); } else { Setter[i](_Entity, EnumDef.GetEnumValue( EnumType[i], obj)); } } } return(true); } return(false); }
bool IModuleAccessForm.ShowDialog(ModuleAccess ma, Dictionary <string, List <string> > ListKey, ref bool AllDocumentData) { labelControl2.Text = string.Concat(ma.FolderName, "\\", ma.ModuleName); this.ma = ma; _OnLoad = true; checkEdit5.Checked = ma.GetVariable <bool>( SecurityVarName.DocumentView, false); checkEdit6.Checked = ma.GetVariable <bool>( SecurityVarName.ReportView, false); checkEdit1.Checked = ma.GetVariable <bool>( SecurityVarName.DocumentNew, false); checkEdit2.Checked = ma.GetVariable <bool>( SecurityVarName.DocumentEdit, false); checkEdit3.Checked = ma.GetVariable <bool>( SecurityVarName.DocumentDelete, false); checkEdit7.Checked = ma.GetVariable <bool>( SecurityVarName.DocumentPrint, false); checkEdit8.Checked = ma.GetVariable <bool>( SecurityVarName.DocumentDesignPrint, false); checkEdit12.Checked = ma.GetVariable <bool>( SecurityVarName.ReportPrint, false); checkEdit11.Checked = ma.GetVariable <bool>( SecurityVarName.ReportDesignPrint, false); checkEdit10.Checked = ma.GetVariable <bool>( SecurityVarName.ReportSave, false); checkEdit4.Checked = ma.GetVariable <bool>( SecurityVarName.ReportLayoutSave, false); _OnLoad = false; this.ListKey = ListKey; if (ma.ListDataField.Count == 0) { xtraTabPage2.PageVisible = false; } else { DataPersistance dp = BaseSecurity.CurrentLogin.Dp; checkEdit14.Checked = AllDocumentData; foreach (ModuleDataField mdf in ma.ListDataField) { List <Item> ListItem = new List <Item>(); ListDataField.Add(mdf.DataFieldName, ListItem); comboBoxEdit1.Properties.Items.Add(mdf.DataFieldName); IDataReader rdr = dp.ExecuteReader(mdf.SqlQuery); while (rdr.Read()) { bool Pilih = false; string DataKey = (string)rdr[0]; foreach (string key in ListKey[mdf.DataFieldName]) { if (key == DataKey) { Pilih = true; break; } } ListItem.Add(new Item(Pilih, DataKey)); } rdr.Close(); } comboBoxEdit1.SelectedIndex = 0; } if (ShowDialog(BaseWinFramework.MdiParent) == DialogResult.OK) { AllDocumentData = this.AllDocumentData; return(true); } else { return(false); } }