private void OrderForm_Load(object sender, EventArgs e)
 {
     LayoutAndBindingByAccess();
     gridOrder.DataSource = PO.GetOrderForSelection(CurrentContext.UserId, null);
     LoadDecimalFormatings();
     gridLkEditOrderType.Properties.DataSource = POType.GetAllPOTypes();
 }
        private void PODialog_Load(object sender, EventArgs e)
        {
            //lookups
            var poTypes         = BLL.Settings.IsCenter ? POType.GetAllPOTypes() : POType.GetAllPOTypesForHub();
            var defaultPOTypeID = poTypes != null && poTypes.Count > 0 ? poTypes.FirstOrDefault().ID:-1;

            //lookups

            gridLkEditOrderType.Properties.DataSource = poTypes;

            var suppliers = Supplier.GetSuppliersByPOType(defaultPOTypeID);

            lkSupplier.Properties.DataSource = suppliers.DefaultView;
            lkSupplier.EditValue             = suppliers.Rows.Count > 0? Convert.ToInt32(suppliers.Rows[0]["ID"]):-1;

            if (!BLL.Settings.IsCenter)
            {
                lkTermOfPayement.Enabled         =
                    txtFreight.Enabled           =
                        txtTotalValue.Enabled    =
                            txtInsurance.Enabled = txtInsuredSum.Enabled = txtNBEServiceCharge.Enabled = false;
                gridLkEditOrderType.EditValue    = POType.MANUAL_DELIVERYNOTE;
            }

            lkCurrencyLCID.Properties.DataSource = Helpers.FormattingHelpers.GetCurrencyList();
            var etb = Convert.ToInt32(Helpers.FormattingHelpers.GetCurrencyList().ToTable().Select("Symbol = 'ETB'")[0]["ID"]);

            lkCurrencyLCID.EditValue = etb; //ETB is the default value
            grdLkEditAccounts.SetupActivityEditor().SetDefaultActivity();
            lkTermOfPayement.Properties.DataSource = TermOfPayment.List;
            LoadDecimalFormatings();
            txtExchangeRate.EditValue = 1;
            if (PoID != 0)
            {
                LoadPurchaseOrderForEdit();
            }
        }
        private void gridOrderView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (e != null && e.PrevFocusedRowHandle < -1)
            {
                return;
            }

            if (gridOrderView.GetFocusedDataRow() != null)
            {
                var dr = gridOrderView.GetFocusedDataRow();

                int    OrderID = Convert.ToInt32(dr["ID"]);
                string sharps  = Helpers.FormattingHelpers.GetNumberFormatting();
                Order = new PO(OrderID);
                RefreshInvoice();
                RefreshPoDetail();
                // Layout  ... Show the damn correct layout

                // Hide the empty layout
                LayoutEmptyDetails.Visibility        = LayoutVisibility.Never;
                LayoutSelectedOrderDetail.Visibility = LayoutVisibility.Always;

                int Currency = 0x0409;
                if (!Order.IsColumnNull("LCID"))
                {
                    Currency = Order.LCID;
                }

                if (!string.IsNullOrEmpty(Order.s_PurchaseType))
                {
                    PurchaseTypes = POType.GetAllPOTypes().Find(t => t.ID == Order.PurchaseType);
                }
                string  space = "";
                DataRow dar   = gridInvoiceView.GetFocusedDataRow();
                HeaderGroup.Text = "PO No: " + dr["OrderNumber"].ToString();
                if (dar != null)
                {
                    HeaderGroup.Text = HeaderGroup.Text + space.PadRight(160) + "Invoice No: " + gridInvoiceView.GetFocusedDataRow()["STVOrInvoiceNo"];
                }

                // lblOrderType.Text = PurchaseTypes != null ?  string.Format("{0} : {1}" ,PurchaseTypes.Group , PurchaseTypes.Name) : "";
                lblPONumber.Text   = Order.PONumber;
                lblTotalValue.Text = Order.TotalValue.ToString(Helpers.FormattingHelpers.GetCurrencyFormatByLCID(Currency));
                lblInsurance.Text  = Order.Insurance.ToString(Helpers.FormattingHelpers.GetBirrFormatting());
                lblNBE.Text        = Order.NBE.ToString(Helpers.FormattingHelpers.GetBirrFormatting());
                lblSupplier.Text   = Order.Supplier.CompanyName;
                lblShipper.Text    = String.IsNullOrEmpty(Order.ShippingSite) ? "-" : Order.ShippingSite;
                lblLetterNo.Text   = String.IsNullOrEmpty(Order.LetterNo) ? "-" : Order.LetterNo;
                lblPOType.Text     = dr["Name"].ToString();

                var PaymentType = new PaymentType();
                PaymentType.LoadByPrimaryKey(Order.PaymentTypeID);
                lblPaymentType.Text = String.IsNullOrEmpty(PaymentType.Name) ? "-" : PaymentType.Name;

                var User = new User();
                User.LoadByPrimaryKey(Order.SavedbyUserID);
                lblPOBy.Text = String.IsNullOrEmpty(User.FullName) ? "-" : User.FullName;

                if (!Order.IsColumnNull("ModeID"))
                {
                    var Mode = new Mode();
                    Mode.LoadByPrimaryKey(Order.ModeID);
                    lblMode.Text = Mode.TypeName;
                }
                else
                {
                    lblMode.Text = "-";
                }



                if (!Order.IsColumnNull("PurchaseOrderStatusID"))
                {
                    var poStatus = new PurchaseOrderStatus();
                    poStatus.LoadByPrimaryKey(Order.PurchaseOrderStatusID);
                    lblPOStatus.Text = poStatus.Name;
                }


                chkboxIsElectronic.Checked = Order.IsElectronic;
                lblOrderDate.Text          = Order.PODate.ToShortDateString();
                lblSyncDate.Text           = Order.ModifiedDate == DateTime.MinValue ? "NA" :  Order.ModifiedDate.ToString(CultureInfo.InvariantCulture);

                if (!Order.IsColumnNull("StoreID"))
                {
                    Activity act = new Activity();
                    act.LoadByPrimaryKey(Order.StoreID);
                    lblAccount.Text    = act.AccountName;
                    lblSubAccount.Text = act.SubAccountName;
                    lblActivity.Text   = act.Name;
                }
                else
                {
                    lblAccount.Text = lblSubAccount.Text = lblActivity.Text = "-";
                }

                lblRefNo.Text          = String.IsNullOrEmpty(Order.RefNo) ? "-" : Order.RefNo;
                lblRemainingValue.Text = Order.Remaining.ToString(Helpers.FormattingHelpers.GetCurrencyFormatByLCID(Currency));
                if (BLL.Settings.UseNewUserManagement && this.HasPermission("Add-Invoice"))
                {
                    btnAddInvoice.Enabled = true;
                }
                else if (BLL.Settings.UseNewUserManagement)
                {
                    btnAddInvoice.Enabled = false;
                }

                btnAddInvoice.Enabled = btnEditOrder.Enabled = btnAddOrderDetail.Enabled = !Order.IsElectronic;

                if (Order.IsElectronic)
                {
                    grdPoDetail.Enabled = false;
                    gridInvoice.Enabled = false;
                }
                else
                {
                    grdPoDetail.Enabled = true;
                    gridInvoice.Enabled = true;
                }

                //purchse order details
                grdPoDetail.DataSource = Order.PurchaseOrderDetail.DefaultView;
            }
            else
            {
                // Hide the empty layout
                LayoutEmptyDetails.Visibility        = LayoutVisibility.Always;
                LayoutSelectedOrderDetail.Visibility = LayoutVisibility.Never;
            }
        }