Example #1
0
        //Save order
        private void metroTileOrdSav_Click(object sender, EventArgs e)
        {
            Order aOrder = createOrd();

            if (aOrder == null)
            {
                return;
            }
            //If is an edition, edit current order
            if (isEdit)
            {
                int ordIndex = HiTechForm.ordList.FindIndex(t => t.OrdId.Equals(currentOrder.OrdId));
                if (aOrder.OrdCost <= aOrder.OrdClient.ClientCredit)
                {
                    HiTechForm.ordList[ordIndex] = aOrder;
                    OperatorDA.SaveList <Order>(HiTechForm.ordList, filePaths.orderPath);
                    //Update client's credit
                    int clIndex = HiTechForm.clientList.FindIndex(t => t.ClientId.Equals(selClient.ClientId));
                    if (HiTechForm.clientList.Find(t => t.ClientId.Equals(selClient.ClientId)) != null)
                    {
                        HiTechForm.clientList[clIndex].ClientCredit = HiTechForm.clientList[clIndex].ClientCredit + currentOrder.OrdCost - aOrder.OrdCost;
                        OperatorDA.SaveList <Client>(HiTechForm.clientList, filePaths.clientPath);
                    }
                    this.Close();
                }
            }
            //If is a new order, save
            else
            {
                aOrder.OrdId = OperatorDA.uniqueID(HiTechForm.ordList, metroComboBoxOrdCl.Text, metroDateTimeOrd.Text);
                if (aOrder.OrdCost <= aOrder.OrdClient.ClientCredit)
                {
                    HiTechForm.ordList.Add(aOrder);
                    OperatorDA.SaveList <Order>(HiTechForm.ordList, filePaths.orderPath);
                    //Update client's credit
                    Client updateCl = HiTechForm.clientList.Find(t => t.ClientName.Equals(metroComboBoxOrdCl.Text));
                    int    clIndex  = HiTechForm.clientList.FindIndex(t => t.ClientId.Equals(updateCl.ClientId));
                    if (HiTechForm.clientList.Find(t => t.ClientId.Equals(updateCl.ClientId)) != null)
                    {
                        HiTechForm.clientList[clIndex].ClientCredit = updateCl.ClientCredit - aOrder.OrdCost;
                        OperatorDA.SaveList <Client>(HiTechForm.clientList, filePaths.clientPath);
                    }

                    this.Close();
                }
            }
        }
Example #2
0
        //Create object order item
        private OrdItem createOrdItem()
        {
            MetroTextBox[]  textBoxes  = { metroTextBoxOrdQt };
            MetroComboBox[] comboBoxes = { metroComboBoxOrdProd };
            MetroTextBox[]  textboxInt = { metroTextBoxOrdQt };
            if (!(Validator.isNotnull(textBoxes) && Validator.isNotnull(comboBoxes) && Validator.isNumberInt(textboxInt)))
            {
                return(null);
            }
            OrdItem aitem = new OrdItem();

            aitem.OrdItId = OperatorDA.uniqueID(orderItemsList, metroComboBoxOrdProd.Text, metroComboBoxOrdProd.Text);
            if (metroComboBoxOrdProdType.SelectedIndex.Equals(0))
            {
                aitem.OrdProd = HiTechForm.bookList.Find(t => t.Title.Equals(metroComboBoxOrdProd.Text));
            }
            if (metroComboBoxOrdProdType.SelectedIndex.Equals(1))
            {
                aitem.OrdProd = HiTechForm.softwareList.Find(t => t.Title.Equals(metroComboBoxOrdProd.Text));
            }
            aitem.OrdItQt = Convert.ToInt32(metroTextBoxOrdQt.Text);
            return(aitem);
        }