private void LocalMenu_OnItemClicked(string ActionType)
        {
            var selectedItem = dgEmailSetupGrid.SelectedItem as CompanySMTPClient;

            switch (ActionType)
            {
            case "AddRow":
                AddDockItem(TabControls.EmailSetupPage2, api, Uniconta.ClientTools.Localization.lookup("EmailSetup"), "Add_16x16.png");
                break;

            case "CopyRow":
                if (selectedItem == null)
                {
                    return;
                }
                object[] copyParam = new object[2];
                copyParam[0] = StreamingManager.Clone(selectedItem);
                copyParam[1] = false;
                AddDockItem(TabControls.EmailSetupPage2, copyParam, string.Format("{0}: {1}", string.Format(Uniconta.ClientTools.Localization.lookup("CopyOBJ"), Uniconta.ClientTools.Localization.lookup("EmailSetup")), selectedItem._Name), "Copy_16x16.png");
                break;

            case "EditRow":
                if (selectedItem == null)
                {
                    return;
                }
                object[] editParam = new object[2];
                editParam[0] = selectedItem;
                editParam[1] = true;
                AddDockItem(TabControls.EmailSetupPage2, editParam, string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("EmailSetup"), selectedItem._Name), "Edit_16x16.png");
                break;

            case "ApprovalSetup":
                var smtps = dgEmailSetupGrid.ItemsSource as IList <CompanySMTPClient>;
                var approverEmailDialog = new CWApprovalEmailSetup(api, smtps);
                approverEmailDialog.Show();
                break;

            case "AddNote":
                if (selectedItem != null)
                {
                    AddDockItem(TabControls.UserNotesPage, dgEmailSetupGrid.syncEntity);
                }
                break;

            case "AddDoc":
                if (selectedItem != null)
                {
                    AddDockItem(TabControls.UserDocsPage, dgEmailSetupGrid.syncEntity, string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("Documents"), selectedItem._Name));
                }
                break;

            default:
                gridRibbon_BaseActions(ActionType);
                break;
            }
        }
Exemple #2
0
 void ClearFields(CreditorOrderClient initialOrder)
 {
     Order = StreamingManager.Clone(initialOrder) as CreditorOrderClient;
     Order.PropertyChanged += Editrow_PropertyChanged;
     this.DataContext       = Order;
     dgCreditorOrderLineGrid.UpdateMaster(Order);
     dgCreditorOrderLineGrid.ItemsSource = null;
     dgCreditorOrderLineGrid.AddFirstRow();
     LeAccount.Focus();
 }
        private UnicontaBaseEntity CreateSourceObject(Appointment appointment)
        {
            var source = appointment.GetSourceObject(employeeScheduler.GetCoreStorage()) as EmployeeJournalLineClient;

            if (source == null)
            {
                return(null);
            }
            return(StreamingManager.Clone(source));
        }
