Beispiel #1
0
        public FreightForm(freight f)
        {
            InitializeComponent();
            ControlsUtil.SetBackColor(this.Controls);
            if (f == null)
                IsNew = true;
            if (IsNew)
                f = new freight() { number_note = null, number_cte = null };
            else
            {
                ListFueleds = fueled.Fetch("WHERE freight_id=@0", f.id);
                ListOutputs = output.Fetch("WHERE freight_id=@0", f.id);
                ListDeposits = deposits.Fetch("WHERE freight_id=@0", f.id);
                loadValuesFueledsAndOutputs(f);
                tfNumberNote.Properties.ReadOnly = true;
                cbTruck.Properties.ReadOnly = true;
                btnStay.Visible = true;
            }
            loadData();
            bdgFreight.DataSource = f;
            DateTime now = freight.Now();
            tfStart.Properties.MaxValue = now;
            tfEnd.Properties.MaxValue = now;

            if (!IsNew)
            {
                //cbDriver.EditValue = f.driver_id;
                //tfPercentComission.EditValue = f.taxe_comission;
            }
        }
Beispiel #2
0
        public ViewDepositsForm(List <deposits> _ld, freight _fre)
        {
            List <deposits> ld = _ld;// new List<deposits>();

            //ld.Clear();
            //foreach (deposits d in _ld)
            // ld.Add(d);

            InitializeComponent();
            ControlsUtil.SetBackColor(this.Controls);
            fre = _fre;

            if (ld == null)
            {
                ld = new List <deposits>();
                ld.Clear();
            }
            else
            {
                for (int i = 0; i < ld.Count; i++)
                {
                    bank_account ba = bank_account.SingleOrDefault(ld[i].account_id);
                    banks        b  = banks.SingleOrDefault(ba.bank_id);
                    ld[i].account       = String.Format("{0}/{1} - {2}/{3}", ba.agency, ba.account, b.code, b.name);
                    ld[i].customer_name = customer.SingleOrDefault(ld[i].customer_id).corporate_name;
                    ld[i].type_name     = ld[i].type == 0 ? "Dinheiro" : "Cheque";
                    ld[i].truck_board   = truck.SingleOrDefault(ld[i].truck_id).board;
                }
            }
            bdgDeposits.DataSource = ld;
            if (bdgDeposits.Count == 0)
            {
                btnAdd_Click(this, null);
            }
        }
Beispiel #3
0
        public ViewDepositsForm(List<deposits> _ld, freight _fre)
        {
            List<deposits> ld = new List<deposits>();
            ld.Clear();
            foreach (deposits d in _ld)
                ld.Add(d);

            InitializeComponent();
            ControlsUtil.SetBackColor(this.Controls);
            fre = _fre;

            if (ld == null)
            {
                ld = new List<deposits>();
                ld.Clear();
            }
            else
            {
                for (int i = 0; i < ld.Count; i++)
                {
                    bank_account ba = bank_account.SingleOrDefault(ld[i].account_id);
                    ld[i].account = String.Format("{0} - {1}", ba.agency, ba.account);
                    ld[i].customer_name = customer.SingleOrDefault(ld[i].customer_id).corporate_name;
                    ld[i].type_name = ld[i].type == 0 ? "Dinheiro" : "Cheque";
                    ld[i].truck_board = truck.SingleOrDefault(ld[i].truck_id).board;
                }
            }
            bdgDeposits.DataSource = ld;
        }
Beispiel #4
0
        private void loadValuesFueledsAndOutputs(freight f)
        {
            ValueFueled  = 0;
            ValueOutputs = 0;
            foreach (fueled fu in ListFueleds)
            {
                ValueFueled += fu.total;
            }
            foreach (output o in ListOutputs)
            {
                ValueOutputs += o.value;
            }

            tfFueled.EditValue  = ValueFueled;
            tfOutputs.EditValue = ValueOutputs;
            stay st = stay.SingleOrDefault("WHERE freight_id=@0", f.id);

            if (st != null)
            {
                tfStay.EditValue           = st.total;
                tfExtraComission.EditValue = st.total_comission;
                if (((freight)bdgFreight.Current) != null)
                {
                    ((freight)bdgFreight.Current).extra_comission = st.total_comission;
                }
                tfExtraComission.Properties.ReadOnly = true;
            }
        }
