Exemplo n.º 1
0
        public void Save(Model.ItemGroupModel itemGroupModel)
        {
            int groupCode = Controller.ConnectionController.Instance.ExecuteSqlForObject <int>("GetItemGroupCode", itemGroupModel.GroupName);

            if (groupCode != 0)
            {
                itemGroupModel.GroupCode = groupCode;
                return;
            }

            ItemGroups itemGroup = (ItemGroups)Controller.ConnectionController.Instance.Company.GetBusinessObject(BoObjectTypes.oItemGroups);

            try
            {
                if (itemGroup.GetByKey(itemGroupModel.GroupCode))
                {
                    itemGroup.GroupName = itemGroupModel.GroupName;

                    foreach (KeyValuePair <string, dynamic> userField in itemGroupModel.UserFields)
                    {
                        itemGroup.UserFields.Fields.Item(userField.Key).Value = userField.Value;
                    }

                    Controller.ConnectionController.Instance.VerifyBussinesObjectSuccess();

                    itemGroup.Update();
                }
                else
                {
                    itemGroup.GroupName = itemGroupModel.GroupName;
                    //itemGroup.InventoryAccount = "1.01.01.01.01";
                    //itemGroup.CostAccount = "1.01.01.01.01";
                    //itemGroup.TransfersAccount = "1.01.01.01.01";
                    //itemGroup.VarianceAccount = "1.01.01.01.01";
                    //itemGroup.PriceDifferencesAccount = "1.01.01.01.01";

                    foreach (KeyValuePair <string, dynamic> userField in itemGroupModel.UserFields)
                    {
                        itemGroup.UserFields.Fields.Item(userField.Key).Value = userField.Value;
                    }

                    itemGroup.Add();

                    Controller.ConnectionController.Instance.VerifyBussinesObjectSuccess();

                    itemGroupModel.GroupCode = Controller.ConnectionController.Instance.LastObjectCode;
                }
            }
            finally
            {
                GC.Collect();
                Marshal.ReleaseComObject(itemGroup);
            }
        }
Exemplo n.º 2
0
        public void Save()
        {
            if (_newObject)
            {
                _businessObject.Add();
            }
            else
            {
                _businessObject.Update();
            }

            Controller.ConnectionController.Instance.VerifyBussinesObjectSuccess();

            if (m_ItemClassSet)
            {
                Controller.ConnectionController.Instance.ExecuteStatementDirect(@"UPDATE OITB SET ""ItemClass"" = '{0}' WHERE ""ItmsGrpCod"" = {1}", ((int)ItemClassEnum.itcMaterial).ToString(), _businessObject.Number.ToString());

                m_ItemClassSet = false;
            }

            if (m_MaterialTypeSet)
            {
                Controller.ConnectionController.Instance.ExecuteStatementDirect(@"UPDATE OITB SET ""MatType"" = '{0}' WHERE ""ItmsGrpCod"" = {1}", ((int)m_MaterialType).ToString(), _businessObject.Number.ToString());

                m_MaterialTypeSet = false;
            }

            if (m_MaterialGroupSet)
            {
                Controller.ConnectionController.Instance.ExecuteStatementDirect(@"UPDATE OITB SET ""MatGrp"" = '{0}' WHERE ""ItmsGrpCod"" = {1}", m_MaterialGroup.ToString(), _businessObject.Number.ToString());

                m_MaterialGroupSet = false;
            }

            if (m_NCMCodeSet)
            {
                Controller.ConnectionController.Instance.ExecuteStatementDirect(@"UPDATE OITB SET ""NCMCode"" = '{0}' WHERE ""ItmsGrpCod"" = {1}", m_NCMCodeSet.ToString(), _businessObject.Number.ToString());

                m_NCMCodeSet = false;
            }

            if (m_ProductSourceSet)
            {
                Controller.ConnectionController.Instance.ExecuteStatementDirect(@"UPDATE OITB SET ""ProductSrc"" = '{0}' WHERE ""ItmsGrpCod"" = {1}", m_ProductSource.ToString(), _businessObject.Number.ToString());

                m_ProductSourceSet = false;
            }
        }