Exemple #4
0
 public CreditorGroupPostingPage2(UnicontaBaseEntity sourceData, UnicontaBaseEntity groupMaster, bool isEdit = true) : base(sourceData, isEdit)
 {
     InitializeComponent();
     if (!isEdit)
     {
         editRow = (DCGroupPostingClient)StreamingManager.Clone(sourceData);
     }
     isGroupEnabled = !isEdit;
     InitPage(api, groupMaster);
 }
 /*For Edit*/
 public EmployeePage2(UnicontaBaseEntity sourcedata, bool isEdit = true)
     : base(sourcedata, isEdit)
 {
     InitializeComponent();
     if (!isEdit)
     {
         editrow         = (EmployeeClient)StreamingManager.Clone(sourcedata);
         editrow._Number = null;
     }
     InitPage(api);
 }
 /*For Edit*/
 public CreditorGroupPage2(UnicontaBaseEntity sourcedata, bool isEdit = true)
     : base(sourcedata, isEdit)
 {
     if (!isEdit)
     {
         editrow = (CreditorGroupClient)StreamingManager.Clone(sourcedata);
         IdKey idkey = (IdKey)editrow;
         if (idkey.KeyStr != null)
         {
             idkey.KeyStr = null;
         }
     }
     InitPage(api);
 }
        private async void LoadInv()
        {
            busyIndicator.IsBusy = true;
            var list = await api.LoadCache(typeof(Uniconta.DataModel.InvItem));

            inventoryItemList = new List <InvItemClient>(list.Count >> 4);
            foreach (var rec in (Uniconta.DataModel.InvItem[])list.GetNotNullArray)
            {
                if (rec._ItemType >= 2)
                {
                    inventoryItemList.Add(StreamingManager.Clone(rec) as InvItemClient);
                }
            }

            var invBomLst = await api.Query <InvBOMClient>();

            if (invBomLst != null)
            {
                var cache = new SQLCache(inventoryItemList.ToArray(), true);

                InvItemClient master = null;
                foreach (var invBom in invBomLst)
                {
                    if (invBom._ItemMaster != master?._Item)
                    {
                        master = (InvItemClient)cache.Get(invBom._ItemMaster);
                    }
                    if (master != null)
                    {
                        List <InvBOMClient> bomLst;
                        if (master.BOMs != null)
                        {
                            bomLst = (List <InvBOMClient>)master.BOMs;
                        }
                        else
                        {
                            master.BOMs = bomLst = new List <InvBOMClient>();
                        }
                        bomLst.Add(invBom);
                    }
                }
            }
            if (inventoryItemList.Count > 0)
            {
                dgInvItem.ItemsSource = null;
                dgInvItem.ItemsSource = inventoryItemList;
            }
            dgInvItem.Visibility = Visibility.Visible;
            busyIndicator.IsBusy = false;
        }
Exemple #8
0
        public CWAccountingPeriod(CompanyFinanceYearClient accountYears, CompanyFinancePeriodClient[] accountPeriodClient, CrudAPI api)
        {
            this.DataContext = this;
            InitializeComponent();
#if !SILVERLIGHT
            this.Title = Uniconta.ClientTools.Localization.lookup("AccountingPeriod");
#endif
            API            = api;
            ModifiedRow    = accountYears;
            LoadedRow      = StreamingManager.Clone((UnicontaBaseEntity)ModifiedRow);
            accountPeriods = accountPeriodClient;
            dgAccountPeriod.ItemsSource = accountPeriods;
            this.Loaded += CW_Loaded;
        }
Exemple #9
0
 public DebtorPaymentFormatPage2(UnicontaBaseEntity sourcedata, bool isEdit = true)
     : base(sourcedata, isEdit)
 {
     InitializeComponent();
     if (!isEdit)
     {
         editrow = (DebtorPaymentFormatClient)StreamingManager.Clone(sourcedata);
         IdKey idkey = (IdKey)editrow;
         if (idkey.KeyStr != null)
         {
             idkey.KeyStr = null;
         }
     }
     InitPage(api);
 }
        public ErrorCodes Execute(UnicontaBaseEntity master, UnicontaBaseEntity currentRow, IEnumerable <UnicontaBaseEntity> source, string command, string args)
        {
            var original = StreamingManager.Clone(source);

            foreach (GLDailyJournalLineClient line in source)
            {
                if (line.Text?.Contains("@1") ?? false)
                {
                    // TODO process
                    line.AccountType = "Ledger";
                    line.Account     = "1000";
                }
            }
            return(Crud.Update(original, source).Result);
        }
Exemple #11
0
        void UpdateVoucher(VouchersClient attachedVoucher, CreditorOrderClient editrow)
        {
            if (attachedVoucher == null)
            {
                return;
            }
            var buf = attachedVoucher._Data;

            attachedVoucher._Data = null;
            var org = StreamingManager.Clone(attachedVoucher);

            attachedVoucher._Content         = ContentTypes.PurchaseInvoice;
            attachedVoucher._PurchaseNumber  = editrow._OrderNumber;
            attachedVoucher._CreditorAccount = editrow._InvoiceAccount ?? editrow._DCAccount;
            api.UpdateNoResponse(org, attachedVoucher);
            attachedVoucher._Data = buf;
        }