Beispiel #5
0
 internal static bool NumberCteFreightUnique(freight fre)
 {
     try
     {
         int count;
         var s = TruckSystemRepo.GetInstance().ExecuteScalar <string>
                     ("SELECT COUNT(id) FROM freights WHERE number_cte=@0", fre.number_cte);
         if (s.Equals(DBNull.Value) || String.IsNullOrEmpty(s))
         {
             count = 0;
         }
         else
         {
             count = Convert.ToInt32(s);
         }
         if (count == 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message, ex.InnerException);
     }
 }
Beispiel #6
0
 public NewDepositForm(deposits _d, freight fre)
 {
     InitializeComponent();
     ControlsUtil.SetBackColor(this.Controls);
     loadModels();
     if(_d == null)
         _d = new deposits() { type = -1, freight_id = fre.id, truck_id = fre.truck_id, date = null };
     bdgDeposit.DataSource = _d;
 }
Beispiel #7
0
 public FueledForm(freight f)
 {
     InitializeComponent();
     ControlsUtil.SetBackColor(this.Controls);
     bdgFueled.DataSource = new fueled() { freight_id = 0, truck_id = f.truck_id, driver_id = f.driver_id };
     bdgCustomers.DataSource = customer.Fetch("");
     tfDate.Properties.MaxValue = Convert.ToDateTime(f.end);
     tfDate.Properties.MinValue = Convert.ToDateTime(f.start);
     cbGasStation.Focus();
 }
 public OutputsFreightForm(freight f)
 {
     InitializeComponent();
     ControlsUtil.SetBackColor(this.Controls);
     bdgOutput.DataSource = new output() { freight_id = 0, truck_id = f.truck_id };
     bdgCustomers.DataSource = customer.Fetch("");
     tfDate.Properties.MaxValue = Convert.ToDateTime(f.end);
     tfDate.Properties.MinValue = Convert.ToDateTime(f.start);
     cbCustomer.Focus();
 }
Beispiel #9
0
 public FueledForm(freight f)
 {
     InitializeComponent();
     ControlsUtil.SetBackColor(this.Controls);
     bdgFueled.DataSource = new fueled()
     {
         freight_id = 0, truck_id = f.truck_id, driver_id = f.driver_id
     };
     bdgCustomers.DataSource    = customer.Fetch("");
     tfDate.Properties.MaxValue = Convert.ToDateTime(f.end);
     tfDate.Properties.MinValue = Convert.ToDateTime(f.start);
     cbGasStation.Focus();
 }
 public OutputsFreightForm(freight f)
 {
     InitializeComponent();
     ControlsUtil.SetBackColor(this.Controls);
     bdgOutput.DataSource = new output()
     {
         freight_id = 0, truck_id = f.truck_id, others_outputs = false
     };
     bdgCustomers.DataSource    = customer.Fetch("");
     tfDate.Properties.MaxValue = Convert.ToDateTime(f.end);
     tfDate.Properties.MinValue = Convert.ToDateTime(f.start);
     cbCustomer.Focus();
 }
Beispiel #11
0
        public StayForm(freight _f)
        {
            InitializeComponent();
            ControlsUtil.SetBackColor(this.Controls);
            f = _f;
            stay s = stay.SingleOrDefault("WHERE freight_id=@0", f.id);
            if (s == null)
                s = new stay();
            bdgStay.DataSource = s;

            tfTruck.EditValue = truck.SingleOrDefault(f.truck_id).board;
            tfNameDriver.EditValue = driver.SingleOrDefault(f.driver_id).full_name;
            tfFreight.EditValue = f.id;
        }
Beispiel #12
0
 public NewDepositForm(deposits _d, freight fre)
 {
     InitializeComponent();
     ControlsUtil.SetBackColor(this.Controls);
     loadModels();
     if (_d == null)
     {
         _d = new deposits()
         {
             type = -1, freight_id = fre.id, truck_id = fre.truck_id, date = null
         }
     }
     ;
     bdgDeposit.DataSource = _d;
 }
Beispiel #13
0
        public StayForm(freight _f)
        {
            InitializeComponent();
            ControlsUtil.SetBackColor(this.Controls);
            f = _f;
            stay s = stay.SingleOrDefault("WHERE freight_id=@0", f.id);

            if (s == null)
            {
                s = new stay();
            }
            bdgStay.DataSource = s;

            tfTruck.EditValue      = truck.SingleOrDefault(f.truck_id).board;
            tfNameDriver.EditValue = driver.SingleOrDefault(f.driver_id).full_name;
            tfFreight.EditValue    = f.id;
        }
