Exemplo n.º 1
0
        void Menu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (e.Item.Tag != null && e.Item.Tag.ToString() == "New")
            {
                TableChooserForm form         = new TableChooserForm();
                String           strTableName = form.ShowChooseOne();
                if (form.DialogResult == DialogResult.Cancel)
                {
                    return;
                }
                if (DataStructureProvider.IsExistedTable(strTableName) == false)
                {
                    return;
                }

                TreeConfigData configData = new TreeConfigData();
                configData.Name             = "objNew" + this.Manager.ConfigList.Count;
                configData.DefaultLoad      = true;
                configData.TableName        = strTableName;
                configData.ColumnFieldNames = new Dictionary <string, string>();

                TreeConfigNode obj = (TreeConfigNode)DataConfigTreeCtrl.GetDataRecordByNode(DataConfigTreeCtrl.FocusedNode);
                if (obj == null)
                {
                    new TreeConfigNode(Manager.RootConfig, configData);
                }
                else
                {
                    configData.ParentTableName = obj.InnerData.TableName;
                    configData.ParentField     = DataStructureProvider.GetPrimaryKeyColumn(obj.InnerData.TableName);
                    configData.ChildField      = DataStructureProvider.GetForeignKeyOfTableName(configData.TableName, obj.InnerData.TableName);
                    new TreeConfigNode(obj, configData);
                }

                UpdateDataConfigs();
                RefreshDataConfigTree();
            }

            if (e.Item.Tag != null && e.Item.Tag.ToString() == "Delete")
            {
                TreeConfigNode obj = (TreeConfigNode)DataConfigTreeCtrl.GetDataRecordByNode(DataConfigTreeCtrl.FocusedNode);
                if (obj == null || (TreeConfigData)obj.InnerData == null)
                {
                    return;
                }

                DialogResult result = ABCHelper.ABCMessageBox.Show("Do you want to delete selected Object ? ", "Delete Object", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    obj.ParentNode.ChildrenNodes.Remove(obj.InnerData.Name);
                    obj.ParentNode = null;

                    UpdateDataConfigs();
                    RefreshDataConfigTree();
                }
            }
        }
Exemplo n.º 2
0
        public static void CopyFKFields(BusinessObject sourceObj, String strItemTableName)
        {
            if (sourceObj == null)
            {
                return;
            }

            String strFK = DataStructureProvider.GetForeignKeyOfTableName(strItemTableName, sourceObj.AATableName);

            if (String.IsNullOrWhiteSpace(strFK))
            {
                return;
            }


            String strQuery = String.Format("UPDATE {0} SET ", strItemTableName);

            Dictionary <String, object> lstCols = new Dictionary <string, object>();

            foreach (PropertyInfo pro in BusinessObjectHelper.PropertyList[sourceObj.AATableName].Values)
            {
                if (DataStructureProvider.IsTableColumn(strItemTableName, pro.Name) == false)
                {
                    continue;
                }

                if (DataStructureProvider.IsForeignKey(sourceObj.AATableName, pro.Name))
                {
                    lstCols.Add(pro.Name, ABCHelper.DataConverter.ConvertToGuid(ABCDynamicInvoker.GetValue(sourceObj, pro)));
                }

                if (pro.Name == ABCCommon.ABCConstString.colApprovalStatus ||
                    pro.Name == ABCCommon.ABCConstString.colApprovedDate ||
                    pro.Name == ABCCommon.ABCConstString.colDocumentDate ||
                    pro.Name == ABCCommon.ABCConstString.colLockStatus ||
                    pro.Name == ABCCommon.ABCConstString.colVoucher ||
                    pro.Name == ABCCommon.ABCConstString.colVoucherDate ||
                    pro.Name == ABCCommon.ABCConstString.colJournalStatus ||
                    pro.Name == ABCCommon.ABCConstString.colJournalDate ||
                    pro.Name == ABCCommon.ABCConstString.colUpdateTime ||
                    pro.Name == ABCCommon.ABCConstString.colUpdateUser)
                {
                    lstCols.Add(pro.Name, ABCDynamicInvoker.GetValue(sourceObj, pro));
                }
            }

            int i = -1;

            foreach (String strKey in lstCols.Keys)
            {
                i++;
                if (lstCols[strKey] != null && lstCols[strKey] != DBNull.Value)
                {
                    String strValue = lstCols[strKey].ToString();
                    if (lstCols[strKey] is DateTime)
                    {
                        strValue = ((DateTime)lstCols[strKey]).ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    if (lstCols[strKey] is Nullable <DateTime> )
                    {
                        strValue = ((Nullable <DateTime>)lstCols[strKey]).Value.ToString("yyyy-MM-dd HH:mm:ss");
                    }

                    if (i < lstCols.Count - 1)
                    {
                        strQuery = strQuery + String.Format(" [{0}] = '{1}',", strKey, strValue);
                    }
                    else
                    {
                        strQuery = strQuery + String.Format(" [{0}] = '{1}'", strKey, strValue);
                    }
                }
                else
                {
                    if (i < lstCols.Count - 1)
                    {
                        strQuery = strQuery + String.Format(" [{0}] = NULL,", strKey);
                    }
                    else
                    {
                        strQuery = strQuery + String.Format(" [{0}] =NULL", strKey);
                    }
                }
            }
            strQuery = strQuery + String.Format(" WHERE [{0}] ='{1}' ", strFK, sourceObj.GetID());
            BusinessObjectController.RunQuery(strQuery);
        }