Exemple #12
0
        private void SelectedItem_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            var rec = sender as GLAccountClosingSheetClient;

            switch (e.PropertyName)
            {
            case "IsReconciled":
                if (rec._Reconciled != this.prevReconciled)
                {
                    var GlobalRec = (GLAccount)LedgerCache.Get(rec.RowId);
                    var old       = (GLAccount)StreamingManager.Clone(GlobalRec);
                    GlobalRec._Reconciled = rec._Reconciled;
                    api.UpdateNoResponse(old, rec);
                }
                break;
            }
        }
Exemple #13
0
 public ProjectGroupPage2(UnicontaBaseEntity sourcedata, bool isEdit)
     : base(sourcedata, isEdit)
 {
     InitializeComponent();
     if (!isEdit)
     {
         editrow       = (ProjectGroupClient)StreamingManager.Clone(sourcedata);
         editrow.Group = string.Empty;
         editrow.Name  = string.Empty;
         IdKey idkey = (IdKey)editrow;
         if (idkey.KeyStr != null)
         {
             idkey.KeyStr = null;
         }
     }
     InitPage(api);
 }
        private void LocalMenu_OnItemClicked(string ActionType)
        {
            var selectedItem = dgEmailSetupGrid.SelectedItem as DebtorEmailSetupClient;

            switch (ActionType)
            {
            case "AddRow":
                AddDockItem(TabControls.DebtorEmailSetupPage2, api, Uniconta.ClientTools.Localization.lookup("EmailSetup"), ";component/Assets/img/Add_16x16.png");
                break;

            case "CopyRow":
                if (selectedItem == null)
                {
                    return;
                }
                object[] copyParam = new object[2];
                copyParam[0] = StreamingManager.Clone(selectedItem);
                copyParam[1] = false;
                AddDockItem(TabControls.DebtorEmailSetupPage2, copyParam, string.Format("{0}: {1}", string.Format(Uniconta.ClientTools.Localization.lookup("CopyOBJ"), Uniconta.ClientTools.Localization.lookup("EmailSetup")), selectedItem.Name),
                            ";component/Assets/img/Copy_16x16.png");
                break;

            case "EditRow":
                if (selectedItem == null)
                {
                    return;
                }
                object[] editParam = new object[2];
                editParam[0] = selectedItem;
                editParam[1] = true;
                AddDockItem(TabControls.DebtorEmailSetupPage2, editParam, string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("EmailSetup"), selectedItem.Name), ";component/Assets/img/Edit_16x16.png");
                break;

            case "Attachments":
                if (selectedItem != null)
                {
                    AddDockItem(TabControls.UserDocsPage, dgEmailSetupGrid.syncEntity, string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("Documents"), selectedItem._Name));
                }
                break;

            default:
                gridRibbon_BaseActions(ActionType);
                break;
            }
        }
 public FAMPage2(UnicontaBaseEntity sourcedata, bool isEdit = true) : base(sourcedata, isEdit)
 {
     InitializeComponent();
     if (!isEdit)
     {
         editrow = (FamClient)StreamingManager.Clone(sourcedata);
         IdKey idkey = (IdKey)editrow;
         if (idkey.KeyStr != null)
         {
             idkey.KeyStr = null;
         }
     }
     if (!string.IsNullOrWhiteSpace(editrow._Parent))
     {
         this.parentName = editrow._Parent;
     }
     InitPage(api);
 }