Beispiel #14
0
 public ViewOutputsForm(List<output> lo, freight fr)
 {
     InitializeComponent();
     ControlsUtil.SetBackColor(this.Controls);
     fre = fr;
     if (lo == null)
     {
         bdgOutputs.DataSource = new List<output>();
         bdgOutputs.Clear();
     }
     else
     {
         for (int i = 0; i < lo.Count; i++)
             lo[i].customer_name = customer.SingleOrDefault(lo[i].customer_id).corporate_name;
         bdgOutputs.DataSource = lo;
     }
     if(bdgOutputs.Count == 0)
         btnAdd_Click(this, null);
 }
Beispiel #15
0
 public ViewFueledsForm(List<fueled> lf, freight fr)
 {
     InitializeComponent();
     ControlsUtil.SetBackColor(this.Controls);
     fre = fr;
     if (lf == null)
     {
         bdgFueleds.DataSource = new List<fueled>();
         bdgFueleds.Clear();
         btnAdd_Click(this, null);
     }
     else
     {
         for (int i = 0; i < lf.Count; i++)
             lf[i].gas_station_name = customer.SingleOrDefault(lf[i].gas_station_id).corporate_name;
             bdgFueleds.DataSource = lf;
     }
     if (bdgFueleds.Count == 0)
         btnAdd_Click(this, null);
 }
Beispiel #16
0
        public FreightForm(freight f)
        {
            InitializeComponent();
            ControlsUtil.SetBackColor(this.Controls);
            if (f == null)
            {
                IsNew = true;
            }
            if (IsNew)
            {
                f = new freight()
                {
                    number_note = null, number_cte = null
                }
            }
            ;
            else
            {
                ListFueleds  = fueled.Fetch("WHERE freight_id=@0", f.id);
                ListOutputs  = output.Fetch("WHERE freight_id=@0", f.id);
                ListDeposits = deposits.Fetch("WHERE freight_id=@0", f.id);
                loadValuesFueledsAndOutputs(f);
                tfNumberNote.Properties.ReadOnly = true;
                cbTruck.Properties.ReadOnly      = true;
                btnStay.Visible = true;
            }
            loadData();
            bdgFreight.DataSource = f;
            DateTime now = freight.Now();

            tfStart.Properties.MaxValue = now;
            tfEnd.Properties.MaxValue   = now;

            if (!IsNew)
            {
                //cbDriver.EditValue = f.driver_id;
                //tfPercentComission.EditValue = f.taxe_comission;
            }
        }
Beispiel #17
0
 public ViewOutputsForm(List <output> lo, freight fr)
 {
     InitializeComponent();
     ControlsUtil.SetBackColor(this.Controls);
     fre = fr;
     if (lo == null)
     {
         bdgOutputs.DataSource = new List <output>();
         bdgOutputs.Clear();
     }
     else
     {
         for (int i = 0; i < lo.Count; i++)
         {
             lo[i].customer_name = customer.SingleOrDefault(lo[i].customer_id).corporate_name;
         }
         bdgOutputs.DataSource = lo;
     }
     if (bdgOutputs.Count == 0)
     {
         btnAdd_Click(this, null);
     }
 }
