예제 #1
0
        private async void BtnAdd_Click(object sender, RoutedEventArgs e)

        {
            if (!CheckEmpty())
            {
                return;
            }
            var havalehId = 0;

            #region AddHavaleh

            try
            {
                var addHavaleh = new DHavaleh
                {
                    DFactoryId      = ((tblFactory)CboFactory.SelectedItem).Id,
                    DCountyId       = ((tblCounty)CboCounty.SelectedItem).Id,
                    DBuyerId        = ((tblBuyer)CboBuyer.SelectedItem).Id,
                    DDriverId       = ((tblDriver)CboDriver.SelectedItem).Id,
                    DVehicleTypeId  = ((tblVehicleType)CboVehicle.SelectedItem).Id,
                    DDate           = TxtDate.Text.Trim() == string.Empty ? null : Utility.CurrectDate(TxtDate.Text),
                    DNumber         = TxtNumber.Text.Trim() == string.Empty ? null : TxtNumber.Text,
                    DHavlehNumber   = TxtHavlehNumber.Text.Trim() == string.Empty ? null : TxtHavlehNumber.Text,
                    DHavlehDate     = TxtHavlehDate.Text.Trim() == string.Empty ? null : Utility.CurrectDate(TxtHavlehDate.Text),
                    DHavalehEndDate = TxtHavalehEndDate.Text.Trim() == string.Empty ? null : Utility.CurrectDate(TxtHavalehEndDate.Text)
                };
                havalehId = Convert.ToInt32(await addHavaleh.Add());
            }
            catch (Exception exception)
            {
                Utility.MyMessageBox("خطا در بانک اطلاعاتی", "خطا در ثبت اطلاعات\n" + exception.Message);
            }

            foreach (var t in _createProduct)
            {
                try
                {
                    var addSelectProduct = new DSelectProduct
                    {
                        DHavalehId      = havalehId,
                        DProductId      = t.ProductId,
                        DCapacityId     = t.CapacityId,
                        DCapacityNumber = t.Num
                    };
                    await Task.Run(() => addSelectProduct.Add());
                }
                catch (Exception exception)
                {
                    Utility.MyMessageBox("خطا در بانک اطلاعاتی", "خطا در ثبت اطلاعات\n" + exception.Message);
                }
            }


            Window_Loaded(null, null);
            Utility.Message("پیام", "اطلاعات با موفقیت ثبت گردید", "Correct.png");

            #endregion
        }
예제 #2
0
        private async void BtnEdit_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckSelectEdit() || !CheckEmpty())
            {
                return;
            }
            var selectItem = _havalehSearchData[DgdHavaleh.SelectedIndex];

            try
            {
                var editHavaleh = new DHavaleh
                {
                    DId             = selectItem.Id,
                    DFactoryId      = ((tblFactory)CboFactory.SelectedItem).Id,
                    DCountyId       = ((tblCounty)CboCounty.SelectedItem).Id,
                    DBuyerId        = ((tblBuyer)CboBuyer.SelectedItem).Id,
                    DDriverId       = ((tblDriver)CboDriver.SelectedItem).Id,
                    DVehicleTypeId  = ((tblVehicleType)CboVehicle.SelectedItem).Id,
                    DDate           = TxtDate.Text.Trim() == string.Empty ? null : Utility.CurrectDate(TxtDate.Text),
                    DNumber         = TxtNumber.Text.Trim() == string.Empty ? null : TxtNumber.Text,
                    DHavlehNumber   = TxtHavlehNumber.Text.Trim() == string.Empty ? null : TxtHavlehNumber.Text,
                    DHavlehDate     = TxtHavlehDate.Text.Trim() == string.Empty ? null : Utility.CurrectDate(TxtHavlehDate.Text),
                    DHavalehEndDate = TxtHavalehEndDate.Text.Trim() == string.Empty ? null : Utility.CurrectDate(TxtHavalehEndDate.Text)
                };
                await Task.Run(() => editHavaleh.Edit());
            }
            catch (Exception exception)
            {
                Utility.MyMessageBox("خطا در بانک اطلاعاتی", "خطا در ویرایش اطلاعات پزشک\n" + exception.Message);
                return;
            }

            try
            {
                var deleteSelectProduct = new DSelectProduct
                {
                    DHavalehId = selectItem.Id
                };
                await Task.Run(() => deleteSelectProduct.Delete());
            }
            catch (Exception exception)
            {
                Utility.MyMessageBox("خطا در بانک اطلاعاتی", "خطا در حذف اطلاعات\n" + exception.Message);
                return;
            }

            foreach (var t in _createProduct)
            {
                try
                {
                    var addSelectProduct = new DSelectProduct
                    {
                        DHavalehId      = selectItem.Id,
                        DProductId      = t.ProductId,
                        DCapacityId     = t.CapacityId,
                        DCapacityNumber = t.Num
                    };
                    await Task.Run(() => addSelectProduct.Add());
                }
                catch (Exception exception)
                {
                    Utility.MyMessageBox("خطا در بانک اطلاعاتی", "خطا در ثبت اطلاعات\n" + exception.Message);
                }
            }

            Window_Loaded(null, null);
            Utility.Message("پیام", "اطلاعات با موفقیت ویرایش گردید", "Correct.png");
        }