Exemple #16
0
        public CWCopyUserFields(UnicontaBaseEntity sourcedata, CrudAPI api)
        {
            this.DataContext = this;
            InitializeComponent();
#if SILVERLIGHT
            Utility.SetThemeBehaviorOnChildWindow(this);
#else
            this.Title = Uniconta.ClientTools.Localization.lookup("UserFields");
#endif
            API         = api;
            this.master = StreamingManager.Clone(sourcedata);
            this.masterWithCompanyId = sourcedata;
            masterList = new List <UnicontaBaseEntity>();
            masterList.Add(sourcedata);
            listClient     = new List <CustomTableFieldsClient>();
            this.Loaded   += CWCopyUserFields_Loaded;
            this.Height   += 40;
            rowh.Height    = new GridLength(270);
            copyUserFields = true;
        }
        private void LocalMenu_OnItemClicked(string ActionType)
        {
            var selectedItem = dgDebtorMessageGrid.SelectedItem as DebtorMessagesClient;

            switch (ActionType)
            {
            case "AddRow":
                AddDockItem(TabControls.DebtorMessagesPage2, api, Uniconta.ClientTools.Localization.lookup("Message"), "Add_16x16.png");
                break;

            case "CopyRow":
                if (selectedItem == null)
                {
                    return;
                }
                object[] copyParam = new object[2];
                copyParam[0] = StreamingManager.Clone(selectedItem);
                copyParam[1] = false;
                AddDockItem(TabControls.DebtorMessagesPage2, copyParam, string.Format("{0}: {1}", string.Format(Uniconta.ClientTools.Localization.lookup("CopyOBJ"), Uniconta.ClientTools.Localization.lookup("Message")), selectedItem._Name), "Copy_16x16.png");
                break;

            case "EditRow":
                if (selectedItem == null)
                {
                    return;
                }
                object[] editParam = new object[2];
                editParam[0] = selectedItem;
                editParam[1] = true;
                AddDockItem(TabControls.DebtorMessagesPage2, editParam, string.Format("{0}: {1}", Uniconta.ClientTools.Localization.lookup("Message"), selectedItem._Name), "Edit_16x16.png");
                break;

            default:
                gridRibbon_BaseActions(ActionType);
                break;
            }
        }