Beispiel #18
0
        public ViewFueledsForm(List <fueled> lf, freight fr)
        {
            InitializeComponent();
            ControlsUtil.SetBackColor(this.Controls);
            fre = fr;
            if (lf == null)
            {
                bdgFueleds.DataSource = new List <fueled>();
                bdgFueleds.Clear();
            }
            else
            {
                for (int i = 0; i < lf.Count; i++)
                {
                    lf[i].gas_station_name = customer.SingleOrDefault(lf[i].gas_station_id).corporate_name;
                }
                bdgFueleds.DataSource = lf;
            }

            if (bdgFueleds.Count == 0)
            {
                btnAdd_Click(this, null);
            }
        }
        void searchFreights()
        {
            try
            {
                SplashScreenManager.ShowForm(desk, typeof(PleaseWaitForm), false, false, false);
                List <freight> listF = new List <freight>();
                string         st    = "";

                if (Convert.ToInt64(tfId.EditValue) > 0 || Convert.ToInt64(cbTruck.EditValue) > 0 ||
                    Convert.ToInt32(tfNumberNote.EditValue) > 0 || (tfStart.EditValue != null && tfEnd.EditValue != null))
                {
                    st += "WHERE";
                }
                if (Convert.ToInt64(tfId.EditValue) > 0)
                {
                    st += String.Format(" id={0}", tfId.EditValue);
                }

                if (Convert.ToInt64(cbTruck.EditValue) > 0)
                {
                    if (Convert.ToInt64(tfId.EditValue) > 0)
                    {
                        st += " AND";
                    }
                    st += String.Format(" truck_id={0}", cbTruck.EditValue);
                }

                if (Convert.ToInt64(tfNumberNote.EditValue) > 0)
                {
                    if (Convert.ToInt64(tfId.EditValue) > 0 || Convert.ToInt64(cbTruck.EditValue) > 0)
                    {
                        st += " AND";
                    }
                    st += String.Format(" number_note={0}", tfNumberNote.EditValue);
                }

                if (tfStart.EditValue != null && tfEnd.EditValue != null)
                {
                    if (Convert.ToInt64(tfId.EditValue) > 0 || Convert.ToInt64(cbTruck.EditValue) > 0 ||
                        Convert.ToInt32(tfNumberNote.EditValue) > 0)
                    {
                        st += " AND";
                    }
                    st += String.Format(" start BETWEEN to_date('{0:yyyy-MM-dd}', 'yyyy-MM-dd') AND to_date('{1:yyyy-MM-dd}', 'yyyy-MM-dd')",
                                        tfStart.DateTime, tfEnd.DateTime);
                }
                st   += " ORDER BY start, id";
                listF = freight.Fetch(st);

                for (int i = 0; i < listF.Count; i++)
                {
                    freight  f    = listF[i];
                    customer cs   = customer.SingleOrDefault(f.company_source);
                    city     cacs = city.SingleOrDefault(address.SingleOrDefault(cs.address_id).city_id);
                    f.company_source_name = String.Format("{0}/{1}", cacs.name, cs.corporate_name);
                    customer cd   = customer.SingleOrDefault(f.company_destination);
                    city     cacd = city.SingleOrDefault(address.SingleOrDefault(cd.address_id).city_id);
                    f.company_destination_name = String.Format("{0}/{1}", cacd.name, cd.corporate_name);
                    f.truck_board = truck.SingleOrDefault(f.truck_id).board;
                    f.driver_name = driver.SingleOrDefault(f.driver_id).full_name;

                    decimal vgross  = ((f.weight * f.value_ton) + totalStays(f.id));
                    decimal fueleds = totalFueleds(f.id);
                    decimal outputs = totalOutputs(f.id);
                    f.value_gross = vgross;
                    f.total       = (vgross - f.value_comission) - (fueleds + outputs);
                    listF[i]      = f;
                }
                bdgFreights.DataSource = listF;
                SplashScreenManager.CloseForm(false);
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(String.Format("Ocorreu um erro:\n\n{0}\n{1}", ex.Message, ex.InnerException));
            }
        }
