Untitled

 avatar
unknown
plain_text
25 days ago
60 kB
9
Indexable
using BTWMS.Mobil.Models;
using BTWMS.Mobil.Models.Logo;
using BTWMS.Mobil.Models.Material;
using BTWMS.Mobil.Models.Receipt;
using BTWMS.Mobil.Models.User;
using BTWMS.Mobil.Services;
using BTWMS.Mobil.StaticClass;
using BTWMS.Mobil.Views.Generic;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Essentials;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace BTWMS.Mobil.Views.Material
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class CountFiche : TabbedPage
    {
        UserServices userServices = new UserServices();
        ReceiptServices receiptServices = new ReceiptServices();
        LogoServices logoServices = new LogoServices();
        MaterialServices materialServices = new MaterialServices();
        private int _recordref;
        private string _ficheNo;
        private bool _buttonType;
        private bool _internetsiz;
        public CountFiche(int recordref,string ficheno,bool buttonType,bool internetsiz)
        {
            _buttonType = buttonType;
            _ficheNo = ficheno;
               _recordref = recordref;
            InitializeComponent();
            BarkodEntry.Focus();
            _internetsiz = internetsiz;
            Kontrol();
        }
        int AmbarNo = 0;
        List<UserWareHouseModel> userWareHouseModels = new List<UserWareHouseModel>();

        private async void Kontrol()
        {

            if (_buttonType == false)
            {
                KaydetButton.IsEnabled = false;
            }

            if (_recordref == 0)
            {
                string ficheNo  = await materialServices.getCountFicheNo();
                FisNoEntry.Text = ficheNo;
                SaveCountingLineModel saveCountingLineModel = new SaveCountingLineModel();
                saveCountingLineModel.COUNTFICHEREF = -1;
                saveCountingLineModel.USERREF = UserStaticModel.USERREF;
                saveCountingLineModel.FIRMNR = UserStaticModel.FIRMNR;
                var countingLineList = await materialServices.getCountingLineList(saveCountingLineModel);
                if (countingLineList.Count > 0)
                {
                    var result = await DisplayAlert("UYARI", "Kaydedilmemiş kayıtlar mevcut. Kayıtlar geri yüklensin Mi?", "EVET", "HAYIR");
                    if (!result)
                    {
                        await materialServices.deleteCountTemp(saveCountingLineModel);
                    }
                }
            }
            else
            {
                FisNoEntry.Text = _ficheNo;

                SaveCountingLineModel saveCountingLineModel = new SaveCountingLineModel();
                saveCountingLineModel.COUNTFICHEREF = -1;
                saveCountingLineModel.USERREF = UserStaticModel.USERREF;
                saveCountingLineModel.FIRMNR = UserStaticModel.FIRMNR;
                await materialServices.deleteCountTemp(saveCountingLineModel);

                CountingModel countingModel = new CountingModel();
                countingModel.RECORDREF = _recordref;
                var response = await materialServices.saveCountingToTemp(countingModel);
                if (response.STATUS == 0)
                {
                    await DisplayAlert("UYARI", "Kaydedilen veriler çekilemedi.", "ok");
                }


                if (_internetsiz == true)
                {
                    SaveCountinglineSeriLotModel postModel = new SaveCountinglineSeriLotModel();
                    postModel.COUNTFICHEREF = -1;
                    postModel.USERREF = UserStaticModel.USERREF;
                    postModel.FIRMNR = UserStaticModel.FIRMNR;
                    countinglineSeriLotModels = await materialServices.getCountingLineSeriLotList(postModel);
                }
            }



        }
        protected async override void OnAppearing()
        {
            SKTEntry.Date = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            FicheDate.Date = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            BarkodEntry.Focus();

            if (_internetsiz == true)
            {
                if (Enums.UrunKod != "")
                {
                    SearchBarcodeSendModel searchBarcodeSendModel = new SearchBarcodeSendModel();
                    searchBarcodeSendModel.FIRMNR = UserStaticModel.FIRMNR;
                    searchBarcodeSendModel.BARCODE = Enums.UrunKod;
                    searchModel = UserAuthModelStatic.searchModelList.Where(x=>x.BARCODE==Enums.UrunKod).FirstOrDefault();
                    KodBaslik.IsVisible = true;
                    AciklamaBaslik.IsVisible = true;
                    BirimBaslik.IsVisible = true;
                    UrunKoduLabel.IsVisible = true;
                    UrunKoduLabel.Text = searchModel.STOCKCODE;
                    UrunAciklamaLabel.IsVisible = true;
                    UrunAciklamaLabel.Text = searchModel.STOCKNAME;
                    UrunBirimLabel.IsVisible = true;
                    UrunBirimLabel.Text = searchModel.UNITCODE;
                    BarkodEntry.IsVisible = false;
                    Enums.UrunKod = "";
                    MiktarEntry.IsVisible = true;
                    MiktarEntry.Focus();
                    if (searchModel.TRACKTYPE == 2)
                    {
                        MiktarEntry.Text = "1";
                        MiktarOkut();
                    }
                }
            }
            else
            {
                if (Enums.UrunKod != "")
                {
                    SearchBarcodeSendModel searchBarcodeSendModel = new SearchBarcodeSendModel();
                    searchBarcodeSendModel.FIRMNR = UserStaticModel.FIRMNR;
                    searchBarcodeSendModel.BARCODE = Enums.UrunKod;
                    searchModel = await receiptServices.getSearchBarcode(searchBarcodeSendModel);
                    KodBaslik.IsVisible = true;
                    AciklamaBaslik.IsVisible = true;
                    BirimBaslik.IsVisible = true;
                    UrunKoduLabel.IsVisible = true;
                    UrunKoduLabel.Text = searchModel.STOCKCODE;
                    UrunAciklamaLabel.IsVisible = true;
                    UrunAciklamaLabel.Text = searchModel.STOCKNAME;
                    UrunBirimLabel.IsVisible = true;
                    UrunBirimLabel.Text = searchModel.UNITCODE;
                    BarkodEntry.IsVisible = false;
                    Enums.UrunKod = "";
                    MiktarEntry.IsVisible = true;
                    MiktarEntry.Focus();
                    if (searchModel.TRACKTYPE == 2)
                    {
                        MiktarEntry.Text = "1";
                        MiktarOkut();
                    }
                }
            }

            

        }


        private void Giris_Appearing(object sender, EventArgs e)
        {

        }
        SearchBarcodeResponseModel searchModel = new SearchBarcodeResponseModel();
        private async void BarkodEntry_Completed(object sender, EventArgs e)
        {
            string barcode = BarkodEntry.Text;

            if (barcode == "" || barcode == null)
            {
                await DisplayAlert("UYARI", "Barkod veya ürün kodu giriniz.", "OK");
            }
            else
            {
                if (_internetsiz == true)
                {
                    OfflineBarkodSorgula(barcode);
                }
                else
                {
                    OnlineBarkodSorgula(barcode);
                }
            }

        }




        private async void OnlineBarkodSorgula(string barcode)
        {
            if (barcode == "" || barcode == null)
            {
                await DisplayAlert("UYARI", "Barkod veya ürün kodu giriniz.", "OK");
            }
            else
            {
                SearchBarcodeSendModel searchBarcodeSendModel = new SearchBarcodeSendModel();
                searchBarcodeSendModel.FIRMNR = UserStaticModel.FIRMNR;
                searchBarcodeSendModel.BARCODE = barcode;
                searchModel = await receiptServices.getSearchBarcode(searchBarcodeSendModel);
                if (searchModel.STOCKREF == 0)
                {


                    var itemList = await receiptServices.getSearchBarcodeList(searchBarcodeSendModel);
                    if (itemList.Count > 0)
                    {
                        await Navigation.PushAsync(new PopupItemList(itemList));
                    }
                    else
                    {
                        await DisplayAlert("UYARI", "Ürün bulunamadı.Kontrol ediniz.", "OK");
                        BarkodEntry.Text = "";
                        BarkodEntry.Focus();

                    }



                }
                else
                {
                    KodBaslik.IsVisible = true;
                    AciklamaBaslik.IsVisible = true;
                    BirimBaslik.IsVisible = true;
                    UrunKoduLabel.IsVisible = true;
                    UrunKoduLabel.Text = searchModel.STOCKCODE;
                    UrunAciklamaLabel.IsVisible = true;
                    UrunAciklamaLabel.Text = searchModel.STOCKNAME;
                    UrunBirimLabel.IsVisible = true;
                    UrunBirimLabel.Text = searchModel.UNITCODE;
                    BarkodEntry.IsVisible = false;

                    MiktarEntry.IsVisible = true;
                    MiktarEntry.Focus();
                    if (searchModel.TRACKTYPE == 2)
                    {
                        MiktarEntry.Text = "1";
                        MiktarOkut();
                    }



                }
            }
        }

        private async void OfflineBarkodSorgula(string barcode)
        {
            if (barcode == "" || barcode == null)
            {
                await DisplayAlert("UYARI", "Barkod veya ürün kodu giriniz.", "OK");
            }
            else
            {
                searchModel = UserAuthModelStatic.searchModelList.Where(x=>x.BARCODE ==  barcode).FirstOrDefault();
                if ( searchModel == null)
                {

                    searchModel = new SearchBarcodeResponseModel();
                    searchModel = UserAuthModelStatic.searchModelList.Where(x => x.STOCKCODE == barcode).FirstOrDefault();


                    if ( searchModel == null)
                    {
                        var itemList = UserAuthModelStatic.searchModelList;
                        if (itemList.Count > 0)
                        {
                            await Navigation.PushAsync(new PopupItemList(UserAuthModelStatic.searchModelList));
                        }
                        else
                        {
                            await DisplayAlert("UYARI", "Ürün bulunamadı.Kontrol ediniz.", "OK");
                            BarkodEntry.Text = "";
                            BarkodEntry.Focus();

                        }
                    }
                    else
                    {

                        KodBaslik.IsVisible = true;
                        AciklamaBaslik.IsVisible = true;
                        BirimBaslik.IsVisible = true;
                        UrunKoduLabel.IsVisible = true;
                        UrunKoduLabel.Text = searchModel.STOCKCODE;
                        UrunAciklamaLabel.IsVisible = true;
                        UrunAciklamaLabel.Text = searchModel.STOCKNAME;
                        UrunBirimLabel.IsVisible = true;
                        UrunBirimLabel.Text = searchModel.UNITCODE;
                        BarkodEntry.IsVisible = false;

                        MiktarEntry.IsVisible = true;
                        MiktarEntry.Focus();
                        if (searchModel.TRACKTYPE == 2)
                        {
                            MiktarEntry.Text = "1";
                            MiktarOkut();
                        }
                    }
                    



                }
                else
                {
                    KodBaslik.IsVisible = true;
                    AciklamaBaslik.IsVisible = true;
                    BirimBaslik.IsVisible = true;
                    UrunKoduLabel.IsVisible = true;
                    UrunKoduLabel.Text = searchModel.STOCKCODE;
                    UrunAciklamaLabel.IsVisible = true;
                    UrunAciklamaLabel.Text = searchModel.STOCKNAME;
                    UrunBirimLabel.IsVisible = true;
                    UrunBirimLabel.Text = searchModel.UNITCODE;
                    BarkodEntry.IsVisible = false;

                    MiktarEntry.IsVisible = true;
                    MiktarEntry.Focus();
                    if (searchModel.TRACKTYPE == 2)
                    {
                        MiktarEntry.Text = "1";
                        MiktarOkut();
                    }



                }
            }
        }


        List<CountingLineModel> countingLineModelsAll = new List<CountingLineModel>();
        private async void Kaydet1()
        {


            if (_internetsiz == true)
            {
                CountingLineModel saveCountingLineModel = new CountingLineModel();
                saveCountingLineModel.COUNTFICHEREF = -1;

                saveCountingLineModel.UINFO1 = searchModel.UINFO1;
                saveCountingLineModel.UINFO2 = searchModel.UINFO2;
                saveCountingLineModel.UOMREF = searchModel.UNITLINEREF;
                saveCountingLineModel.STOCKREF = searchModel.STOCKREF;
                saveCountingLineModel.STOCKCODE = searchModel.STOCKCODE;
                saveCountingLineModel.STOCKNAME = searchModel.STOCKNAME;
                saveCountingLineModel.UNITCODE = searchModel.UNITCODE;
                saveCountingLineModel.TRACKTYPE = searchModel.TRACKTYPE;
                saveCountingLineModel.READAMOUNT = Convert.ToDouble(UrunMiktarLabel.Text);
                saveCountingLineModel.READCOUNT = 1;
                saveCountingLineModel.USERREF = UserStaticModel.USERREF;
                saveCountingLineModel.FIRMNR = UserStaticModel.FIRMNR;
                countingLineModelsAll.Add(saveCountingLineModel);
                Sifirla();
            }
            else
            {
                SaveCountingLineModel saveCountingLineModel = new SaveCountingLineModel();
                saveCountingLineModel.COUNTFICHEREF = -1;

                saveCountingLineModel.UINFO1 = searchModel.UINFO1;
                saveCountingLineModel.UINFO2 = searchModel.UINFO2;
                saveCountingLineModel.UOMREF = searchModel.UNITLINEREF;
                saveCountingLineModel.STOCKREF = searchModel.STOCKREF;
                saveCountingLineModel.STOCKCODE = searchModel.STOCKCODE;
                saveCountingLineModel.STOCKNAME = searchModel.STOCKNAME;
                saveCountingLineModel.UNITCODE = searchModel.UNITCODE;
                saveCountingLineModel.TRACKTYPE = searchModel.TRACKTYPE;
                saveCountingLineModel.READAMOUNT = Convert.ToDouble(UrunMiktarLabel.Text);
                saveCountingLineModel.READCOUNT = 1;
                saveCountingLineModel.USERREF = UserStaticModel.USERREF;
                saveCountingLineModel.FIRMNR = UserStaticModel.FIRMNR;
                var responseModel = await materialServices.saveCountingLine(saveCountingLineModel);
                if (responseModel.STATUS == 0)
                {
                    await DisplayAlert("HATA", responseModel.MSG, "ok");
                }
                else
                {
                    Sifirla();
                }
            }

            
        }

        private async void Kaydet2()
        {


            if (_internetsiz == true)
            {
                CountingLineModel saveCountingLineModel = new CountingLineModel();
                saveCountingLineModel.COUNTFICHEREF = -1;

                saveCountingLineModel.UINFO1 = searchModel.UINFO1;
                saveCountingLineModel.UINFO2 = searchModel.UINFO2;
                saveCountingLineModel.UOMREF = searchModel.UNITLINEREF;
                saveCountingLineModel.STOCKREF = searchModel.STOCKREF;
                saveCountingLineModel.STOCKCODE = searchModel.STOCKCODE;
                saveCountingLineModel.STOCKNAME = searchModel.STOCKNAME;
                saveCountingLineModel.UNITCODE = searchModel.UNITCODE;
                saveCountingLineModel.TRACKTYPE = searchModel.TRACKTYPE;
                saveCountingLineModel.READAMOUNT = Convert.ToDouble(UrunMiktarLabel.Text);
                saveCountingLineModel.READCOUNT = 1;
                saveCountingLineModel.USERREF = UserStaticModel.USERREF;
                saveCountingLineModel.FIRMNR = UserStaticModel.FIRMNR;
                countingLineModelsAll.Add(saveCountingLineModel);
                if (1 == 0)
                {
                    await DisplayAlert("HATA", "", "ok");
                }
                else
                {

                    CountinglineSeriLotModel saveCountinglineSeriLotModel = new CountinglineSeriLotModel();
                    saveCountinglineSeriLotModel.COUNTFICHEREF = -1;
                    saveCountinglineSeriLotModel.STOCKREF = searchModel.STOCKREF;
                    saveCountinglineSeriLotModel.STOCKNAME = searchModel.STOCKNAME;
                    saveCountinglineSeriLotModel.STOCKCODE = searchModel.STOCKCODE;
                    saveCountinglineSeriLotModel.UNITCODE = searchModel.UNITCODE;
                    saveCountinglineSeriLotModel.SERILOTNO = UrunLotLabel.Text; ;
                    saveCountinglineSeriLotModel.SERILOTDESC = LotAciklamaEntry.Text; ;
                    saveCountinglineSeriLotModel.SLTYPE = searchModel.TRACKTYPE;
                    saveCountinglineSeriLotModel.TRACKTYPE = searchModel.TRACKTYPE;
                    saveCountinglineSeriLotModel.READAMOUNT = Convert.ToDouble(UrunMiktarLabel.Text);

                    saveCountinglineSeriLotModel.READCOUNT = 1;
                    saveCountinglineSeriLotModel.UINFO1 = searchModel.UINFO1;
                    saveCountinglineSeriLotModel.UINFO2 = searchModel.UINFO2;
                    saveCountinglineSeriLotModel.UOMREF = searchModel.UNITLINEREF;
                    var gelenDate = SKTEntry.Date.ToString();
                    var expdate = DateTime.Parse(gelenDate).ToString("yyyy.MM.dd", CultureInfo.InvariantCulture);
                    saveCountinglineSeriLotModel.EXPDATE = expdate;

                    saveCountinglineSeriLotModel.LOCATION = UrunStokYeriLabel.Text;

                    saveCountinglineSeriLotModel.USERREF = UserStaticModel.USERREF;
                    saveCountinglineSeriLotModel.FIRMNR = UserStaticModel.FIRMNR;

                    countinglineSeriLotModels.Add(saveCountinglineSeriLotModel);
                   
                        Sifirla();

                }
            }
            else
            {
                SaveCountingLineModel saveCountingLineModel = new SaveCountingLineModel();
                saveCountingLineModel.COUNTFICHEREF = -1;

                saveCountingLineModel.UINFO1 = searchModel.UINFO1;
                saveCountingLineModel.UINFO2 = searchModel.UINFO2;
                saveCountingLineModel.UOMREF = searchModel.UNITLINEREF;
                saveCountingLineModel.STOCKREF = searchModel.STOCKREF;
                saveCountingLineModel.STOCKCODE = searchModel.STOCKCODE;
                saveCountingLineModel.STOCKNAME = searchModel.STOCKNAME;
                saveCountingLineModel.UNITCODE = searchModel.UNITCODE;
                saveCountingLineModel.TRACKTYPE = searchModel.TRACKTYPE;
                saveCountingLineModel.READAMOUNT = Convert.ToDouble(UrunMiktarLabel.Text);
                saveCountingLineModel.READCOUNT = 1;
                saveCountingLineModel.USERREF = UserStaticModel.USERREF;
                saveCountingLineModel.FIRMNR = UserStaticModel.FIRMNR;
                var responseModel = await materialServices.saveCountingLine(saveCountingLineModel);
                if (responseModel.STATUS == 0)
                {
                    await DisplayAlert("HATA", responseModel.MSG, "ok");
                }
                else
                {

                    SaveCountinglineSeriLotModel saveCountinglineSeriLotModel = new SaveCountinglineSeriLotModel();
                    saveCountinglineSeriLotModel.COUNTFICHEREF = -1;
                    saveCountinglineSeriLotModel.STOCKREF = searchModel.STOCKREF;
                    saveCountinglineSeriLotModel.STOCKNAME = searchModel.STOCKNAME;
                    saveCountinglineSeriLotModel.STOCKCODE = searchModel.STOCKCODE;
                    saveCountinglineSeriLotModel.UNITCODE = searchModel.UNITCODE;
                    saveCountinglineSeriLotModel.SERILOTNO = UrunLotLabel.Text; ;
                    saveCountinglineSeriLotModel.SERILOTDESC = LotAciklamaEntry.Text; ;
                    saveCountinglineSeriLotModel.SLTYPE = searchModel.TRACKTYPE;
                    saveCountinglineSeriLotModel.TRACKTYPE = searchModel.TRACKTYPE;
                    saveCountinglineSeriLotModel.READAMOUNT = Convert.ToDouble(UrunMiktarLabel.Text);

                    saveCountinglineSeriLotModel.READCOUNT = 1;
                    saveCountinglineSeriLotModel.UINFO1 = searchModel.UINFO1;
                    saveCountinglineSeriLotModel.UINFO2 = searchModel.UINFO2;
                    saveCountinglineSeriLotModel.UOMREF = searchModel.UNITLINEREF;
                    var gelenDate = SKTEntry.Date.ToString();
                    var expdate = DateTime.Parse(gelenDate).ToString("yyyy.MM.dd", CultureInfo.InvariantCulture);
                    saveCountinglineSeriLotModel.EXPDATE = expdate;

                    saveCountinglineSeriLotModel.LOCATION = UrunStokYeriLabel.Text;

                    saveCountinglineSeriLotModel.USERREF = UserStaticModel.USERREF;
                    saveCountinglineSeriLotModel.FIRMNR = UserStaticModel.FIRMNR;
                    var responseModel2 = await materialServices.saveCountingLineSeriLot(saveCountinglineSeriLotModel);
                    if (responseModel2.STATUS == 0)
                    {
                        await DisplayAlert("HATA", responseModel2.MSG, "ok");
                    }
                    else
                    {
                        Sifirla();
                    }


                }
            }

            
        }

        private void Sifirla()
        {
            LotAciklamaEntry.Text = "";
            LotEntry.Text = "";
            MiktarEntry.Text = "";
            SKTEntry.Date = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            FicheDate.Date = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            BarkodEntry.Text = "";
            StokYeriEntry.Text = "";
            LotAciklamaEntry.IsVisible = false;
            LotEntry.IsVisible = false;
            MiktarEntry.IsVisible = false;
            StokYeriEntry.IsVisible = false;
            BarkodEntry.IsVisible = true;
            BarkodEntry.Focus();

            UrunAciklamaLabel.Text = "";
            UrunAciklamaLabel.IsVisible = false;

            UrunBirimLabel.Text = "";
            UrunBirimLabel.IsVisible = false;

            UrunKoduLabel.Text = "";
            UrunKoduLabel.IsVisible = false;

            UrunLotLabel.Text = "";
            UrunLotLabel.IsVisible = false;

            UrunMiktarLabel.Text = "";
            UrunMiktarLabel.IsVisible = false;

            UrunStokYeriLabel.Text = "";
            UrunStokYeriLabel.IsVisible = false;

            gridGiris.IsVisible = false;

            SKTEntryButton.IsVisible = false;

            KodBaslik.IsVisible = false;
            AciklamaBaslik.IsVisible = false;
            BirimBaslik.IsVisible = false;
            MiktarBaslik.IsVisible = false;
            StokYeriBaslik.IsVisible = false;
            LotBaslik.IsVisible = false;
        }

        private async void MiktarOkut()
        {
            string miktar = MiktarEntry.Text.Replace('.',',');

            if (miktar == null || miktar == "")
            {
                await DisplayAlert("UYARI", "Miktar Giriniz.", "OK");
            }
            else
            {
                MiktarBaslik.IsVisible = true;
                UrunMiktarLabel.IsVisible = true;
                UrunMiktarLabel.Text = Convert.ToDouble(miktar).ToString("N2");

                if (searchModel.LOCTRACKING == 1)
                {
                    MiktarEntry.Text = "";
                    MiktarEntry.IsVisible = false;
                    StokYeriEntry.IsVisible = true;
                    StokYeriEntry.Focus();


                    if (_internetsiz == true)
                    {
                       
                        userWareHouseModels = UserAuthModelStatic.userwarehouseList;
                        var userwareHouse = userWareHouseModels.Where(x => x.TYPE_ == FicheType.gCount).FirstOrDefault();
                        var locationList = UserAuthModelStatic.locationlist.Where(x => x.INVENNR == userwareHouse.SOURCE_WAREHOUSE).ToList();
                        gridGiris.IsVisible = true;
                        gridGiris.BindingContext = locationList;
                    }
                    else
                    {
                        UserrefSendModel userrefSendModel = new UserrefSendModel();
                        userrefSendModel.USERREF = UserStaticModel.USERREF;
                        userWareHouseModels = await userServices.getUserWareHouseList(userrefSendModel);
                        var userwareHouse = userWareHouseModels.Where(x => x.TYPE_ == FicheType.gCount).FirstOrDefault();
                        LocationPostModel locationPostModel = new LocationPostModel();
                        locationPostModel.FIRMNR = UserStaticModel.FIRMNR;
                        locationPostModel.INVENNR = userwareHouse.SOURCE_WAREHOUSE;
                        var locationList = await logoServices.getLocationList(locationPostModel);
                        gridGiris.IsVisible = true;
                        gridGiris.BindingContext = locationList;
                    }


                }
                else
                {
                    if (searchModel.TRACKTYPE == 0)
                    {
                        // Kaydetme İşlemi Yap
                        Kaydet1();
                    }
                    else
                    {
                        MiktarEntry.Text = "";
                        MiktarEntry.IsVisible = false;


                        if (StaticParamsModel.SKT_USE == 0)
                        {
                            SKTEntry.IsVisible = true;
                            SKTEntryButton.IsVisible = true;
                        }
                        else if (StaticParamsModel.SKT_USE == 1)
                        {
                            ItemSktPostModel ıtemSktPostModel = new ItemSktPostModel();
                            ıtemSktPostModel.FIRMNR = UserStaticModel.FIRMNR.ToString().PadLeft(3, '0');
                            ıtemSktPostModel.CODE = UrunKoduLabel.Text;
                            ıtemSktPostModel.SKT_VALUE = StaticParamsModel.SKT_VALUE;
                            ıtemSktPostModel.SKT_DEF = StaticParamsModel.SKT_DEF;
                            var sktModel = await userServices.getItemSkt(ıtemSktPostModel);
                            if (sktModel.LOGICALREF > 0)
                            {
                                SKTEntry.IsVisible = true;
                                SKTEntryButton.IsVisible = true;
                            }
                            else
                            {
                                SKTEntry.IsVisible = false;
                                SKTEntryButton.IsVisible = false;

                                LotEntry.IsVisible = true;

                                LotEntry.IsVisible = true;
                                LotEntry.Focus();
                                LotEntry.LabelText = "Seri No Okutunuz.";
                            }
                        }
                        else
                        {
                            LotEntry.IsVisible = true;

                            LotEntry.IsVisible = true;
                            LotEntry.Focus();
                            LotEntry.LabelText = "Seri No Okutunuz.";
                        }
                    }
                }

            }
        }

        private void MiktarEntry_Completed(object sender, EventArgs e)
        {
            MiktarOkut();
        }
        private async void StokYeriOkut()
        {
            string stokYeri = StokYeriEntry.Text;

            if (stokYeri == null || stokYeri == "")
            {
                await DisplayAlert("UYARI", "Stok Yeri Okutunuz.", "OK");

            }
            else
            {

                if (_internetsiz == true)
                {
                    userWareHouseModels = UserAuthModelStatic.userwarehouseList;
                    var userwareHouse = userWareHouseModels.Where(x => x.TYPE_ == FicheType.gCount).FirstOrDefault();
                    var locationList = UserAuthModelStatic.locationlist.Where(x => x.INVENNR == userwareHouse.SOURCE_WAREHOUSE).ToList();
                    var locationModel = locationList.Where(x => x.CODE.ToUpper() == stokYeri.ToUpper()).FirstOrDefault();
                    if (locationModel == null)
                    {
                        await DisplayAlert("UYARI", "Okutulan Stok Yeri Bulunamadı.Kontrol ediniz.", "OK");
                        StokYeriEntry.Text = "";
                        StokYeriEntry.Focus();
                    }
                    else
                    {
                        if (searchModel.TRACKTYPE == 0)
                        {
                            UrunStokYeriLabel.IsVisible = true;
                            UrunStokYeriLabel.Text = StokYeriEntry.Text;
                            Kaydet2();
                        }
                        else
                        {
                            StokYeriBaslik.IsVisible = true;
                            UrunStokYeriLabel.IsVisible = true;
                            UrunStokYeriLabel.Text = StokYeriEntry.Text;
                            StokYeriEntry.Text = "";
                            StokYeriEntry.IsVisible = false;
                            gridGiris.IsVisible = false;
                            SKTEntry.IsVisible = true;
                            SKTEntryButton.IsVisible = true;
                        }
                    }
                }
                else
                {
                    UserrefSendModel userrefSendModel = new UserrefSendModel();
                    userrefSendModel.USERREF = UserStaticModel.USERREF;
                    userWareHouseModels = await userServices.getUserWareHouseList(userrefSendModel);
                    var userwareHouse = userWareHouseModels.Where(x => x.TYPE_ == FicheType.gCount).FirstOrDefault();
                    LocationPostModel locationPostModel = new LocationPostModel();
                    locationPostModel.FIRMNR = UserStaticModel.FIRMNR;
                    locationPostModel.INVENNR = userwareHouse.SOURCE_WAREHOUSE;
                    var locationList = await logoServices.getLocationList(locationPostModel);
                    var locationModel = locationList.Where(x => x.CODE.ToUpper() == stokYeri.ToUpper()).FirstOrDefault();
                    if (locationModel == null)
                    {
                        await DisplayAlert("UYARI", "Okutulan Stok Yeri Bulunamadı.Kontrol ediniz.", "OK");
                        StokYeriEntry.Text = "";
                        StokYeriEntry.Focus();
                    }
                    else
                    {
                        if (searchModel.TRACKTYPE == 0)
                        {
                            UrunStokYeriLabel.IsVisible = true;
                            UrunStokYeriLabel.Text = StokYeriEntry.Text;
                            Kaydet2();
                        }
                        else
                        {
                            StokYeriBaslik.IsVisible = true;
                            UrunStokYeriLabel.IsVisible = true;
                            UrunStokYeriLabel.Text = StokYeriEntry.Text;
                            StokYeriEntry.Text = "";
                            StokYeriEntry.IsVisible = false;
                            gridGiris.IsVisible = false;
                            

                            if(StaticParamsModel.SKT_USE == 1)
                            {
                                LotEntry.IsVisible = true;

                                LotEntry.IsVisible = true;
                                LotEntry.Focus();
                                LotEntry.LabelText = "Seri No Okutunuz.";
                            }
                            else
                            {
                                SKTEntry.IsVisible = true;
                                SKTEntryButton.IsVisible = true;
                            }
                         
                        }
                    }
                }
            
            }
        }
        private void StokYeriEntry_Completed(object sender, EventArgs e)
        {
            StokYeriOkut();
        }

        private async void LotEntry_Completed(object sender, EventArgs e)
        {
            string lot = LotEntry.Text;

            if (lot == "" || lot == null)
            {
                if (searchModel.TRACKTYPE == 1)
                {
                    await DisplayAlert("UYARI", "Lot Okutunuz.", "OK");
                }
                else
                {
                    await DisplayAlert("UYARI", "Seri No Okutunuz.", "OK");
                }
            }
            else
            {


                if (searchModel.TRACKTYPE == 1)
                {
                    LotBaslik.IsVisible = true;
                    LotBaslik.Text = "Lot:";
                    UrunLotLabel.Text = LotEntry.Text;
                    LotEntry.IsVisible = false;
                    LotEntry.Text = "";


                    if (UserAuthModelStatic.INPUT_LOT_DESC == 0)
                    {
                        Kaydet2();
                    }
                    else
                    {
                        // Girilsin
                        LotAciklamaEntry.IsVisible = true;
                        LotAciklamaEntry.LabelText = "Lot Açıklaması Okutunuz.(var ise)";

                        UrunLotLabel.IsVisible = true;
                        LotAciklamaEntry.Focus();
                    }
                }
                else
                {
                    UrunLotLabel.Text = LotEntry.Text;
                    SaveCountinglineSeriLotModel postModel = new SaveCountinglineSeriLotModel();
                    postModel.SERILOTNO = UrunLotLabel.Text;
                    postModel.STOCKREF = searchModel.STOCKREF;
                    if(_recordref == 0)
                    {
                        postModel.COUNTFICHEREF = -1;
                    }
                    else
                    {
                        postModel.COUNTFICHEREF = _recordref;
                    }
                    
                    postModel.USERREF = UserStaticModel.USERREF;
                    postModel.FIRMNR = UserStaticModel.FIRMNR;

                    var responseModel = await materialServices.getSeriNoCheck(postModel);
                    if (responseModel.STATUS == 1)
                    {
                        LotBaslik.IsVisible = true;
                        LotBaslik.Text = "Seri No:";
                        UrunLotLabel.Text = LotEntry.Text;
                        LotEntry.IsVisible = false;
                        LotEntry.Text = "";

                        if (UserAuthModelStatic.INPUT_SERI_DESC == 0)
                        {
                            Kaydet2();
                        }
                        else
                        {
                            // Girilsin
                            LotAciklamaEntry.IsVisible = true;
                            LotAciklamaEntry.LabelText = "Seri Açıklaması Okutunuz.(var ise)";

                            UrunLotLabel.IsVisible = true;
                            LotAciklamaEntry.Focus();
                        }
                    }
                    else
                    {
                        await DisplayAlert("UYARI", "Aynı seri numarasından daha önce okuttunuz. Kontrol ediniz.", "OK");
                        LotEntry.Text = "";
                        LotEntry.Focus();
                    }


                }


            }
        }

        private void LotAciklamaEntry_Completed(object sender, EventArgs e)
        {
            Kaydet2();
        }

        private  void SKTEntryButton_Clicked(object sender, EventArgs e)
        {
            if (searchModel.TRACKTYPE == 1)
            {
                SKTEntry.IsVisible = false;
                SKTEntryButton.IsVisible = false;
                LotEntry.IsVisible = true;
                LotEntry.Focus();
                LotEntry.LabelText = "Lot Okutunuz.";


            }
            else if (searchModel.TRACKTYPE == 2)
            {
                SKTEntry.IsVisible = false;
                SKTEntryButton.IsVisible = false;
                LotEntry.IsVisible = true;
                LotEntry.Focus();
                LotEntry.LabelText = "Seri No Okutunuz.";
            }
        }

        private void SecSwipe_Tap(object sender, DevExpress.XamarinForms.DataGrid.SwipeItemTapEventArgs e)
        {
            var item = (LocationModel)e.Item;
            StokYeriEntry.Text = item.CODE;
            StokYeriOkut();
        }

        private void DetayTab_Appearing(object sender, EventArgs e)
        {
            DetayIslemler();
        }
        List<CountinglineSeriLotModel> countinglineSeriLotModels = new List<CountinglineSeriLotModel>();
        private async void DetayIslemler()
        {

            if (_internetsiz == true)
            {
                if (FilterText.Text == null || FilterText.Text == "")
                {

                }
                else
                {
                    countinglineSeriLotModels = countinglineSeriLotModels.Where(x =>
         x.STOCKCODE.ToUpper().Contains(FilterText.Text.ToUpper()) ||
         x.STOCKNAME.ToUpper().Contains(FilterText.Text.ToUpper())
     ).ToList();
                }

                detayGrid.ItemsSource = null;
                detayGrid.RefreshData();

                detayGrid.ItemsSource = countinglineSeriLotModels;
            }
            else
            {
                SaveCountinglineSeriLotModel postModel = new SaveCountinglineSeriLotModel();
                postModel.COUNTFICHEREF = -1;
                postModel.USERREF = UserStaticModel.USERREF;
                postModel.FIRMNR = UserStaticModel.FIRMNR;
                countinglineSeriLotModels = await materialServices.getCountingLineSeriLotList(postModel);

                if (FilterText.Text == null || FilterText.Text == "")
                {

                }
                else
                {
                    countinglineSeriLotModels = countinglineSeriLotModels.Where(x =>
         x.STOCKCODE.ToUpper().Contains(FilterText.Text.ToUpper()) ||
         x.STOCKNAME.ToUpper().Contains(FilterText.Text.ToUpper())
     ).ToList();
                }

                detayGrid.ItemsSource = null;
                detayGrid.RefreshData();

                detayGrid.ItemsSource = countinglineSeriLotModels;
            }

          
        }
        private async void Sil_Tap(object sender, DevExpress.XamarinForms.DataGrid.SwipeItemTapEventArgs e)
        {
            var itemV = (CountinglineSeriLotModel)e.Item;
            bool answer = await DisplayAlert("UYARI", $"{itemV.STOCKCODE} kodlu ürüne ait seçilen kaydı silmek istiyor musunuz ?", "EVET", "HAYIR");
            if (answer)
            {

                if (_internetsiz == true)
                {
                    SaveCountinglineSeriLotModel postModel = new SaveCountinglineSeriLotModel();
                    postModel.STOCKREF = itemV.STOCKREF;
                    if (_recordref == 0)
                    {
                        postModel.COUNTFICHEREF = -1;
                    }
                    else
                    {
                        postModel.COUNTFICHEREF = _recordref;
                    }
                    postModel.USERREF = UserStaticModel.USERREF;
                    postModel.SERILOTNO = itemV.SERILOTNO;
                    DeleteCountingLineSeriLotLocal(postModel);
                    DetayIslemler();
                }
                else
                {
                    SaveCountinglineSeriLotModel postModel = new SaveCountinglineSeriLotModel();
                    postModel.STOCKREF = itemV.STOCKREF;
                    if (_recordref == 0)
                    {
                        postModel.COUNTFICHEREF = -1;
                    }
                    else
                    {
                        postModel.COUNTFICHEREF = _recordref;
                    }
                    postModel.USERREF = UserStaticModel.USERREF;
                    postModel.SERILOTNO = itemV.SERILOTNO;
                    await materialServices.deleteCountingLineSeriLot(postModel);
                    DetayIslemler();
                }
                
            }

        }

        public ResponseModel DeleteCountingLineSeriLotLocal(SaveCountinglineSeriLotModel sendModel)
        {
            var responseModel = new ResponseModel();

            try
            {
                sendModel.COUNTFICHEREF = -1; // Aynen SQL tarafında yaptığınız gibi

                // 1. READAMOUNT alma
                var seriLotEntry = countinglineSeriLotModels.FirstOrDefault(x =>
                    x.USERREF == sendModel.USERREF &&
                    x.COUNTFICHEREF == sendModel.COUNTFICHEREF &&
                    x.SERILOTNO == sendModel.SERILOTNO &&
                    x.STOCKREF == sendModel.STOCKREF);

                double miktar = seriLotEntry?.READAMOUNT ?? 0;

                // 2. COUNTINGLINESERILOT sil
                countinglineSeriLotModels.RemoveAll(x =>
                    x.USERREF == sendModel.USERREF &&
                    x.COUNTFICHEREF == sendModel.COUNTFICHEREF &&
                    x.SERILOTNO == sendModel.SERILOTNO &&
                    x.STOCKREF == sendModel.STOCKREF);

                // 3. COUNTINGLINE güncelle
                var lineEntry = countingLineModelsAll.FirstOrDefault(x =>
                    x.USERREF == sendModel.USERREF &&
                    x.COUNTFICHEREF == sendModel.COUNTFICHEREF &&
                    x.STOCKREF == sendModel.STOCKREF);

                if (lineEntry != null)
                {
                    lineEntry.READAMOUNT -= miktar;
                }

                // 4. Eğer SERILOTNO boşsa COUNTINGLINE da silinsin
                if (string.IsNullOrEmpty(sendModel.SERILOTNO))
                {
                    countingLineModelsAll.RemoveAll(x =>
                        x.USERREF == sendModel.USERREF &&
                        x.COUNTFICHEREF == sendModel.COUNTFICHEREF &&
                        x.STOCKREF == sendModel.STOCKREF);
                }

                responseModel.STATUS = 1;
            }
            catch (Exception ex)
            {
                responseModel.STATUS = 0;
                responseModel.MSG = ex.ToString();
            }

            return responseModel;
        }


        private async void KaydetButton_Clicked(object sender, EventArgs e)
        {

            var current = Connectivity.NetworkAccess;

            if (current != NetworkAccess.Internet)
            {
                await DisplayAlert("Bağlantı Hatası", "Lütfen internet bağlantınızı kontrol ediniz.", "Tamam");
                return;
            }

            if (_internetsiz == true)
            {
                if (_recordref == 0)
                {
                    


                    foreach (var item in countingLineModelsAll)
                    {
                        SaveCountingLineModel saveCountingLineModel = new SaveCountingLineModel();
                        saveCountingLineModel.COUNTFICHEREF = -1;

                        saveCountingLineModel.UINFO1 = item.UINFO1;
                        saveCountingLineModel.UINFO2 = item.UINFO2;
                        saveCountingLineModel.UOMREF = item.UOMREF;
                        saveCountingLineModel.STOCKREF = item.STOCKREF;
                        saveCountingLineModel.STOCKCODE = item.STOCKCODE;
                        saveCountingLineModel.STOCKNAME = item.STOCKNAME;
                        saveCountingLineModel.UNITCODE = item.UNITCODE;
                        saveCountingLineModel.TRACKTYPE = item.TRACKTYPE;
                        saveCountingLineModel.READAMOUNT = item.READAMOUNT;
                        saveCountingLineModel.READCOUNT = item.READCOUNT;
                        saveCountingLineModel.USERREF = item.USERREF;
                        saveCountingLineModel.FIRMNR = item.FIRMNR;
                        await materialServices.saveCountingLine(saveCountingLineModel);
                    }


                    foreach (var item in countinglineSeriLotModels)
                    {
                        SaveCountinglineSeriLotModel saveCountinglineSeriLotModel = new SaveCountinglineSeriLotModel();
                        saveCountinglineSeriLotModel.COUNTFICHEREF = -1;
                        saveCountinglineSeriLotModel.STOCKREF = item.STOCKREF;
                        saveCountinglineSeriLotModel.STOCKNAME = item.STOCKNAME;
                        saveCountinglineSeriLotModel.STOCKCODE = item.STOCKCODE;
                        saveCountinglineSeriLotModel.UNITCODE = item.UNITCODE;
                        saveCountinglineSeriLotModel.SERILOTNO = item.SERILOTNO; ;
                        saveCountinglineSeriLotModel.SERILOTDESC = item.SERILOTDESC; ;
                        saveCountinglineSeriLotModel.SLTYPE = item.TRACKTYPE;
                        saveCountinglineSeriLotModel.TRACKTYPE = item.TRACKTYPE;
                        saveCountinglineSeriLotModel.READAMOUNT = item.READAMOUNT;

                        saveCountinglineSeriLotModel.READCOUNT = 1;
                        saveCountinglineSeriLotModel.UINFO1 = item.UINFO1;
                        saveCountinglineSeriLotModel.UINFO2 = item.UINFO2;
                        saveCountinglineSeriLotModel.UOMREF = item.UOMREF;
                        var gelenDate = SKTEntry.Date.ToString();
                        var expdate = DateTime.Parse(gelenDate).ToString("yyyy.MM.dd", CultureInfo.InvariantCulture);
                        saveCountinglineSeriLotModel.EXPDATE = expdate;

                        saveCountinglineSeriLotModel.LOCATION = item.LOCATION;

                        saveCountinglineSeriLotModel.USERREF = item.USERREF;
                        saveCountinglineSeriLotModel.FIRMNR = item.FIRMNR;
                        var responseModel2 = await materialServices.saveCountingLineSeriLot(saveCountinglineSeriLotModel);
                    }

                    CountingModel countingModel = new CountingModel();
                    countingModel.RECORDREF = 0;
                    countingModel.FICHENO = FisNoEntry.Text;
                    countingModel.DATE_ = DateTime.Now.ToString("yyyy.MM.dd");
                    UserrefSendModel userrefSendModel = new UserrefSendModel();
                    userrefSendModel.USERREF = UserStaticModel.USERREF;
                    userWareHouseModels = await userServices.getUserWareHouseList(userrefSendModel);
                    var userwareHouse = userWareHouseModels.Where(x => x.TYPE_ == FicheType.gCount).FirstOrDefault();
                    countingModel.BRANCH = userwareHouse.SOURCE_DIVISION;
                    countingModel.DEPARTMENT = userwareHouse.SOURCE_DEPARTMENT;
                    countingModel.SOURCEINDEX = userwareHouse.SOURCE_WAREHOUSE;
                    countingModel.USERREF = UserStaticModel.USERREF;
                    countingModel.FIRMNR = UserStaticModel.FIRMNR;
                    countingModel.STATU = 0;
                    var responseModel = await materialServices.saveCounting(countingModel);
                    if (responseModel.STATUS > 0)
                    {
                        await DisplayAlert("UYARI", "Başarılı bir şekilde kayıt edildi.", "OK");
                        await Navigation.PopAsync();
                    }
                    else
                    {
                        await DisplayAlert("HATA", responseModel.MSG, "OK");
                    }

                }
                else
                {
                    SaveCountingLineModel saveCountingLineModel = new SaveCountingLineModel();
                    saveCountingLineModel.USERREF = UserStaticModel.USERREF;
                    saveCountingLineModel.COUNTFICHEREF = _recordref;
                    await materialServices.deleteCountTemp(saveCountingLineModel);

                    foreach (var item in countingLineModelsAll)
                    {
                        saveCountingLineModel = new SaveCountingLineModel();
                        saveCountingLineModel.COUNTFICHEREF = -1;

                        saveCountingLineModel.UINFO1 = item.UINFO1;
                        saveCountingLineModel.UINFO2 = item.UINFO2;
                        saveCountingLineModel.UOMREF = item.UOMREF;
                        saveCountingLineModel.STOCKREF = item.STOCKREF;
                        saveCountingLineModel.STOCKCODE = item.STOCKCODE;
                        saveCountingLineModel.STOCKNAME = item.STOCKNAME;
                        saveCountingLineModel.UNITCODE = item.UNITCODE;
                        saveCountingLineModel.TRACKTYPE = item.TRACKTYPE;
                        saveCountingLineModel.READAMOUNT = item.READAMOUNT;
                        saveCountingLineModel.READCOUNT = item.READCOUNT;
                        saveCountingLineModel.USERREF = item.USERREF;
                        saveCountingLineModel.FIRMNR = item.FIRMNR;
                        await materialServices.saveCountingLine(saveCountingLineModel);
                    }


                    foreach (var item in countinglineSeriLotModels)
                    {
                        SaveCountinglineSeriLotModel saveCountinglineSeriLotModel = new SaveCountinglineSeriLotModel();
                        saveCountinglineSeriLotModel.COUNTFICHEREF = -1;
                        saveCountinglineSeriLotModel.STOCKREF = item.STOCKREF;
                        saveCountinglineSeriLotModel.STOCKNAME = item.STOCKNAME;
                        saveCountinglineSeriLotModel.STOCKCODE = item.STOCKCODE;
                        saveCountinglineSeriLotModel.UNITCODE = item.UNITCODE;
                        saveCountinglineSeriLotModel.SERILOTNO = item.SERILOTNO; ;
                        saveCountinglineSeriLotModel.SERILOTDESC = item.SERILOTDESC; ;
                        saveCountinglineSeriLotModel.SLTYPE = item.TRACKTYPE;
                        saveCountinglineSeriLotModel.TRACKTYPE = item.TRACKTYPE;
                        saveCountinglineSeriLotModel.READAMOUNT = item.READAMOUNT;

                        saveCountinglineSeriLotModel.READCOUNT = 1;
                        saveCountinglineSeriLotModel.UINFO1 = item.UINFO1;
                        saveCountinglineSeriLotModel.UINFO2 = item.UINFO2;
                        saveCountinglineSeriLotModel.UOMREF = item.UOMREF;
                        var gelenDate = SKTEntry.Date.ToString();
                        var expdate = DateTime.Parse(gelenDate).ToString("yyyy.MM.dd", CultureInfo.InvariantCulture);
                        saveCountinglineSeriLotModel.EXPDATE = expdate;

                        saveCountinglineSeriLotModel.LOCATION = item.LOCATION;

                        saveCountinglineSeriLotModel.USERREF = item.USERREF;
                        saveCountinglineSeriLotModel.FIRMNR = item.FIRMNR;
                        var responseModel2 = await materialServices.saveCountingLineSeriLot(saveCountinglineSeriLotModel);
                    }

                    CountingModel countingModel = new CountingModel();
                    countingModel.RECORDREF = _recordref;
                    countingModel.FICHENO = FisNoEntry.Text;
                    countingModel.DATE_ = DateTime.Now.ToString("yyyy.MM.dd");
                    UserrefSendModel userrefSendModel = new UserrefSendModel();
                    userrefSendModel.USERREF = UserStaticModel.USERREF;
                    userWareHouseModels = await userServices.getUserWareHouseList(userrefSendModel);
                    var userwareHouse = userWareHouseModels.Where(x => x.TYPE_ == FicheType.gCount).FirstOrDefault();
                    countingModel.BRANCH = userwareHouse.SOURCE_DIVISION;
                    countingModel.DEPARTMENT = userwareHouse.SOURCE_DEPARTMENT;
                    countingModel.SOURCEINDEX = userwareHouse.SOURCE_WAREHOUSE;
                    countingModel.USERREF = UserStaticModel.USERREF;
                    countingModel.FIRMNR = UserStaticModel.FIRMNR;
                    countingModel.STATU = 0;

                    var responseModel = await materialServices.saveCounting(countingModel);
                    if (responseModel.STATUS > 0)
                    {
                        await DisplayAlert("UYARI", "Başarılı bir şekilde kayıt edildi.", "OK");
                        await Navigation.PopAsync();
                    }
                    else
                    {
                        await DisplayAlert("HATA", responseModel.MSG, "OK");
                    }



                }
            }
            else
            {
                if (_recordref == 0)
                {
                    CountingModel countingModel = new CountingModel();
                    countingModel.RECORDREF = 0;
                    countingModel.FICHENO = FisNoEntry.Text;
                    countingModel.DATE_ = DateTime.Now.ToString("yyyy.MM.dd");
                    UserrefSendModel userrefSendModel = new UserrefSendModel();
                    userrefSendModel.USERREF = UserStaticModel.USERREF;
                    userWareHouseModels = await userServices.getUserWareHouseList(userrefSendModel);
                    var userwareHouse = userWareHouseModels.Where(x => x.TYPE_ == FicheType.gCount).FirstOrDefault();
                    countingModel.BRANCH = userwareHouse.SOURCE_DIVISION;
                    countingModel.DEPARTMENT = userwareHouse.SOURCE_DEPARTMENT;
                    countingModel.SOURCEINDEX = userwareHouse.SOURCE_WAREHOUSE;
                    countingModel.USERREF = UserStaticModel.USERREF;
                    countingModel.FIRMNR = UserStaticModel.FIRMNR;
                    countingModel.STATU = 0;
                    var responseModel = await materialServices.saveCounting(countingModel);
                    if (responseModel.STATUS > 0)
                    {
                        await DisplayAlert("UYARI", "Başarılı bir şekilde kayıt edildi.", "OK");
                        await Navigation.PopAsync();
                    }
                    else
                    {
                        await DisplayAlert("HATA", responseModel.MSG, "OK");
                    }

                }
                else
                {
                    SaveCountingLineModel saveCountingLineModel = new SaveCountingLineModel();
                    saveCountingLineModel.USERREF = UserStaticModel.USERREF;
                    saveCountingLineModel.COUNTFICHEREF = _recordref;
                    await materialServices.deleteCountTemp(saveCountingLineModel);

                    CountingModel countingModel = new CountingModel();
                    countingModel.RECORDREF = _recordref;
                    countingModel.FICHENO = FisNoEntry.Text;
                    countingModel.DATE_ = DateTime.Now.ToString("yyyy.MM.dd");
                    UserrefSendModel userrefSendModel = new UserrefSendModel();
                    userrefSendModel.USERREF = UserStaticModel.USERREF;
                    userWareHouseModels = await userServices.getUserWareHouseList(userrefSendModel);
                    var userwareHouse = userWareHouseModels.Where(x => x.TYPE_ == FicheType.gCount).FirstOrDefault();
                    countingModel.BRANCH = userwareHouse.SOURCE_DIVISION;
                    countingModel.DEPARTMENT = userwareHouse.SOURCE_DEPARTMENT;
                    countingModel.SOURCEINDEX = userwareHouse.SOURCE_WAREHOUSE;
                    countingModel.USERREF = UserStaticModel.USERREF;
                    countingModel.FIRMNR = UserStaticModel.FIRMNR;
                    countingModel.STATU = 0;

                    var responseModel = await materialServices.saveCounting(countingModel);
                    if (responseModel.STATUS > 0)
                    {
                        await DisplayAlert("UYARI", "Başarılı bir şekilde kayıt edildi.", "OK");
                        await Navigation.PopAsync();
                    }
                    else
                    {
                        await DisplayAlert("HATA", responseModel.MSG, "OK");
                    }



                }
            }


        }

        private void gridGiris_SelectionChanged(object sender, DevExpress.XamarinForms.DataGrid.SelectionChangedEventArgs e)
        {

        }

        private void detayGrid_SelectionChanged(object sender, DevExpress.XamarinForms.DataGrid.SelectionChangedEventArgs e)
        {

        }

        private void FilterText_Completed(object sender, EventArgs e)
        {
            DetayIslemler();
        }
    }
}
Editor is loading...
Leave a Comment