Exemple #18
0
        static void Main(string[] args)
        {
            AskCredentials(out username, out password);

            #region Create session and log in
            // Create connection
            var connection = new UnicontaConnection(APITarget.Live);
            // Create session
            var session = new Session(connection);
            // Login user. The guid required here is the partner API key which you will get when you ask for it as a partner.
            var apiKey = new Guid("00000000-0000-0000-0000-000000000000");
            if (apiKey.Equals(Guid.Empty))
            {
                Console.WriteLine("You need to set the API key");
                return;
            }

            var logged = session.LoginAsync(username, password, Uniconta.Common.User.LoginType.API, apiKey).Result;

            if (logged != Uniconta.Common.ErrorCodes.Succes)
            {
                Console.WriteLine("Login failed");
                return;
            }
            #endregion

            #region Selecting a company for the session
            // Select the company for session, otherwise it will be default company in Uniconta
            var companies = session.GetCompanies().Result;
            var company   = session.GetCompany(companies[0].CompanyId).Result; // Getting specific company

            var defaultCompany = session.User._DefaultCompany;                 // returns an ID of the company

            session.OpenCompany(defaultCompany, true);                         // true sets the default company for the session, not as a default company for the user
            #endregion

            #region API examples
            // Set the API you want to use. Query, Crud and other APIs with different functionality
            var api  = new CrudAPI(session, company);
            var qapi = new QueryAPI(session, company);
            #endregion

            #region Create records
            // Insert example
            CrmProspectClient prospect = new CrmProspectClient();

            prospect.Name         = "UC corp.";
            prospect.CompanyRegNo = "12315151";
            prospect.Address1     = "Tree 1, Branch 2";

            // Single record insert
            var error = api.Insert(prospect).Result;

            Thread.Sleep(500);                                          // This is just to make sure that insert is done before I request data
            var tempProspects = api.Query <CrmProspectClient>().Result; // This is without any filters and gets all the entities

            // This is local LINQ query, instead of using for loop or other loops to find correct entity
            var master = tempProspects.Where(pr => pr.Name == "UC corp.").FirstOrDefault();

            var contacts = new List <ContactClient>();

            ContactClient contact = new ContactClient();
            contact.Name  = "Jane Doe";
            contact.Email = "*****@*****.**";
            contact.SetMaster(master);

            contacts.Add(contact);

            contact       = new ContactClient();
            contact.Name  = "John Doe";
            contact.Email = "*****@*****.**";
            contact.SetMaster(master);

            contacts.Add(contact);

            // Bulk insert, warning, dont insert too many records. Try to do it in batches.
            error = api.Insert(contacts).Result;
            #endregion

            #region Read records
            // Plain no filter query, gets all the records on this entity in session company.
            var debtorOrders = api.Query <DebtorOrderClient>().Result;

            // Just to show, what we got
            foreach (var creditor in debtorOrders)
            {
                Console.WriteLine("Order: " + creditor.OrderNumber + " - " + creditor.Account);
            }

            // Querying rows that are all related to master record.
            var orderLines = api.Query <DebtorOrderLineClient>(debtorOrders[0]).Result;

            // Setting up a filter
            DateTime fromDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
            DateTime toDate   = DateTime.Today;
            var      filter   = new List <PropValuePair>
            {
                PropValuePair.GenereteWhereElements("Date", typeof(DateTime), $"{fromDate.ToString("d/M-yyyy", CultureInfo.InvariantCulture)}..{toDate.ToString("d/M-yyyy", CultureInfo.InvariantCulture)}"),
                PropValuePair.GenereteOrderByElement("Account", true) // This is sorting filter.
            };

            var invoices = api.Query <DebtorInvoiceClient>(filter).Result;

            // Creating SQL filter
            filter = new List <PropValuePair>();
            filter.Add(PropValuePair.GenereteWhere("Account <= '1234' and Name like 'Something'"));

            var debtorClients = api.Query <DebtorClient>(filter).Result;

            // Pagination filter
            var page     = 0;
            var pageSize = 10;

            filter = new List <PropValuePair>();
            filter.Add(PropValuePair.GenereteOrderByElement("RowId", false));
            filter.Add(PropValuePair.GenereteSkipN(pageSize * page));
            filter.Add(PropValuePair.GenereteTakeN(pageSize * (page + 1)));

            debtorClients = api.Query <DebtorClient>(filter).Result;

            #endregion

            #region Update records
            // Update example
            var prospects = api.Query <CrmProspect>().Result;
            prospects[0]._Address1 = "Tree 2, Branch 3";
            error = api.Update(prospects[0]).Result;

            // Update example using streamingmanager to make sure only fields you updated will be updated
            prospects = api.Query <CrmProspect>().Result;
            var updProspect      = prospects[0];
            var originalProspect = StreamingManager.Clone(updProspect);

            updProspect._Address1 = "Tree 2, Branch 3";
            error = api.Update(originalProspect, updProspect).Result;

            // And again, you can update in bulk.
            #endregion

            #region Delete records
            // Delete näide
            prospects = api.Query <CrmProspect>().Result;
            error     = api.Delete(prospects[0]).Result;
            #endregion

            #region Additional possibilities

            // MultiCrud enables you to insert, update and delete at the same time
            // api.MultiCrud()

            // NoResponse if no response is required with these operations
            // api.InsertNoResponse();
            // api.UpdateNoResponse();
            // api.DeleteNoResponse();

            // Cache
            SQLCache cache = api.CompanyEntity.GetCache(typeof(InvItemClient));
            if (cache == null)
            {
                cache = api.CompanyEntity.LoadCache(typeof(InvItemClient), api).Result;
            }
            var item = cache.Get("1001");

            // Gets all records from cache
            var invEntities = cache.GetRecords as InvItemClient[];
            // Get specific items
            var specItems = invEntities.Where(i => i.KeyName.Contains("old") && i.Available > 3);
            #endregion

            #region UserDocuments
            // Insert UserDocuments
            var            file       = File.ReadAllBytes(@"PATH TO FILE");
            UserDocsClient newUserDoc = new UserDocsClient
            {
                Created      = DateTime.Now,
                DocumentType = FileextensionsTypes.DOCX,
                Text         = "My file name for UC",
                _Data        = file,
            };
            newUserDoc.SetMaster(prospect);

            ErrorCodes errorCode = api.Insert(newUserDoc).Result;


            // Read UserDocuments
            var prospectDocuments = api.Query <UserDocsClient>(prospect).Result;
            if (prospectDocuments.Length != 0)
            {
                var readResult = api.Read(prospectDocuments[0]).Result;
                var fileBytes  = prospectDocuments[0]._Data;

                if (prospectDocuments[0].DocumentType == FileextensionsTypes.DOCX)
                {
                    File.WriteAllBytes(@"PATH TO FILE", fileBytes);
                }
            }
            #endregion

            /*Other APIs:
             *
             * GeneralLedger:
             * •	ReportAPI
             * •	BankStatementAPI
             * •	DocumentAPI
             * •	FinancialYearAPI
             * •	PeriodTotalAPI
             * •	PostingAPI
             * •	StandardGLAccountAPI
             * DebtorCreditor:
             * •	DebtorOrderAPI
             * •	InvoiceAPI
             * •	ReportAPI
             * •	TransactionAPI
             * Inventory:
             * •	PostingAPI
             * •	ReportAPI
             * System:
             * •	CompanyAPI
             * •	NumberSerieAPI
             * •	CompanyAccessAPI
             * •	UserAPI
             *
             */

            // Always try to close your session when done.
            session.LogOut();
        }