Beispiel #20
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!validator.Validate())
            {
                return;
            }
            freight fre = (freight)bdgFreight.Current;

            if (IsNew)
            {
                if (!Validations.Unique.NumberNoteFreightUnique(fre))
                {
                    freight nf = freight.SingleOrDefault("SELECT id FROM freights WHERE number_note=@0", fre.number_note);
                    if (nf != null)
                    {
                        XtraMessageBox.Show("Numero da nota já existe, verifique!\nFrete ID: " + nf.id);
                    }
                    return;
                }

                if (!Validations.Unique.NumberCteFreightUnique(fre))
                {
                    freight nf = freight.SingleOrDefault("SELECT id FROM freights WHERE number_cte=@0", fre.number_cte);
                    if (nf != null)
                    {
                        XtraMessageBox.Show("Numero do CT-e já existe, verifique!\nFrete ID: " + nf.id);
                    }
                    return;
                }

                string TextMessage = String.Format("Confirma salvar os dados deste frete com as informações abaixo?"
                                                   + "\n  - {0} abastecidas\n  - {1} despesas",
                                                   ListFueleds != null ? ListFueleds.Count : 0, ListOutputs != null ? ListOutputs.Count : 0);
                if (XtraMessageBox.Show(TextMessage, "Cadore Tecnologia", MessageBoxButtons.OKCancel,
                                        MessageBoxIcon.Question) == DialogResult.Cancel)
                {
                    return;
                }
            }
            try
            {
                using (var scope = freight.repo.GetTransaction())
                {
                    if (IsNew)
                    {
                        fre.registred_at = freight.Now();
                        fre.registred_by = Singleton.getUser().id;
                    }

                    /*trailer tr1 = trailer.SingleOrDefault("WHERE truck_id=@0 AND index=@1", fre.truck_id, 1);
                     * trailer tr2 = trailer.SingleOrDefault("WHERE truck_id=@0 AND index=@1", fre.truck_id, 2);
                     * trailer tr3 = trailer.SingleOrDefault("WHERE truck_id=@0 AND index=@1", fre.truck_id, 3);
                     *
                     * fre.trailers = String.Format("{0},{1},{2}",
                     *  (tr1 != null ? tr1.id.ToString() : "0"),
                     *  (tr2 != null ? tr2.id.ToString() : "0"),
                     *  (tr3 != null ? tr3.id.ToString() : "0"));
                     */
                    fre.Save();

                    foreach (trailer t in Trailers)
                    {
                        set_freight_trailers sft = new set_freight_trailers()
                        {
                            freight_id    = fre.id,
                            trailer_id    = t.id,
                            index_trailer = t.index
                        };
                        sft.Save();
                    }

                    if (ListFueleds != null)
                    {
                        foreach (fueled fue in ListFueleds)
                        {
                            fue.registred_at = fueled.Now();
                            fue.registred_by = Singleton.getUser().id;
                            fue.freight_id   = fre.id;
                            fue.driver_id    = fre.driver_id;
                            fue.truck_id     = fre.truck_id;
                            if (fue.IsNew())
                            {
                                fue.Save();
                            }
                        }
                    }

                    if (ListOutputs != null)
                    {
                        foreach (output o in ListOutputs)
                        {
                            o.registred_at = output.Now();
                            o.registred_by = Singleton.getUser().id;
                            o.freight_id   = fre.id;
                            o.truck_id     = fre.truck_id;
                            if (o.IsNew())
                            {
                                o.Save();
                            }
                        }
                    }

                    if (ListDeposits != null)
                    {
                        Console.WriteLine("Deposit not null");
                        foreach (deposits d in ListDeposits)
                        {
                            Console.WriteLine("single deposit");
                            d.freight_id = fre.id;
                            d.truck_id   = fre.truck_id;
                            if (d.IsNew())
                            {
                                Console.WriteLine("deposit saved");
                                d.Save();
                            }
                            else
                            {
                                Console.WriteLine("deposit updated");
                                d.Update();
                            }
                        }
                    }
                    scope.Complete();
                }
                tfId.EditValue = fre.id;
                if (MessageToSave("Frete"))
                {
                    desk.AddTabAndCloseCurrent(new FreightForm(null), "Novo Frete", false);
                }
            }
            catch (Exception ex)
            {
                freight.repo.AbortTransaction();
                XtraMessageBox.Show(String.Format("Ocorreu um erro:\n\n{0}\n{1}", ex.Message, ex.InnerException));
            }
        }
Beispiel #21
0
        private void loadValuesFueledsAndOutputs(freight f)
        {
            ValueFueled = 0;
            ValueOutputs = 0;
            foreach (fueled fu in ListFueleds)
                ValueFueled += fu.total;
            foreach (output o in ListOutputs)
                ValueOutputs += o.value;

            tfFueled.EditValue = ValueFueled;
            tfOutputs.EditValue = ValueOutputs;
            stay st = stay.SingleOrDefault("WHERE freight_id=@0", f.id);
            if (st != null)
            {
                tfStay.EditValue = st.total;
                tfExtraComission.EditValue = st.total_comission;
                if (((freight)bdgFreight.Current) != null)
                    ((freight)bdgFreight.Current).extra_comission = st.total_comission;
                tfExtraComission.Properties.ReadOnly = true;
            }
        }
Beispiel #22
0
 internal static bool NumberNoteFreightUnique(freight fre)
 {
     try
     {
         int count;
         var s = TruckSystemRepo.GetInstance().ExecuteScalar<string>
             ("SELECT COUNT(id) FROM freights WHERE number_note=@0", fre.number_note);
         if (s.Equals(DBNull.Value) || String.IsNullOrEmpty(s))
             count = 0;
         else
             count = Convert.ToInt32(s);
         if (count == 0)
             return true;
         else
             return false;
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message, ex.InnerException);
     }
 }