Exemple #19
0
        private async void UnlinkRows()
        {
            var dcorderlineMaster = this.dcorderlineMaster;
            UnicontaBaseEntity orgMaster;

            dgLinkedGrid.SelectedItem   = null;
            dgUnlinkedGrid.SelectedItem = null;
            var dcolSerieBatchList = new List <DCOrderLineSerieBatch>();
            var linkedRows         = dgLinkedGrid.ItemsSource as List <SerialToOrderLineClient>;

            if (linkedRows == null || linkedRows.Count == 0)
            {
                if (dcorderlineMaster._SerieBatchMarked && dcorderlineMaster.RowId != 0)
                {
                    orgMaster = StreamingManager.Clone((UnicontaBaseEntity)dcorderlineMaster);
                    dcorderlineMaster.SerieBatch       = null;
                    dcorderlineMaster.SerieBatchMarked = false;
                    api.UpdateNoResponse(orgMaster, (UnicontaBaseEntity)dcorderlineMaster);
                }
                dcorderlineMaster.SerieBatch       = null;
                dcorderlineMaster.SerieBatchMarked = false;
                return;
            }

            bool AllRemoved = true;

            foreach (var row in linkedRows)
            {
                if (row.Mark)
                {
                    var olSerieBatch = new DCOrderLineSerieBatch();
                    olSerieBatch.SetMaster(dcorderlineMaster as UnicontaBaseEntity);
                    olSerieBatch.SetMaster(row);
                    olSerieBatch._Qty = row._QtyMarked;
                    dcolSerieBatchList.Add(olSerieBatch);
                }
                else
                {
                    AllRemoved = false;
                }
            }

            ErrorCodes err;

            if (dcorderlineMaster._SerieBatch != null && dcorderlineMaster.RowId != 0)
            {
                orgMaster = StreamingManager.Clone((UnicontaBaseEntity)dcorderlineMaster);
                dcorderlineMaster.SerieBatch = null;
                if (AllRemoved)
                {
                    dcorderlineMaster.SerieBatchMarked = false;
                }
                var Updates = new Uniconta.API.System.CrudAPI.UpdatePair()
                {
                    loaded = orgMaster, modified = (UnicontaBaseEntity)dcorderlineMaster
                };
                err = await api.MultiCrud(null, new[] { Updates }, dcolSerieBatchList);
            }
            else
            {
                err = await api.Delete(dcolSerieBatchList);
            }
            if (err != ErrorCodes.Succes)
            {
                UtilDisplay.ShowErrorCode(err);
            }
            else
            {
                InitQuery();
                dcorderlineMaster.SerieBatch = null;
                if (AllRemoved)
                {
                    dcorderlineMaster.SerieBatchMarked = false;
                }
            }
        }
Exemple #20
0
        private async Task LinkRows(bool added)
        {
            dgLinkedGrid.SelectedItem   = null;
            dgUnlinkedGrid.SelectedItem = null;
            List <SerialToOrderLineClient> unlinkedRows;

            if (added)
            {
                unlinkedRows = dgLinkedGrid.ItemsSource as List <SerialToOrderLineClient>;
            }
            else
            {
                unlinkedRows = dgUnlinkedGrid.ItemsSource as List <SerialToOrderLineClient>;
            }
            if (unlinkedRows == null || unlinkedRows.Count == 0)
            {
                return;
            }

            var markedList = unlinkedRows.Where(r => r.Mark).ToList();

            if (!added)
            {
                var linkedRows = dgLinkedGrid.ItemsSource as List <SerialToOrderLineClient>;
                if (markedList.Count == 0)
                {
                    return;
                }
                if (linkedRows.Intersect(markedList).Any())
                {
                    UnicontaMessageBox.Show(Uniconta.ClientTools.Localization.lookup("LinkedRowErrorMsg"), Uniconta.ClientTools.Localization.lookup("Error"));
                    return;
                }
            }
            if (markedList.Count == 0)
            {
                return;
            }

            UnicontaBaseEntity orgMaster = null;
            var dcorderlineMaster        = this.dcorderlineMaster;

            var _UseSerial = this.invItemMaster._UseSerial;
            List <DCOrderLineSerieBatch> olSerieBatchList = new List <DCOrderLineSerieBatch>();

            foreach (var row in markedList)
            {
                var    olSerieBatch = new DCOrderLineSerieBatch();
                double qty;
                if (_UseSerial)
                {
                    qty = dcorderlineMaster._Qty >= 0 ? 1d : -1d;
                }
                else if (row._QtyMarked != 0)
                {
                    qty = row._QtyMarked;
                }
                else
                {
                    qty = dcorderlineMaster._Qty;
                }
                olSerieBatch._Qty = qty;
                olSerieBatch.SetMaster(row);
                olSerieBatch.SetMaster(dcorderlineMaster as UnicontaBaseEntity);
                olSerieBatchList.Add(olSerieBatch);
                if (row._Warehouse != null && (dcorderlineMaster._Warehouse != row._Warehouse || dcorderlineMaster._Location != row._Location))
                {
                    if (orgMaster == null && dcorderlineMaster.RowId != 0)
                    {
                        orgMaster = StreamingManager.Clone((UnicontaBaseEntity)dcorderlineMaster);
                    }
                    dcorderlineMaster.Warehouse = row._Warehouse;
                    dcorderlineMaster.Location  = row._Location;
                    if (markedList.Count == 1)
                    {
                        dcorderlineMaster.SerieBatch = row._Number;
                    }
                    else
                    {
                        dcorderlineMaster.SerieBatch = null;
                    }
                }
                else
                {
                    string nr = dcorderlineMaster._SerieBatch, newNr;
                    if (markedList.Count == 1)
                    {
                        newNr = row._Number;
                    }
                    else
                    {
                        newNr = null;
                    }
                    if (newNr != nr)
                    {
                        if (orgMaster == null && dcorderlineMaster.RowId != 0)
                        {
                            orgMaster = StreamingManager.Clone((UnicontaBaseEntity)dcorderlineMaster);
                        }
                        dcorderlineMaster.SerieBatch = newNr;
                    }
                }
            }
            ErrorCodes err;

            if (orgMaster != null)
            {
                dcorderlineMaster.SerieBatchMarked = true;
                var Updates = new Uniconta.API.System.CrudAPI.UpdatePair()
                {
                    loaded = orgMaster, modified = (UnicontaBaseEntity)dcorderlineMaster
                };
                err = await api.MultiCrud(olSerieBatchList, new[] { Updates }, null);
            }
            else
            {
                err = await api.Insert(olSerieBatchList);
            }

            if (err != ErrorCodes.Succes)
            {
                UtilDisplay.ShowErrorCode(err);
            }
            else
            {
                dcorderlineMaster.SerieBatchMarked = true;
                if (!saveAndExit)
                {
                    InitQuery();
                }
            }
        }
        async void CalcPrices()
        {
            var items  = this.items;
            var item   = Invitem;
            var stdQty = item._PurchaseQty;

            if (stdQty == 0d)
            {
                stdQty = 1d;
            }

            double p0 = 0d, p1 = 0d, p2 = 0d, p3 = 0d;

            var lst = dgPartInvItemsGrid.ItemsSource as IEnumerable <InvBOMClient>;

            foreach (var bom in lst)
            {
                var itm = (InvItem)items.Get(bom._ItemPart);
                if (itm != null)
                {
                    var qty = bom.GetBOMQty(stdQty);

                    p0 += (qty * itm._CostPrice);

                    double val;
                    if (!double.IsNaN(p1))
                    {
                        val = await GetValue(itm._SalesPrice1, itm._Currency1, qty, item._Currency1);

                        if (!double.IsNaN(val))
                        {
                            p1 += val;
                        }
                        else
                        {
                            p1 = double.NaN;
                        }
                    }
                    if (!double.IsNaN(p2))
                    {
                        val = await GetValue(itm._SalesPrice2, itm._Currency2, qty, item._Currency2);

                        if (!double.IsNaN(val))
                        {
                            p2 += val;
                        }
                        else
                        {
                            p2 = double.NaN;
                        }
                    }
                    if (!double.IsNaN(p3))
                    {
                        val = await GetValue(itm._SalesPrice3, itm._Currency3, qty, item._Currency3);

                        if (!double.IsNaN(val))
                        {
                            p3 += val;
                        }
                        else
                        {
                            p3 = double.NaN;
                        }
                    }
                }
            }

            p0 = Math.Round(p0 / stdQty, 2);
            p1 = Math.Round(p1 / stdQty, 2);
            p2 = Math.Round(p2 / stdQty, 2);
            p3 = Math.Round(p3 / stdQty, 2);

            var dailog = new CWCalculateSalesPrice(p0, p1, p2, p3, Invitem);

            dailog.Closed += delegate
            {
                if (dailog.DialogResult == true)
                {
                    var org = StreamingManager.Clone(Invitem);
                    if (dailog.costPrice != 0d)
                    {
                        Invitem.CostPrice = dailog.costPrice;
                    }
                    if (dailog.salesPrice1 != 0d)
                    {
                        Invitem.SalesPrice1 = dailog.salesPrice1;
                    }
                    if (dailog.salesPrice2 != 0d)
                    {
                        Invitem.SalesPrice2 = dailog.salesPrice2;
                    }
                    if (dailog.salesPrice3 != 0d)
                    {
                        Invitem.SalesPrice3 = dailog.salesPrice3;
                    }
                    api.UpdateNoResponse(org, Invitem);
                }
            };
            dailog.Show();
        }