public async Task <ReturnedSaveFuncInfo> ChangeStatusAsync(PeopleGroupBussines item, bool status, SqlTransaction tr)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var cmd = new SqlCommand("sp_PeopleGroup_ChangeStatus", tr.Connection, tr)
                {
                    CommandType = CommandType.StoredProcedure
                };
                cmd.Parameters.AddWithValue("@Guid", item.Guid);
                cmd.Parameters.AddWithValue("@st", status);

                await cmd.ExecuteNonQueryAsync();
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
Beispiel #2
0
        private async Task <ReturnedSaveFuncInfo> CheckValidationAsync()
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                if (string.IsNullOrWhiteSpace(Name))
                {
                    res.AddError("عنوان نمی تواند خالی باشد");
                }
                if (!await CheckNameAsync(Name.Trim(), Guid))
                {
                    res.AddError("عنوان وارد شده تکراری است");
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
Beispiel #3
0
        private void mnuDelete_Click(object sender, EventArgs e)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                if (DGrid.RowCount <= 0 || DGrid.CurrentRow == null)
                {
                    return;
                }
                if (MessageBox.Show("مایل به حذف سطر جاری هستید ؟", "هشدار", MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2, MessageBoxOptions.RightAlign) ==
                    DialogResult.No)
                {
                    return;
                }
                DGrid.Rows.RemoveAt(DGrid.CurrentRow.Index);
                DGrid.Focus();
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (res.HasError)
                {
                    this.ShowError(res, "خطا در حذف ریز پرداخت");
                }
                else
                {
                    FetchData();
                    SetLables();
                }
            }
        }
        public async Task <ReturnedSaveFuncInfo> SaveAsync(PeoplesBussines item, SqlTransaction tr)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var cmd = new SqlCommand("sp_Peoples_Save", tr.Connection, tr)
                {
                    CommandType = CommandType.StoredProcedure
                };
                cmd.Parameters.AddWithValue("@guid", item.Guid);
                cmd.Parameters.AddWithValue("@modif", item.Modified);
                cmd.Parameters.AddWithValue("@st", item.Status);
                cmd.Parameters.AddWithValue("@name", item.Name);
                cmd.Parameters.AddWithValue("@code", item.Code);
                cmd.Parameters.AddWithValue("@nCode", item.NationalCode ?? "");
                cmd.Parameters.AddWithValue("@idCode", item.IdCode ?? "");
                cmd.Parameters.AddWithValue("@fName", item.FatherName ?? "");
                cmd.Parameters.AddWithValue("@pBirth", item.PlaceBirth ?? "");
                cmd.Parameters.AddWithValue("@dBirth", item.DateBirth ?? "");
                cmd.Parameters.AddWithValue("@address", item.Address ?? "");
                cmd.Parameters.AddWithValue("@issued", item.IssuedFrom ?? "");
                cmd.Parameters.AddWithValue("@postalCode", item.PostalCode ?? "");
                cmd.Parameters.AddWithValue("@groupGuid", item.GroupGuid);
                cmd.Parameters.AddWithValue("@serverSt", (short)item.ServerStatus);
                cmd.Parameters.AddWithValue("@serverDate", item.ServerDeliveryDate);

                await cmd.ExecuteNonQueryAsync();
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
Beispiel #5
0
        public async Task <ReturnedSaveFuncInfo> SaveAsync(PardakhtBussines item, SqlTransaction tr)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var cmd = new SqlCommand("sp_Pardakht_Save", tr.Connection, tr)
                {
                    CommandType = CommandType.StoredProcedure
                };
                cmd.Parameters.AddWithValue("@guid", item.Guid);
                cmd.Parameters.AddWithValue("@modif", item.Modified);
                cmd.Parameters.AddWithValue("@dateM", item.DateM);
                cmd.Parameters.AddWithValue("@desc", item.Description ?? "");
                cmd.Parameters.AddWithValue("@number", item.Number);
                cmd.Parameters.AddWithValue("@tafsilGuid", item.TafsilGuid);
                cmd.Parameters.AddWithValue("@userGuid", item.UserGuid);
                cmd.Parameters.AddWithValue("@moeinGuid", ParentDefaults.MoeinCoding.CLSMoein10304);
                cmd.Parameters.AddWithValue("@sanadNumber", item.SanadNumber);
                cmd.Parameters.AddWithValue("@serverSt", (short)item.ServerStatus);
                cmd.Parameters.AddWithValue("@serverDate", item.ServerDeliveryDate);
                cmd.Parameters.AddWithValue("@sumCheckM", item.SumCheckMoshtari);
                cmd.Parameters.AddWithValue("@sumCheckSh", item.SumCheckShakhsi);
                cmd.Parameters.AddWithValue("@sumHavale", item.SumHavale);
                cmd.Parameters.AddWithValue("@sumNaqd", item.SumNaqd);
                cmd.Parameters.AddWithValue("@sum", item.Sum);

                await cmd.ExecuteNonQueryAsync();
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
        public async Task <ReturnedSaveFuncInfo> SaveAsync(SerializedDataBussines item, SqlTransaction tr)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var cmd = new SqlCommand("sp_SerializedData_Save", tr.Connection, tr)
                {
                    CommandType = CommandType.StoredProcedure
                };
                cmd.Parameters.AddWithValue("@guid", item.Guid);
                cmd.Parameters.AddWithValue("@name", item.Name ?? "");
                cmd.Parameters.AddWithValue("@data", item.Data ?? "");

                await cmd.ExecuteNonQueryAsync();
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
Beispiel #7
0
        public async Task <ReturnedSaveFuncInfo> SaveAsync(NaqzBussines item, SqlTransaction tr)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var cmd = new SqlCommand("sp_Naqz_Save", tr.Connection, tr)
                {
                    CommandType = CommandType.StoredProcedure
                };
                cmd.Parameters.AddWithValue("@guid", item.Guid);
                cmd.Parameters.AddWithValue("@message", item.Message ?? "");
                cmd.Parameters.AddWithValue("@useCount", item.UseCount);

                await cmd.ExecuteNonQueryAsync();
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
Beispiel #8
0
        public static async Task <ReturnedSaveFuncInfo> SaveAsync(PardakhtBussines cls)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var obj = new WebPardakht()
                {
                    Guid               = cls.Guid,
                    Modified           = cls.Modified,
                    HardSerial         = cls.HardSerial,
                    ServerStatus       = cls.ServerStatus,
                    ServerDeliveryDate = cls.ServerDeliveryDate,
                    Description        = cls.Description,
                    DateM              = cls.DateM,
                    Number             = cls.Number,
                    UserGuid           = cls.UserGuid,
                    SanadNumber        = cls.SanadNumber,
                    TafsilGuid         = cls.TafsilGuid,
                    MoeinGuid          = cls.MoeinGuid,
                    SumHavale          = cls.SumHavale,
                    SumNaqd            = cls.SumNaqd,
                    SumCheckMoshtari   = cls.SumCheckMoshtari,
                    Sum             = cls.Sum,
                    SumCheckShakhsi = cls.SumCheckShakhsi
                };
                await obj.SaveAsync();
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
Beispiel #9
0
        public async Task <ReturnedSaveFuncInfo> SaveAsync(TempBussines item, SqlTransaction tr)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var cmd = new SqlCommand("sp_Temp_Save", tr.Connection, tr)
                {
                    CommandType = CommandType.StoredProcedure
                };
                cmd.Parameters.AddWithValue("@guid", item.Guid);
                cmd.Parameters.AddWithValue("@type", (short)item.Type);
                cmd.Parameters.AddWithValue("@objGuid", item.ObjectGuid);

                await cmd.ExecuteNonQueryAsync();
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
Beispiel #10
0
        public async Task <ReturnedSaveFuncInfo> ChangeStatusAsync(bool status, SqlTransaction tr = null)
        {
            var           res      = new ReturnedSaveFuncInfo();
            var           autoTran = tr == null;
            SqlConnection cn       = null;

            try
            {
                if (autoTran)
                {
                    cn = new SqlConnection(Cache.ConnectionString);
                    await cn.OpenAsync();

                    tr = cn.BeginTransaction();
                }

                var tafsil = await TafsilBussines.GetAsync(Guid);

                if (tafsil == null)
                {
                    res.AddError("شخص انتخاب شده معتبر نمی باشد");
                    return(res);
                }

                res.AddReturnedValue(await tafsil.ChangeStatusAsync(status, tr));
                if (res.HasError)
                {
                    return(res);
                }
                res.AddReturnedValue(await PhoneBookBussines.ChangeStatusAsync(Guid, status, tr));
                if (res.HasError)
                {
                    return(res);
                }
                res.AddReturnedValue(await UnitOfWork.Peoples.ChangeStatusAsync(this, status, tr));
                if (res.HasError)
                {
                    return(res);
                }

                var action = status ? EnLogAction.Enable : EnLogAction.Delete;
                res.AddReturnedValue(await UserLogBussines.SaveAsync(action, EnLogPart.Peoples, tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (Cache.IsSendToServer)
                {
                    _ = Task.Run(() => WebPeople.SaveAsync(this));
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (autoTran)
                {
                    res.AddReturnedValue(tr.TransactionDestiny(res.HasError));
                    res.AddReturnedValue(cn.CloseConnection());
                }
            }
            return(res);
        }
        private async void mnuDelete_Click(object sender, EventArgs e)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                if (DGrid.RowCount <= 0)
                {
                    return;
                }
                if (DGrid.CurrentRow == null)
                {
                    return;
                }
                var guid   = (Guid)DGrid[dgGuid.Index, DGrid.CurrentRow.Index].Value;
                var tafsil = await TafsilBussines.GetAsync(guid);

                if (tafsil == null)
                {
                    res.AddError("حساب انتخاب شده معتبر نمی باشد");
                    return;
                }

                if (_st)
                {
                    if (tafsil.isSystem)
                    {
                        res.AddError("شما مجاز به حذف حساب های پیش فرض نمی باشید");
                        return;
                    }
                    if (tafsil.Account != 0)
                    {
                        res.AddError(
                            $"حساب {DGrid[dgName.Index, DGrid.CurrentRow.Index].Value} به علت داشتن گردش، قادر به حذف نمی باشد");
                        return;
                    }
                    if (MessageBox.Show(this,
                                        $@"آیا از حذف {DGrid[dgName.Index, DGrid.CurrentRow.Index].Value} اطمینان دارید؟", "حذف",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    if (tafsil.HesabType == HesabType.Customer)
                    {
                        var cus = await PeoplesBussines.GetAsync(tafsil.Guid);

                        if (cus == null)
                        {
                            return;
                        }
                        res.AddReturnedValue(await cus.ChangeStatusAsync(false));
                        return;
                    }
                    if (tafsil.HesabType == HesabType.Bank)
                    {
                        var bank = await BankBussines.GetAsync(tafsil.Guid);

                        res.AddReturnedValue(await bank.ChangeStatusAsync(false));
                        return;
                    }

                    res.AddReturnedValue(await tafsil.ChangeStatusAsync(false));
                }
                else
                {
                    if (MessageBox.Show(this,
                                        $@"آیا از فعال کردن {DGrid[dgName.Index, DGrid.CurrentRow.Index].Value} اطمینان دارید؟",
                                        "حذف",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    if (tafsil.HesabType == HesabType.Customer)
                    {
                        var cus = await PeoplesBussines.GetAsync(tafsil.Guid);

                        if (cus.GroupGuid == Guid.Empty)
                        {
                            var frm = new frmChangeGroup(cus);
                            if (frm.ShowDialog(this) != DialogResult.OK)
                            {
                                return;
                            }
                        }
                        res.AddReturnedValue(await cus.ChangeStatusAsync(true));
                        return;
                    }
                    if (tafsil.HesabType == HesabType.Bank)
                    {
                        var bank = await BankBussines.GetAsync(tafsil.Guid);

                        res.AddReturnedValue(await bank.ChangeStatusAsync(true));
                        return;
                    }

                    res.AddReturnedValue(await tafsil.ChangeStatusAsync(true));
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (res.HasError)
                {
                    this.ShowError(res, "خطا در تغییر وضعیت حساب تفصیلی");
                }
                else
                {
                    await LoadDataAsync(txtSearch.Text);
                }
            }
        }
        private void btnFinish_Click(object sender, EventArgs e)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                if (cls.Guid == Guid.Empty)
                {
                    cls.Guid  = Guid.NewGuid();
                    cls.DateM = DateTime.Now;
                }

                if (txtPrice.TextDecimal <= 0)
                {
                    res.AddError("لطفا مبلغ را وارد نمایید");
                }
                if (string.IsNullOrEmpty(txtDate.Text))
                {
                    res.AddError("لطفا تاریخ سررسید چک را وارد نمایید");
                }
                if (string.IsNullOrEmpty(txtBankName.Text))
                {
                    res.AddError("لطفا بانک صادر کننده چک را وارد نمایید");
                }
                if (string.IsNullOrEmpty(txtCheckNo.Text))
                {
                    res.AddError("لطفا شماره چک را وارد نمایید");
                }
                if (SandouqBindingSource.Count <= 0)
                {
                    res.AddError("لطفا صندوق مقصد را انتخاب نمایید");
                }

                cls.Modified          = DateTime.Now;
                cls.BankName          = txtBankName.Text;
                cls.DateSarResid      = Calendar.ShamsiToMiladi(txtDate.Text);
                cls.Description       = txtDesc.Text;
                cls.CheckNumber       = txtCheckNo.Text;
                cls.PoshtNomre        = txtPoshtNomre.Text;
                cls.Price             = txtPrice.TextDecimal;
                cls.CheckStatus       = EnCheckM.Mojoud;
                cls.SandouqTafsilGuid = (Guid)cmbSandouq.SelectedValue;
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (res.HasError)
                {
                    this.ShowError(res, "خطا در ثبت دریافت حواله");
                }
                else
                {
                    DialogResult = DialogResult.OK;
                    Close();
                }
            }
        }
Beispiel #13
0
        public async Task <ReturnedSaveFuncInfo> SaveAsync(bool isUpdateAccount, SqlTransaction tr = null)
        {
            var           res      = new ReturnedSaveFuncInfo();
            var           autoTran = tr == null;
            SqlConnection cn       = null;

            try
            {
                if (autoTran)
                {
                    cn = new SqlConnection(Cache.ConnectionString);
                    await cn.OpenAsync();

                    tr = cn.BeginTransaction();
                }

                res.AddReturnedValue(CheckValidation());
                if (res.HasError)
                {
                    return(res);
                }

                if (isUpdateAccount)
                {
                    var oldSanad = await GetAsync(Guid);

                    if (oldSanad != null)
                    {
                        res.AddReturnedValue(await UpdateAccountsAsync(oldSanad, true, tr));
                        if (res.HasError)
                        {
                            return(res);
                        }
                    }
                }

                res.AddReturnedValue(await UnitOfWork.ReceptionCheckAvalDore.SaveAsync(this, tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (isUpdateAccount)
                {
                    res.AddReturnedValue(await UpdateAccountsAsync(this, false, tr));
                    if (res.HasError)
                    {
                        return(res);
                    }
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (autoTran)
                {
                    res.AddReturnedValue(tr.TransactionDestiny(res.HasError));
                    res.AddReturnedValue(cn.CloseConnection());
                }
            }
            return(res);
        }
        private async void mnuDelete_Click(object sender, EventArgs e)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                if (DGrid.RowCount <= 0)
                {
                    return;
                }
                if (DGrid.CurrentRow == null)
                {
                    return;
                }
                var guid = (Guid)DGrid[dgGuid.Index, DGrid.CurrentRow.Index].Value;
                if (_st)
                {
                    if (MessageBox.Show(this,
                                        $@"آیا از حذف {DGrid[dgName.Index, DGrid.CurrentRow.Index].Value} اطمینان دارید؟", "حذف",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    var prd = await RentalAuthorityBussines.GetAsync(guid);

                    res.AddReturnedValue(await prd.ChangeStatusAsync(false));
                }
                else
                {
                    if (MessageBox.Show(this,
                                        $@"آیا از فعال کردن {DGrid[dgName.Index, DGrid.CurrentRow.Index].Value} اطمینان دارید؟",
                                        "حذف",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    var prd = await RentalAuthorityBussines.GetAsync(guid);

                    res.AddReturnedValue(await prd.ChangeStatusAsync(true));
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (res.HasError)
                {
                    var frm = new FrmShowErrorMessage(res, "خطا در تغییر وضعیت ارجحیت اجاره");
                    frm.ShowDialog(this);
                    frm.Dispose();
                }
                else
                {
                    await LoadDataAsync(txtSearch.Text);
                }
            }
        }
        public async Task <ReturnedSaveFuncInfo> SendAsync(long number)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                res.AddReturnedValue(await Utility.Init(number));
                if (res.HasError)
                {
                    return(res);
                }
                await Utility.Wait(2);

                var cat = new FixElements(Utility.RefreshDriver(clsAdvertise.IsSilent));
                cat.FirsCategory(FisrtCat)?.Click();
                await Utility.Wait();

                cat.SecondCategory(SecondCat)?.Click();
                await Utility.Wait();

                cat.ThirdCategory(ThirdCat)?.Click();
                await Utility.Wait(2);

                if (!string.IsNullOrEmpty(ImageList) && ImageList.Length >= 5)
                {
                    cat.ImageContainer()?.SendKeys(ImageList);
                }
                cat.CitySearcher()?.Click();
                await Utility.Wait();

                cat.City()?.SendKeys(City + "\n");
                await Utility.Wait(2);

                cat.RegionSearcher()?.Click();
                await Utility.Wait();

                cat.Region()?.SendKeys(Region + "\n");

                cat.Masahat()?.SendKeys(Metrazh);

                if (agahiDahande.Contains("املاک"))
                {
                    cat.Sender_Amlak()?.Click();
                }
                else
                {
                    cat.Sender_Shakhsi()?.Click();
                }

                cat.Sell()?.SendKeys(Price);

                await Utility.Wait();

                cat.RoomCount()?.Click();
                await Utility.Wait();

                cat.SelectDropDown(RoomCount);

                await Utility.Wait();

                cat.SaleSakht()?.Click();
                await Utility.Wait();

                cat.SelectDropDown(SaleSakht);

                await Utility.Wait();

                cat.Tabaqe()?.Click();
                await Utility.Wait();

                cat.SelectDropDown(Tabaqe);

                await Utility.Wait();

                cat.Asansor()?.Click();
                await Utility.Wait();

                cat.SelectDropDown(Asansor);

                await Utility.Wait();

                cat.Parking()?.Click();
                await Utility.Wait();

                cat.SelectDropDown(Parking);

                await Utility.Wait();

                cat.Anbari()?.Click();
                await Utility.Wait();

                cat.SelectDropDown(Anbari);

                await Utility.Wait();

                if (!isGiveChat)
                {
                    cat.Chat()?.Click();
                }

                cat.Title()?.SendKeys(Title);
                cat.SendContent(Description);

                await Utility.Wait();

                cat.SendAdv();

                res.AddReturnedValue(await Utility.SaveAdv(AdvertiseType.Divar, FisrtCat, SecondCat, ThirdCat, State,
                                                           City,
                                                           Region, Title, Description, number, bu.SellPrice, 0, cat.Url));
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
        public async Task <ReturnedSaveFuncInfo> SaveAsync(SqlTransaction tr = null)
        {
            var           res      = new ReturnedSaveFuncInfo();
            var           autoTran = tr == null;
            SqlConnection cn       = null;

            try
            {
                if (autoTran)
                {
                    cn = new SqlConnection(Cache.ConnectionString);
                    await cn.OpenAsync();

                    tr = cn.BeginTransaction();
                }

                res.AddReturnedValue(await CheckValidationAsync());
                if (res.HasError)
                {
                    return(res);
                }

                if (OptionList.Count > 0)
                {
                    res.AddReturnedValue(await BuildingRelatedOptionsBussines.RemoveRangeAsync(Guid, tr));
                    if (res.HasError)
                    {
                        return(res);
                    }

                    foreach (var item in OptionList)
                    {
                        item.BuildinGuid = Guid;
                    }
                    res.AddReturnedValue(await BuildingRelatedOptionsBussines.SaveRangeAsync(OptionList, tr));
                    if (res.HasError)
                    {
                        return(res);
                    }
                }
                if (GalleryList.Count > 0)
                {
                    res.AddReturnedValue(await BuildingGalleryBussines.RemoveRangeAsync(Guid, tr));
                    if (res.HasError)
                    {
                        return(res);
                    }

                    foreach (var item in GalleryList)
                    {
                        item.BuildingGuid = Guid;
                    }

                    res.AddReturnedValue(await BuildingGalleryBussines.SaveRangeAsync(GalleryList, tr));
                    if (res.HasError)
                    {
                        return(res);
                    }
                }


                res.AddReturnedValue(await UnitOfWork.Building.SaveAsync(this, tr));
                if (res.HasError)
                {
                    return(res);
                }

                var action = IsModified ? EnLogAction.Update : EnLogAction.Insert;
                res.AddReturnedValue(await UserLogBussines.SaveAsync(action, EnLogPart.Building, tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (Cache.IsSendToServer)
                {
                    _ = Task.Run(() => WebBuilding.SaveAsync(this, Cache.Path));
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (autoTran)
                {
                    res.AddReturnedValue(tr.TransactionDestiny(res.HasError));
                    res.AddReturnedValue(cn.CloseConnection());
                }
            }
            return(res);
        }
Beispiel #17
0
        //private static async Task<ReturnedSaveFuncInfo> SendChat_(long number, Guid visitorGuid)
        //{
        //    var res = new ReturnedSaveFuncInfo();
        //    try
        //    {
        //        AdvDepartmentBusiness dep;
        //        if (visitorGuid == Guid.Empty)
        //            dep = await AdvDepartmentBusiness.GetAsync("نوین پرداز");
        //        else
        //        {
        //            var visitor = await VisitorBusiness.GetAsync(visitorGuid);
        //            dep = await AdvDepartmentBusiness.GetAsync(visitor?.DepartmentGuid ?? Guid.Empty);
        //        }

        //        if (dep == null)
        //        {
        //            res.AddReturnedValue(ReturnedState.Error, "Department is Null");
        //            return res;
        //        }

        //        if (!dep.IsSendChat)
        //        {
        //            res.AddReturnedValue(ReturnedState.Error, "Dont Permition Send Chat");
        //            return res;
        //        }
        //        var list = new List<string>();
        //        if (!string.IsNullOrEmpty(dep.ChatList.Desc1)) list.Add(dep.ChatList.Desc1);
        //        if (!string.IsNullOrEmpty(dep.ChatList.Desc2)) list.Add(dep.ChatList.Desc2);
        //        if (!string.IsNullOrEmpty(dep.ChatList.Desc3)) list.Add(dep.ChatList.Desc3);
        //        if (!string.IsNullOrEmpty(dep.ChatList.Desc4)) list.Add(dep.ChatList.Desc4);
        //        if (!string.IsNullOrEmpty(dep.ChatList.Desc5)) list.Add(dep.ChatList.Desc5);
        //        if (!string.IsNullOrEmpty(dep.ChatList.Desc6)) list.Add(dep.ChatList.Desc6);
        //        if (!string.IsNullOrEmpty(dep.ChatList.Desc7)) list.Add(dep.ChatList.Desc7);
        //        if (!string.IsNullOrEmpty(dep.ChatList.Desc8)) list.Add(dep.ChatList.Desc8);
        //        if (!string.IsNullOrEmpty(dep.ChatList.Desc9)) list.Add(dep.ChatList.Desc9);
        //        if (!string.IsNullOrEmpty(dep.ChatList.Desc10)) list.Add(dep.ChatList.Desc10);

        //        var cityList = new List<string>();
        //        if (!string.IsNullOrEmpty(dep.ChatCity.City1)) cityList.Add(dep.ChatCity.City1);
        //        if (!string.IsNullOrEmpty(dep.ChatCity.City2)) cityList.Add(dep.ChatCity.City2);
        //        if (!string.IsNullOrEmpty(dep.ChatCity.City3)) cityList.Add(dep.ChatCity.City3);
        //        if (!string.IsNullOrEmpty(dep.ChatCity.City4)) cityList.Add(dep.ChatCity.City4);
        //        if (!string.IsNullOrEmpty(dep.ChatCity.City5)) cityList.Add(dep.ChatCity.City5);
        //        if (!string.IsNullOrEmpty(dep.ChatCity.City6)) cityList.Add(dep.ChatCity.City6);
        //        if (!string.IsNullOrEmpty(dep.ChatCity.City7)) cityList.Add(dep.ChatCity.City7);
        //        if (!string.IsNullOrEmpty(dep.ChatCity.City8)) cityList.Add(dep.ChatCity.City8);
        //        if (!string.IsNullOrEmpty(dep.ChatCity.City9)) cityList.Add(dep.ChatCity.City9);
        //        if (!string.IsNullOrEmpty(dep.ChatCity.City10)) cityList.Add(dep.ChatCity.City10);
        //        var rand = new Random().Next(0, cityList.Count);
        //        var catList = await DepartmentCategoryBusiness.GetAllAsync(dep.Guid);
        //        var rnd = new Random().Next(0, catList.ToList().Count);
        //        var d = DivarAdv.GetInstance();
        //        await d.SendChat(number, list, dep.ChatCount, cityList[rand], catList[rnd].FirstLevel,
        //            catList[rnd].SecondLevel,
        //            catList[rnd].ThirdLevel, false);
        //    }
        //    catch (Exception ex)
        //    {
        //        WebErrorLog.ErrorLogInstance.StartLog(ex);
        //        res.AddReturnedValue(ex);
        //    }

        //    return res;
        //}
        #endregion


        private static async Task <ReturnedSaveFuncInfo> SendDivarAdv(BuildingBussines bu, long simCardNumber, bool isGiveChat, string sender, int imageCount)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var accType = await BuildingAccountTypeBussines.GetAsync(bu.BuildingAccountTypeGuid);

                if (accType == null)
                {
                    res.AddError("کاربری ملک معتبر نمی باشد");
                    return(res);
                }

                if (bu.RahnPrice1 > 0 || bu.RahnPrice2 > 0 || bu.EjarePrice1 > 0 || bu.EjarePrice2 > 0)
                {
                    if (accType.Name.Contains("مسکونی") && !accType.Name.Contains("زمین"))
                    {
                        var type = await BuildingTypeBussines.GetAsync(bu.BuildingTypeGuid);

                        if (type == null)
                        {
                            res.AddError("نوع ملک معتبر نمی باشد");
                            return(res);
                        }
                        if (type.Name.Contains("پارتمان"))
                        {
                            var ret = new Divar_ResidentialApartmentRent(bu, imageCount, isGiveChat, sender);
                            res.AddReturnedValue(await ret.SendAsync(simCardNumber));
                            return(res);
                        }
                        if (type.Name.Contains("خانه") || accType.Name.Contains("ویلا"))
                        {
                            var ret = new Divar_ResidentialVillaRent(bu, imageCount, isGiveChat, sender);
                            res.AddReturnedValue(await ret.SendAsync(simCardNumber));
                            return(res);
                        }
                    }
                    if (accType.Name.Contains("دفتر") || accType.Name.Contains("اداری") || accType.Name.Contains("مطب"))
                    {
                        var ret = new Divar_OfficeOfficeRent(bu, imageCount, isGiveChat, sender);
                        res.AddReturnedValue(await ret.SendAsync(simCardNumber));
                        return(res);
                    }
                    if (accType.Name.Contains("صنعتی") || accType.Name.Contains("کشاورزی") ||
                        accType.Name.Contains("دامداری") || accType.Name.Contains("مرغداری") ||
                        accType.Name.Contains("زراعی"))
                    {
                        var ret = new Divar_OfficeKeshavarziRent(bu, imageCount, isGiveChat, sender);
                        res.AddReturnedValue(await ret.SendAsync(simCardNumber));
                        return(res);
                    }
                    if (accType.Name.Contains("مغازه") || accType.Name.Contains("غرفه") || accType.Name.Contains("تجاری"))
                    {
                        var ret = new Divar_OfficeStoreRent(bu, imageCount, isGiveChat, sender);
                        res.AddReturnedValue(await ret.SendAsync(simCardNumber));
                        return(res);
                    }
                }

                else if (bu.SellPrice > 0)
                {
                    if (accType.Name.Contains("مسکونی"))
                    {
                        var type = await BuildingTypeBussines.GetAsync(bu.BuildingTypeGuid);

                        if (type == null)
                        {
                            res.AddError("نوع ملک معتبر نمی باشد");
                            return(res);
                        }
                        if (type.Name.Contains("پارتمان"))
                        {
                            var ret = new Divar_ResidentialApartmentSell(bu, imageCount, isGiveChat, sender);
                            res.AddReturnedValue(await ret.SendAsync(simCardNumber));
                            return(res);
                        }
                        if (type.Name.Contains("خانه") || accType.Name.Contains("ویلا"))
                        {
                            var ret = new Divar_ResidentialVillaSell(bu, imageCount, isGiveChat, sender);
                            res.AddReturnedValue(await ret.SendAsync(simCardNumber));
                            return(res);
                        }
                        if (type.Name.Contains("زمین") || type.Name.Contains("کلنگی"))
                        {
                            var ret = new Divar_ResidentialZaminSell(bu, imageCount, isGiveChat, sender);
                            res.AddReturnedValue(await ret.SendAsync(simCardNumber));
                            return(res);
                        }
                    }
                    if (accType.Name.Contains("زمین") || accType.Name.Contains("کلنگی"))
                    {
                        var ret = new Divar_ResidentialZaminSell(bu, imageCount, isGiveChat, sender);
                        res.AddReturnedValue(await ret.SendAsync(simCardNumber));
                        return(res);
                    }
                    if (accType.Name.Contains("دفتر") || accType.Name.Contains("اداری") || accType.Name.Contains("مطب"))
                    {
                        var ret = new Divar_OfficeOfficeSell(bu, imageCount, isGiveChat, sender);
                        res.AddReturnedValue(await ret.SendAsync(simCardNumber));
                        return(res);
                    }
                    if (accType.Name.Contains("صنعتی") || accType.Name.Contains("کشاورزی") ||
                        accType.Name.Contains("دامداری") || accType.Name.Contains("مرغداری") ||
                        accType.Name.Contains("زراعی"))
                    {
                        var ret = new Divar_OfficeKeshavarziSell(bu, imageCount, isGiveChat, sender);
                        res.AddReturnedValue(await ret.SendAsync(simCardNumber));
                        return(res);
                    }
                    if (accType.Name.Contains("مغازه") || accType.Name.Contains("غرفه") || accType.Name.Contains("تجاری"))
                    {
                        var ret = new Divar_OfficeStoreSell(bu, imageCount, isGiveChat, sender);
                        res.AddReturnedValue(await ret.SendAsync(simCardNumber));
                        return(res);
                    }
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
        private async void btnFinish_Click(object sender, EventArgs e)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var isSendSms = false;
                if (cls.Guid == Guid.Empty)
                {
                    cls.Guid  = Guid.NewGuid();
                    isSendSms = true;
                }

                cls.AskerGuid = asker?.Guid ?? Guid.Empty;
                cls.UserGuid  = (Guid)cmbUser.SelectedValue;
                cls.Modified  = DateTime.Now;

                cls.SellPrice1  = txtSellPrice1.TextDecimal;
                cls.SellPrice2  = txtSellPrice2.TextDecimal;
                cls.RahnPrice1  = txtRahn1.TextDecimal;
                cls.RahnPrice2  = txtRahn2.TextDecimal;
                cls.EjarePrice1 = txtEjare1.TextDecimal;
                cls.EjarePrice2 = txtEjare2.TextDecimal;

                cls.HasVam                  = chbHasVam.Checked;
                cls.PeopleCount             = txtPeopleCount.Text.ParseToShort();
                cls.HasOwner                = chbHasOwner.Checked;
                cls.ShortDate               = chbShortDate.Checked;
                cls.RentalAutorityGuid      = (Guid?)cmbRentalAuthority.SelectedValue ?? Guid.Empty;
                cls.CityGuid                = (Guid)cmbCity.SelectedValue;
                cls.BuildingTypeGuid        = (Guid)cmbBuildingType.SelectedValue;
                cls.Masahat1                = txtMasahat1.Text.ParseToInt();
                cls.Masahat2                = txtMasahat2.Text.ParseToInt();
                cls.RoomCount               = txtRoomCount.Text.ParseToInt();
                cls.BuildingAccountTypeGuid = (Guid)cmbBuildingAccountType.SelectedValue;
                cls.BuildingConditionGuid   = (Guid)cmbBuildingCondition.SelectedValue;
                cls.ShortDesc               = txtDesc.Text;

                await SetRegionsAsync(cls.Guid);

                res.AddReturnedValue(await cls.SaveAsync());

                if (res.HasError)
                {
                    return;
                }

                if (Settings.Classes.Payamak.IsSendToSayer.ParseToBoolean() && isSendSms)
                {
                    _ = Task.Run(() => Payamak.FixSms.RequestSend.SendAsync(cls));
                }

                if (MessageBox.Show("آیا مایلید املاک مطابق با این تقاضا را مشاهده نمایید؟", "تطبیق املاک با تقاضا",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                {
                    return;
                }

                var list = new List <BuildingViewModel>();

                decimal       fPrice1, fPrice2, sPrice1, sPrice2;
                EnRequestType type;

                if (cls.SellPrice1 > 0 || cls.SellPrice2 > 0)
                {
                    type    = EnRequestType.Forush;
                    fPrice1 = cls.SellPrice1;
                    fPrice2 = cls.SellPrice2;
                    sPrice1 = sPrice2 = 0;
                }
                else
                {
                    type    = EnRequestType.Rahn;
                    fPrice1 = cls.RahnPrice1;
                    fPrice2 = cls.RahnPrice2;
                    sPrice1 = cls.EjarePrice1;
                    sPrice2 = cls.EjarePrice2;
                }

                _token?.Cancel();
                _token = new CancellationTokenSource();
                list.AddRange(await BuildingBussines.GetAllAsync(null, _token.Token, Guid.Empty,
                                                                 cls.BuildingAccountTypeGuid, cls.Masahat1,
                                                                 cls.Masahat2, cls.RoomCount, fPrice1,
                                                                 sPrice1, fPrice2,
                                                                 sPrice2, type, cls.RegionList?.Select(q => q.RegionGuid).ToList()));

                if (list.Count <= 0)
                {
                    MessageBox.Show("متاسفانه در حال حاضر، ملکی مطابق با این تقاضا وجود ندارد");
                    return;
                }

                var frm = new frmBuildingAdvanceSearch(list);
                frm.ShowDialog(this);
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (res.HasError)
                {
                    var frm = new FrmShowErrorMessage(res, "خطا در ثبت تقاضا");
                    frm.ShowDialog(this);
                    frm.Dispose();
                }
                else
                {
                    DialogResult = DialogResult.OK;
                    Close();
                }
            }
        }
Beispiel #19
0
        public static async Task InsertDefaultDataAsync()
        {
            var            res = new ReturnedSaveFuncInfo();
            SqlTransaction tr  = null;
            SqlConnection  cn  = null;

            try
            {
                cn = new SqlConnection(Cache.ConnectionString);
                await cn.OpenAsync();

                tr = cn.BeginTransaction();

                #region Kol
                var allKol = await KolBussines.GetAllAsync(new CancellationToken());

                if (allKol == null || allKol.Count <= 0)
                {
                    var kol = DefaultKol.SetDef();
                    res.AddReturnedValue(await KolBussines.SaveRangeAsync(kol, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region Moein
                var allMoein = await MoeinBussines.GetAllAsync(new CancellationToken());

                if (allMoein == null || allMoein.Count <= 0)
                {
                    var moein = DefaultMoein.SetDef();
                    res.AddReturnedValue(await MoeinBussines.SaveRangeAsync(moein, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region Tafsil
                var allTafsil = await TafsilBussines.GetAllAsync(new CancellationToken());

                if (allTafsil == null || allTafsil.Count <= 0)
                {
                    var tafsil = DefaultTafsil.SetDef();
                    res.AddReturnedValue(await TafsilBussines.SaveRangeAsync(tafsil, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region Bank
                var allBank = await BankBussines.GetAllAsync(new CancellationToken());

                if (allBank == null || allBank.Count <= 0)
                {
                    var user = new BankBussines()
                    {
                        Guid = ParentDefaults.TafsilCoding.CLSTafsil1010101,
                        Name = "حساب بانکی مرکزی",
                        Code = "1010101",
                    };
                    res.AddReturnedValue(await user.SaveAsync(tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region Bank Segest
                var allbs = await BankSegestBussines.GetAllAsync();

                if (allbs == null || allbs.Count <= 0)
                {
                    var bs = DefaultBankSegest.SetDef();
                    res.AddReturnedValue(await BankSegestBussines.SaveRangeAsync(bs, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region Users
                var allusers = await UserBussines.GetAllAsync(new CancellationToken());

                var access = new AccessLevel();
                if (allusers == null || allusers.Count <= 0)
                {
                    var user = new UserBussines()
                    {
                        Guid             = ParentDefaults.TafsilCoding.CLSTafsil1030401,
                        Name             = "کاربر پیش فرض",
                        UserName         = "******",
                        SecurityQuestion = 0,
                        Access           = Json.ToStringJson(access)
                    };
                    var ue        = new UTF8Encoding();
                    var bytes     = ue.GetBytes("2211");
                    var md5       = new MD5CryptoServiceProvider();
                    var hashBytes = md5.ComputeHash(bytes);
                    user.Password = System.Text.RegularExpressions.Regex.Replace(BitConverter.ToString(hashBytes), "-", "")
                                    .ToLower();
                    res.AddReturnedValue(await user.SaveAsync(tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region States
                var allStates = await StatesBussines.GetAllAsync(new CancellationToken());

                if (allStates == null || allStates.Count <= 0)
                {
                    var states = DefaultStates.SetDef();
                    res.AddReturnedValue(await StatesBussines.SaveRangeAsync(states, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region Cities
                var allCities = await CitiesBussines.GetAllAsync(new CancellationToken());

                if (allCities == null || allCities.Count <= 0)
                {
                    var city = DefaultCities.SetDef();
                    res.AddReturnedValue(await CitiesBussines.SaveRangeAsync(city, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region Regions
                var allRegions = await RegionsBussines.GetAllAsync(new CancellationToken());

                if (allRegions == null || allRegions.Count <= 0)
                {
                    var reg = DefaultRegions.SetDef();
                    res.AddReturnedValue(await RegionsBussines.SaveRangeAsync(reg, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region Naqz
                var allNaqz = await NaqzBussines.GetAllAsync();

                if (allNaqz == null || allNaqz.Count <= 0)
                {
                    var naqz = DefaultNaqz.SetDef();
                    res.AddReturnedValue(await NaqzBussines.SaveRangeAsync(naqz, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region BuildingOption
                var allbo = await BuildingOptionsBussines.GetAllAsync(new CancellationToken());

                if (allbo == null || allbo.Count <= 0)
                {
                    var bo = DefaultBuildingOptions.SetDef();
                    res.AddReturnedValue(await BuildingOptionsBussines.SaveRangeAsync(bo, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region BuildingAccountType
                var allbat = await BuildingAccountTypeBussines.GetAllAsync(new CancellationToken());

                if (allbat == null || allbat.Count <= 0)
                {
                    var bat = DefaultBuildingAccountType.SetDef();
                    res.AddReturnedValue(await BuildingAccountTypeBussines.SaveRangeAsync(bat, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region FloorCover
                var allfc = await FloorCoverBussines.GetAllAsync(new CancellationToken());

                if (allfc == null || allfc.Count <= 0)
                {
                    var fc = DefaultFloorCover.SetDef();
                    res.AddReturnedValue(await FloorCoverBussines.SaveRangeAsync(fc, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region KitchenService
                var allks = await KitchenServiceBussines.GetAllAsync(new CancellationToken());

                if (allks == null || allks.Count <= 0)
                {
                    var ks = DefaultKitchenService.SetDef();
                    res.AddReturnedValue(await KitchenServiceBussines.SaveRangeAsync(ks, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region DocumentType
                var alldt = await DocumentTypeBussines.GetAllAsync(new CancellationToken());

                if (alldt == null || alldt.Count <= 0)
                {
                    var dt = DefaultDocumentType.SetDef();
                    res.AddReturnedValue(await DocumentTypeBussines.SaveRangeAsync(dt, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region RentalAuthority
                var allra = await RentalAuthorityBussines.GetAllAsync(new CancellationToken());

                if (allra == null || allra.Count <= 0)
                {
                    var ra = DefaultRentalAuthority.SetDef();
                    res.AddReturnedValue(await RentalAuthorityBussines.SaveRangeAsync(ra, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region BuildingView
                var allbv = await BuildingViewBussines.GetAllAsync(new CancellationToken());

                if (allbv == null || allbv.Count <= 0)
                {
                    var bv = DefaultBuildingView.SetDef();
                    res.AddReturnedValue(await BuildingViewBussines.SaveRangeAsync(bv, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region BuildingCondition
                var allbc = await BuildingConditionBussines.GetAllAsync(new CancellationToken());

                if (allbc == null || allbc.Count <= 0)
                {
                    var bc = DefaultBuildingCondition.SetDef();
                    res.AddReturnedValue(await BuildingConditionBussines.SaveRangeAsync(bc, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region BuildingType
                var allbt = await BuildingTypeBussines.GetAllAsync(new CancellationToken());

                if (allbt == null || allbt.Count <= 0)
                {
                    var bo = DefaultBuildingType.SetDef();
                    res.AddReturnedValue(await BuildingTypeBussines.SaveRangeAsync(bo, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region PeopleGroup
                var allpg = await PeopleGroupBussines.GetAllAsync();

                if (allpg == null || allpg.Count <= 0)
                {
                    var reg = DefaultPeopleGroup.SetDef();
                    res.AddReturnedValue(await PeopleGroupBussines.SaveRangeAsync(reg, tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion

                #region Setting
                var allSetting = await SettingsBussines.GetAllAsync();

                if (allSetting == null || allSetting.Count <= 0)
                {
                    res.AddReturnedValue(SettingsBussines.Save("ArzeshAfzoude", "9", tr));
                    res.AddReturnedValue(SettingsBussines.Save("Tabdil", "2", tr));
                    if (res.HasError)
                    {
                        return;
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                res.AddReturnedValue(tr.TransactionDestiny(res.HasError));
                res.AddReturnedValue(cn.CloseConnection());
            }
        }
Beispiel #20
0
        private async Task RegisterAdv(AdvertiseLogBusiness adv)
        {
            var ret     = new ReturnedSaveFuncInfo();
            var monitor = new PerfMonitor();

            try
            {
                adv.AdvType = AdvertiseType.NiazKade;
                _driver     = RefreshDriver(_driver);
                _driver.Navigate().GoToUrl("http://www.niazkade.com/new");
                await Wait(4);



                //کلیک روی ساب کتگوری 1
                if (string.IsNullOrEmpty(adv.SubCategory1))
                {
                    adv.SubCategory1 = _cls?.NiazSetting?.Category1;
                }
                _driver.FindElements(By.ClassName("category-list")).FirstOrDefault(q => q.Text == adv.SubCategory1)?.Click();

                await Wait(2);



                //کلیک روی ساب کتگوری2
                if (string.IsNullOrEmpty(adv.SubCategory2))
                {
                    adv.SubCategory2 = _cls?.NiazSetting?.Category2;
                }
                _driver.FindElements(By.ClassName("category-list")).FirstOrDefault(q => q.Text == adv.SubCategory2)?.Click();
                await Wait();


                //درج عکسها

                _driver.FindElement(By.XPath("//input[@type='file']")).SendKeys(adv.ImagesPath);



                //درج عنوان آگهی
                _driver.FindElement(By.Id("title")).SendKeys("");
                _driver.FindElement(By.Id("title")).SendKeys(adv.Title);
                await Wait();


                //انتخاب شهر
                _driver.FindElements(By.ClassName("vs__search")).FirstOrDefault()?.SendKeys(adv.State + "\n");
                await Wait(2);

                _driver.FindElements(By.ClassName("vs__search")).LastOrDefault()?.SendKeys(adv.City + "\n");
                //await Wait();



                //درج محتوای آگهی
                _driver.FindElement(By.Id("description"))
                .SendKeys("");
                _driver.FindElement(By.Id("description"))
                .SendKeys(adv.Content.Replace('(', '<').Replace(')', '>'));
                //await Wait();



                //درج قیمت
                _driver.FindElement(By.Id("price"))?.SendKeys("");
                _driver.FindElement(By.Id("price"))?.SendKeys(adv.Price.ToString());

                await Wait();

                _driver.FindElement(By.Id("phone_number"))?.SendKeys("");
                _driver.FindElement(By.Id("phone_number"))?.SendKeys("0" + adv.SimCardNumber.ToString());

                await Wait(2);

                //کلیک روی دکمه ثبت آگهی


                _driver.FindElements(By.TagName("button")).FirstOrDefault(q => q.Text == "ثبت اگهی")
                ?.Click();

                //اگر آگهی با موفقیت ثبت شود لینک مدیریت آگهی ذخیره می شود
                await Wait(2);


                adv.URL        = _driver.Url;
                adv.UpdateDesc = @"در صف انتشار";
                adv.AdvStatus  = @"در صف انتشار";
                adv.StatusCode = (short)StatusCode.InPublishQueue;
                adv.AdvType    = AdvertiseType.NiazKade;
                adv.IP         = await GetLocalIpAddress();

                await adv.SaveAsync();

                var sim = await SimCardBusiness.GetAsync(adv.SimCardNumber);

                sim.DivarModified = DateTime.Now;
                await sim.SaveAsync();

                //بعد از درج آگهی در دیتابیس لاگ می شود
            }
            catch (Exception ex)
            {
                // MessageBox.Show(@"در هنگام ثبت آگهی زیر خطا رخ داد\r\n" + adv.Adv + @"\r\n" + ex.Message);
                WebErrorLog.ErrorLogInstance.StartLog(ex);
                ret.AddReturnedValue(ex);
            }
            finally { monitor.Dispose(); }
        }
Beispiel #21
0
        private async Task <ReturnedSaveFuncInfo> SaveAsync()
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                if (cls.Guid == Guid.Empty)
                {
                    cls.Guid        = Guid.NewGuid();
                    cls.SanadNumber = await SanadBussines.NextNumberAsync();
                }

                cls.Code           = txtCode.Text.ParseToLong();
                cls.UserGuid       = (Guid)cmbUser.SelectedValue;
                cls.FirstSideGuid  = fSide.Guid;
                cls.FirstSideName  = fSide.Name;
                cls.SecondSideGuid = sSide.Guid;
                cls.SecondSideName = sSide.Name;
                cls.BuildingGuid   = building.Guid;
                cls.Modified       = DateTime.Now;

                cls.Term     = txtTerm.Text.ParseToInt();
                cls.FromDate = Calendar.ShamsiToMiladi(txtfDate.Text);
                if (txtSellPrice.TextDecimal != 0)
                {
                    cls.TotalPrice = txtSellPrice.TextDecimal;
                }
                if (txtRahn.TextDecimal != 0)
                {
                    cls.TotalPrice = txtRahn.TextDecimal;
                }
                if (txtBeyane.TextDecimal != 0)
                {
                    cls.MinorPrice = txtBeyane.TextDecimal;
                }
                if (txtEjare.TextDecimal != 0)
                {
                    cls.MinorPrice = txtEjare.TextDecimal;
                }

                cls.CheckNo       = txtCheckNo.Text;
                cls.BankName      = txtBankName.Text;
                cls.SarResid      = txtSarResid.Text;
                cls.Shobe         = txtShobe.Text;
                cls.DischargeDate = string.IsNullOrEmpty(txtDisCharge.Text)
                    ? DateTime.Now.AddYears(1)
                    : Calendar.ShamsiToMiladi(txtDisCharge.Text);
                cls.SetDocPlace = txtSetDocAddress.Text;
                cls.SetDocDate  = Calendar.ShamsiToMiladi(txtSetDocDate.Text);
                cls.SarQofli    = txtSarQofli.TextDecimal;
                cls.Description = txtDesc.Text;
                cls.Delay       = txtDelay.TextDecimal;

                cls.FirstTax         = txtfAddedValue.TextDecimal;
                cls.FirstAvarez      = txtfAvarez.TextDecimal;
                cls.FirstDiscount    = txtfDiscount.TextDecimal;
                cls.FirstTotalPrice  = txtfTotalPrice.TextDecimal;
                cls.SecondTax        = txtsAddedValue.TextDecimal;
                cls.SecondAvarez     = txtsAvarez.TextDecimal;
                cls.SecondDiscount   = txtsDiscount.TextDecimal;
                cls.SecondTotalPrice = txtsTotalPrice.TextDecimal;

                cls.fBabat = (EnContractBabat)cmbfBabat.SelectedIndex;
                cls.sBabat = (EnContractBabat)cmbsBabat.SelectedIndex;
                if (cmbBazaryab.SelectedValue == null || (Guid)cmbBazaryab.SelectedValue == Guid.Empty)
                {
                    cls.BazaryabGuid  = null;
                    cls.BazaryabPrice = 0;
                }
                else
                {
                    cls.BazaryabGuid  = (Guid)cmbBazaryab.SelectedValue;
                    cls.BazaryabPrice = txtBazaryabPrice.TextDecimal;
                }

                res.AddReturnedValue(await cls.SaveAsync());
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
Beispiel #22
0
        public async Task <ReturnedSaveFuncInfo> SaveAsync(SqlTransaction tr = null)
        {
            var           res      = new ReturnedSaveFuncInfo();
            var           autoTran = tr == null;
            SqlConnection cn       = null;

            try
            {
                if (autoTran)
                {
                    cn = new SqlConnection(Cache.ConnectionString);
                    await cn.OpenAsync();

                    tr = cn.BeginTransaction();
                }

                res.AddReturnedValue(await CheckValidationAsync());
                if (res.HasError)
                {
                    return(res);
                }
                res.AddReturnedValue(await SaveTafsilAsync(tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (TellList?.Count > 0)
                {
                    res.AddReturnedValue(await SaveMobileAsync(tr));
                    if (res.HasError)
                    {
                        return(res);
                    }
                }
                if (BankList?.Count > 0)
                {
                    res.AddReturnedValue(await SaveBankAccountAsync(tr));
                    if (res.HasError)
                    {
                        return(res);
                    }
                }

                res.AddReturnedValue(await UnitOfWork.Peoples.SaveAsync(this, tr));
                if (res.HasError)
                {
                    return(res);
                }

                var action = IsModified ? EnLogAction.Update : EnLogAction.Insert;
                res.AddReturnedValue(await UserLogBussines.SaveAsync(action, EnLogPart.Peoples, tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (Cache.IsSendToServer)
                {
                    _ = Task.Run(() => WebPeople.SaveAsync(this));
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (autoTran)
                {
                    res.AddReturnedValue(tr.TransactionDestiny(res.HasError));
                    res.AddReturnedValue(cn.CloseConnection());
                }
            }
            return(res);
        }
        public async Task <ReturnedSaveFuncInfo> SaveAsync(SqlTransaction tr = null)
        {
            var           res      = new ReturnedSaveFuncInfo();
            var           autoTran = tr == null;
            SqlConnection cn       = null;

            try
            {
                if (autoTran)
                {
                    cn = new SqlConnection(Cache.ConnectionString);
                    await cn.OpenAsync();

                    tr = cn.BeginTransaction();
                }

                res.AddReturnedValue(await CheckvalidationAsync());
                if (res.HasError)
                {
                    return(res);
                }

                var oldSanad = await GetAsync(Guid);

                if (oldSanad != null)
                {
                    res.AddReturnedValue(await UpdateAccounts(oldSanad.Details, true, tr));
                    if (res.HasError)
                    {
                        return(res);
                    }
                }

                res.AddReturnedValue(await UnitOfWork.Sanad.SaveAsync(this, tr));
                if (res.HasError)
                {
                    return(res);
                }
                foreach (var item in Details)
                {
                    item.MasterGuid = Guid;
                }
                res.AddReturnedValue(await SanadDetailBussines.RemoveRangeAsync(Guid, tr));
                if (res.HasError)
                {
                    return(res);
                }
                res.AddReturnedValue(await SanadDetailBussines.SaveRangeAsync(Details, tr));
                if (res.HasError)
                {
                    return(res);
                }
                res.AddReturnedValue(await UpdateAccounts(Details, false, tr));
                if (res.HasError)
                {
                    return(res);
                }

                if (Cache.IsSendToServer)
                {
                    _ = Task.Run(() => WebSanad.SaveAsync(this));
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (autoTran)
                {
                    res.AddReturnedValue(tr.TransactionDestiny(res.HasError));
                    res.AddReturnedValue(cn.CloseConnection());
                }
            }
            return(res);
        }
        private async Task RegisterAdv(AdvertiseLogBusiness adv)
        {
            var ret     = new ReturnedSaveFuncInfo();
            var monitor = new PerfMonitor();

            try
            {
                adv.AdvType = AdvertiseType.NiazmandyHa;
                _driver     = Utility.RefreshDriver(_driver);
                _driver.Navigate().GoToUrl("https://niazmandyha.ir/newAd");
                await Utility.Wait();

                //درج عکسها
                _driver.FindElement(By.XPath("//input[@type='file']")).SendKeys(adv.ImagesPath);

                //درج عنوان آگهی
                _driver.FindElement(By.Name("title")).SendKeys("");
                _driver.FindElement(By.Name("title")).SendKeys(adv.Title);


                //کلیک کردن روی کتگوری اصلی
                _driver.FindElements(By.Name("category")).FirstOrDefault()?.Click();
                await Utility.Wait();

                //کلیک روی ساب کتگوری 1
                if (string.IsNullOrEmpty(adv.SubCategory1))
                {
                    adv.SubCategory1 = cls?.NiazmandyHaSetting?.Category1;
                }
                _driver.FindElements(By.TagName("option")).FirstOrDefault(q => q.Text == adv.SubCategory1)?.Click();

                await Utility.Wait(1);



                //درج قیمت

                _driver.FindElement(By.Name("cost"))?.SendKeys("");
                _driver.FindElement(By.Name("cost"))?.SendKeys(adv.Price.ToString());

                await Utility.Wait();


                //درج محتوای آگهی
                var thread = new Thread(() => Clipboard.SetText(adv.Content.Replace('(', '<').Replace(')', '>')));
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();

                var t = _driver.FindElement(By.TagName("iframe"));
                t.Click();
                await Utility.Wait(1);

                t.SendKeys(OpenQA.Selenium.Keys.Control + "v");
                var thread1 = new Thread(Clipboard.Clear);
                thread1.SetApartmentState(ApartmentState.STA);
                thread1.Start();


                //انتخاب شهر
                await Utility.Wait();

                _driver.FindElement(By.Name("state")).Click();
                await Utility.Wait();

                _driver.FindElements(By.TagName("option"))?.FirstOrDefault(q => q.Text == adv.State)?.Click();
                await Utility.Wait(1);

                _driver.FindElement(By.Name("city")).Click();
                await Utility.Wait();

                var cc = _driver.FindElements(By.TagName("option")).FirstOrDefault(q => q.Text == adv.City) ??
                         _driver.FindElements(By.TagName("option")).LastOrDefault();
                await Utility.Wait();

                cc?.Click();


                //کلیک روی دکمه ثبت آگهی
                await Utility.Wait(2);

                _driver.FindElements(By.TagName("button")).FirstOrDefault(q => q.Text == "ثبت آگهی")
                ?.Click();



                //اگر آگهی با موفقیت ثبت شود لینک مدیریت آگهی ذخیره می شود
                await Utility.Wait();

                await Utility.Wait(2);

                adv.URL = await MakeUrl(_driver.Url);

                adv.UpdateDesc = @"در صف انتشار";
                adv.AdvStatus  = @"در صف انتشار";
                adv.StatusCode = (short)StatusCode.InPublishQueue;
                adv.AdvType    = AdvertiseType.NiazmandyHa;
                adv.IP         = await Utility.GetLocalIpAddress();

                adv.SubCategory2 = "-";
                await adv.SaveAsync();

                var sim = await SimCardBusiness.GetAsync(adv.SimCardNumber);

                sim.NiazmandyHaModified = DateTime.Now;
                await sim.SaveAsync();

                //بعد از درج آگهی در دیتابیس لاگ می شود
            }
            catch (Exception ex)
            {
                // MessageBox.Show(@"در هنگام ثبت آگهی زیر خطا رخ داد\r\n" + adv.Adv + @"\r\n" + ex.Message);
                WebErrorLog.ErrorLogInstance.StartLog(ex);
                ret.AddReturnedValue(ex);
            }
            finally { monitor.Dispose(); }
        }
        public static async Task <ReturnedSaveFuncInfo> ReStoreDbAsync(string connectionString, string pathf, bool autoBackup, ENSource Source)
        {
            var ret = new ReturnedSaveFuncInfo();
            var cn  = new SqlConnection();

            try
            {
                GC.Collect();
                SqlConnection.ClearAllPools();

                if (autoBackup)
                {
                    var dir = Application.StartupPath + "\\AradBackUp";
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    var file = Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly()?.Location)?.Replace(".exe", "__");
                    var d    = Calendar.MiladiToShamsi(DateTime.Now).Replace("/", "_");
                    d    += "__" + DateTime.Now.Hour + " - " + DateTime.Now.Minute;
                    file += d;

                    var filepath = dir + "\\" + file + ".Bak";
                    ret.AddReturnedValue(await BackupDbAsync(connectionString, Source, EnBackUpType.Manual, filepath));
                }

                if (pathf.EndsWith(".NPZ") || pathf.EndsWith(".npz"))
                {
                    var zp = new Zip();
                    pathf = zp.ExtractTempDIR(pathf);
                }
                else if (pathf.EndsWith(".NPZ2") || pathf.EndsWith(".npz2"))
                {
                    try
                    {
                        var zp  = new CompressFile();
                        var res = await zp.ExtractTempDIR(pathf);

                        ret.AddReturnedValue(res);
                        if (res.HasError)
                        {
                            return(ret);
                        }
                        pathf = res.value;
                    }
                    catch
                    {
                        var zp = new Zip();
                        pathf = zp.ExtractTempDIR(pathf);
                    }
                }

                var csb = new SqlConnectionStringBuilder(connectionString);
                var serverConnectionString =
                    connectionString.Replace("Initial Catalog=" + csb.InitialCatalog, "Initial Catalog=");
                cn = new SqlConnection(serverConnectionString)
                {
                    ConnectionString = serverConnectionString
                };
                var cmd        = new SqlCommand("RESTORE DATABASE [dbName] FROM  DISK = N'bkPath' WITH  FILE = 1,  MOVE N'novin' TO N'dbMDFPath',  MOVE N'novin_log' TO N'dbLDFPath',   NOUNLOAD,  REPLACE,  STATS = 5", cn);
                var dbInfo     = new CLSServerDBs(connectionString);
                var backUpInfo = new DataBaseBackUpInfo(pathf, cn.ConnectionString);

                cmd.CommandText = cmd.CommandText.Replace("dbName", csb.InitialCatalog);
                cmd.CommandText = cmd.CommandText.Replace("bkPath", pathf);
                cmd.CommandText = cmd.CommandText.Replace("novin", backUpInfo.LogicalName);
                cmd.CommandText = cmd.CommandText.Replace("novin_log", backUpInfo.LogicalName + "_log.ldf");
                cmd.CommandText = cmd.CommandText.Replace("dbMDFPath", dbInfo.FileName);
                cmd.CommandText =
                    cmd.CommandText.Replace("dbLDFPath", dbInfo.FileName.ToLower().Replace(".mdf", "_log.Ldf"));

                //تایم اوت بالا بردن مجاز است
                cmd.CommandTimeout = 5 * 60 * 1000;//5 minutes

                cn.Open();
                var temp = cmd.CommandText;
                cmd.CommandText = "ALTER DATABASE [" + csb.InitialCatalog + "] SET SINGLE_USER WITH ROLLBACK IMMEDIATE";
                cmd.ExecuteNonQuery();

                cmd.CommandText = temp;
                cmd.ExecuteNonQuery();

                // cmd.CommandText = NovinPardaz.Properties.Resources.DatabaseSettings;
                cmd.CommandText = cmd.CommandText.Replace("dbName", csb.InitialCatalog);
                cmd.ExecuteNonQuery();

                cmd.CommandText = "ALTER DATABASE [" + csb.InitialCatalog + "] SET Multi_USER";
                cmd.ExecuteNonQuery();
                cn.Close();

                SqlConnection.ClearAllPools();
                Application.DoEvents();
            }
            catch (SqlException ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                try { cn.Close(); } catch { }
                ret.AddReturnedValue(ReturnedState.Error, $"حساب کاربری SQL دسترسی به مسیر نصب برنامه ندارد\r\n{ex.Message }//{ex?.InnerException?.Message ?? ""}");
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                try { cn.Close(); } catch { }
                ret.AddReturnedValue(ex);
            }
            Task.Run(() => SetMultiUser(connectionString));
            return(ret);
        }
Beispiel #26
0
        public static async Task <ReturnedSaveFuncInfo> NaqdAvalDoreAsync(PardakhtCheckAvalDoreBussines cls)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                var checkPage = await CheckPageBussines.GetAsync(cls.CheckPageGuid);

                var dasteCheck = await DasteCheckBussines.GetAsync(checkPage.CheckGuid);

                var bank = await TafsilBussines.GetAsync(dasteCheck.BankGuid);

                var girande = await TafsilBussines.GetAsync(cls.TafsilGuid);

                var sanad = new SanadBussines()
                {
                    Guid        = Guid.NewGuid(),
                    Modified    = DateTime.Now,
                    Description = $"نقد کردن چک پرداختنی * شماره: {checkPage.Number} بانک صادر کننده: {bank.Name} * گیرنده: {girande.Name}",
                    DateM       = DateTime.Now,
                    Number      = await SanadBussines.NextNumberAsync(),
                    SanadStatus = EnSanadStatus.Temporary,
                    SanadType   = EnSanadType.Auto,
                    UserGuid    = UserBussines.CurrentUser.Guid
                };

                if (checkPage.CheckStatus == EnCheckSh.Bargashti)
                {
                    res.AddReturnedValue(await NaqdBargashtAvalDoreAsync(cls, sanad));
                    if (res.HasError)
                    {
                        return(res);
                    }
                }

                //بستانکار--موجودی
                sanad.AddToListSanad(new SanadDetailBussines()
                {
                    Guid        = Guid.NewGuid(),
                    Modified    = DateTime.Now,
                    Description = $"نقد کردن چک {checkPage.Number} {bank.Name} * گیرنده: {girande.Name}",
                    Debit       = 0,
                    Credit      = cls.Price,
                    TafsilGuid  = bank.Guid,
                    MasterGuid  = sanad.Guid,
                    MoeinGuid   = ParentDefaults.MoeinCoding.CLSMoein10101
                });
                //بدهکار--اسناد
                sanad.AddToListSanad(new SanadDetailBussines()
                {
                    Guid        = Guid.NewGuid(),
                    Modified    = DateTime.Now,
                    Description = $"نقد کردن چک {checkPage.Number} {bank.Name} * گیرنده: {girande.Name}",
                    Debit       = cls.Price,
                    Credit      = 0,
                    TafsilGuid  = bank.Guid,
                    MasterGuid  = sanad.Guid,
                    MoeinGuid   = ParentDefaults.MoeinCoding.CLSMoein30101
                });

                res.AddReturnedValue(await sanad.SaveAsync());


                checkPage.CheckStatus = EnCheckSh.Pass;
                checkPage.Modified    = DateTime.Now;
                res.AddReturnedValue(await checkPage.SaveAsync());
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }

            return(res);
        }
        private async void mnuDelete_Click(object sender, EventArgs e)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                if (DGrid.RowCount <= 0)
                {
                    return;
                }
                if (DGrid.CurrentRow == null)
                {
                    return;
                }
                var guid = (Guid)DGrid[dgGuid.Index, DGrid.CurrentRow.Index].Value;
                if (_st)
                {
                    var hazine = await BankBussines.GetAsync(guid);

                    if (hazine == null)
                    {
                        return;
                    }
                    if (hazine.Account != 0)
                    {
                        res.AddError("به دلیل داشتن گردش حساب، شما مجاز به حذف حساب بانکی نمی باشید");
                        return;
                    }

                    if (MessageBox.Show(this,
                                        $@"آیا از حذف {DGrid[dgName.Index, DGrid.CurrentRow.Index].Value} اطمینان دارید؟", "حذف",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    var prd = await BankBussines.GetAsync(guid);

                    res.AddReturnedValue(await prd.ChangeStatusAsync(false));
                }
                else
                {
                    if (MessageBox.Show(this,
                                        $@"آیا از فعال کردن {DGrid[dgName.Index, DGrid.CurrentRow.Index].Value} اطمینان دارید؟",
                                        "حذف",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    var prd = await BankBussines.GetAsync(guid);

                    res.AddReturnedValue(await prd.ChangeStatusAsync(true));
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (res.HasError)
                {
                    this.ShowError(res, "خطا در تغییر وضعیت حساب بانکی");
                }
                else
                {
                    await LoadDataAsync(txtSearch.Text);
                }
            }
        }
        private async void mnuDelete_Click(object sender, EventArgs e)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                if (DGrid.RowCount <= 0)
                {
                    return;
                }
                if (DGrid.CurrentRow == null)
                {
                    return;
                }
                var guid      = (Guid)DGrid[dgGuid.Index, DGrid.CurrentRow.Index].Value;
                var dasteChek = await DasteCheckBussines.GetAsync(guid);

                if (_st)
                {
                    if (dasteChek == null)
                    {
                        frmNotification.PublicInfo.ShowMessage("دسته چک انتخابی معتبر نمی باشد");
                        return;
                    }
                    var masraf = dasteChek.CheckPages.Any(q => q.CheckStatus != EnCheckSh.Mojoud);
                    if (masraf)
                    {
                        frmNotification.PublicInfo.ShowMessage("به علت کشیدن چک از این دسته چک، شما مجاز به ویرایش آن نمی باشید");
                        return;
                    }
                    if (MessageBox.Show(this,
                                        $@"آیا از حذف دسته چک {DGrid[dgName.Index, DGrid.CurrentRow.Index].Value} اطمینان دارید؟", "حذف",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    res.AddReturnedValue(await dasteChek.ChangeStatusAsync(false));
                }
                else
                {
                    if (MessageBox.Show(this,
                                        $@"آیا از فعال کردن دسته چک {DGrid[dgName.Index, DGrid.CurrentRow.Index].Value} اطمینان دارید؟",
                                        "حذف",
                                        MessageBoxButtons.YesNo,
                                        MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return;
                    }
                    res.AddReturnedValue(await dasteChek.ChangeStatusAsync(true));
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (res.HasError)
                {
                    this.ShowError(res, "خطا در تغییر وضعیت حساب بانکی");
                }
                else
                {
                    await LoadDataAsync(txtSearch.Text);
                }
            }
        }
Beispiel #29
0
        public async Task <ReturnedSaveFuncInfo> SaveAsync()
        {
            var monitor = new PerfMonitor();
            var ret     = new ReturnedSaveFuncInfo();

            try
            {
                if (string.IsNullOrEmpty(RootPath))
                {
                    RootPath = ConfigurationManager.AppSettings.Get("RootPath");
                }

                #region validation

                if (string.IsNullOrEmpty(AdvName))
                {
                    ret.AddReturnedValue(ReturnedState.Error, "آگهی فاقد نام است");
                }
                if (string.IsNullOrEmpty(Content))
                {
                    ret.AddReturnedValue(ReturnedState.Error, "آگهی فاقد محتوا می باشد");
                }
                if (string.IsNullOrEmpty(Price.ToString(CultureInfo.CurrentCulture)))
                {
                    ret.AddReturnedValue(ReturnedState.Error, "آگهی فاقد قیمت می باشد");
                }
                if (Titles?.Count < 1)
                {
                    ret.AddReturnedValue(ReturnedState.Error, "آگهی فاقد عنوان است");
                }
                if (Images?.Count < 1)
                {
                    ret.AddReturnedValue(ReturnedState.Error, "آگهی فاقد تصویر است");
                }

                #endregion

                var advPath = Path.Combine(RootPath, AdvName);

                if (!_isEdit && Directory.Exists(advPath))
                {
                    ret.AddReturnedValue(ReturnedState.Error, "نام آگهی تکراری است");
                }

                if (ret.HasError)
                {
                    return(ret);
                }

                //ذخیره آگهی
                await Task.Run(() =>
                {
                    var picturePath = Path.Combine(advPath, "Pictures");
                    if (!Directory.Exists(picturePath))
                    {
                        Directory.CreateDirectory(picturePath);
                    }
                    //حذف عسکهای اضافی
                    if (_isEdit)
                    {
                        //حذف عکسهایی که اکنون در لیست عکسهای آگهی نیستند
                        //بعبارتی کاربر هنگام ویرایش آنها را حذف کرده است
                        var oldImages = GetFiles(picturePath);
                        if (oldImages?.Count > 0)
                        {
                            foreach (var image in oldImages)
                            {
                                if (Images.IndexOf(image) < 0)
                                {
                                    File.Delete(image);
                                }
                            }
                        }
                    }
                    var contentPath = Path.Combine(advPath, "Content.txt");
                    File.WriteAllText(contentPath, Content);

                    var titlesPath = Path.Combine(advPath, "Titles.txt");
                    if (Titles != null)
                    {
                        File.WriteAllLines(titlesPath, Titles);
                    }

                    var divCatPath = Path.Combine(advPath, "DivarCat.txt");
                    if (DivarCategories != null)
                    {
                        File.WriteAllLines(divCatPath, DivarCategories);
                    }

                    var sheyCatPath = Path.Combine(advPath, "SheypoorCat.txt");
                    if (SheypoorCategories != null)
                    {
                        File.WriteAllLines(sheyCatPath, SheypoorCategories);
                    }

                    var niazCatPath = Path.Combine(advPath, "NiazKadeCat.txt");
                    if (NiazKadeCategories != null)
                    {
                        File.WriteAllLines(niazCatPath, NiazKadeCategories);
                    }
                    var niazmandyHaCatPath = Path.Combine(advPath, "NiazmandyHaCat.txt");
                    if (NiazmandyHaCategories != null)
                    {
                        File.WriteAllLines(niazmandyHaCatPath, NiazmandyHaCategories);
                    }

                    var pricePath = Path.Combine(advPath, "Price.txt");
                    File.WriteAllText(pricePath, Price.ToString(CultureInfo.CurrentCulture));

                    var pishNevisPath = Path.Combine(advPath, "PishNevis.txt");
                    if (PishNevis)
                    {
                        File.WriteAllText(pishNevisPath, "True");
                    }
                    else
                    if (File.Exists(pishNevisPath))
                    {
                        File.Delete(pishNevisPath);
                    }



                    //ذخیره عکسهای جدید کاربر
                    if (Images?.Count > 0)
                    {
                        var oldImages = GetFiles(picturePath);
                        foreach (var image in Images)
                        {
                            if (oldImages.IndexOf(image) < 0)
                            {
                                File.Copy(image, Path.Combine(picturePath, $"{Guid.NewGuid()}.jpg"));
                            }
                        }
                    }

                    //حذف آگهی قدیمی :در صورتیکه نام آگهی تغییر کند
                    if (!string.IsNullOrEmpty(OldAdvName))
                    {
                        var deleteResult = DeleteAsync(OldAdvName, RootPath);
                        if (deleteResult.Result.HasError)
                        {
                            foreach (var error in deleteResult.Result.ErrorList)
                            {
                                ret.AddReturnedValue(ReturnedState.Error, error);
                            }
                        }
                    }
                });

                //ویرایش نام آگهی در جدول آگهی های مجاز برای ویزیتور
                var visitorAdv = await VisitorAdvBusiness.GetAllAsync(OldAdvName);

                if (visitorAdv != null && visitorAdv.Count != 0)
                {
                    foreach (var item in visitorAdv)
                    {
                        item.AdvName = AdvName;
                        await item.SaveAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorLogInstance.StartLog(ex);
                ret.AddReturnedValue(ex);
            }
            finally { monitor.Dispose(); }
            return(ret);
        }
        private async void btnFinish_Click(object sender, EventArgs e)
        {
            var res = new ReturnedSaveFuncInfo();

            try
            {
                if (cls.Guid == Guid.Empty)
                {
                    cls.Guid  = Guid.NewGuid();
                    cls.DateM = DateTime.Now;
                }
                cls.Modified    = DateTime.Now;
                cls.Status      = true;
                cls.Name        = txtName.Text;
                cls.Code        = txtCode.Text;
                cls.Description = txtDesc.Text;
                cls.isSystem    = false;
                cls.HesabType   = (HesabType)cmbType.SelectedIndex + 1;
                var acc = txtAccount_.TextDecimal;
                if (cmbAccount.SelectedIndex == 0)
                {
                    cls.AccountFirst = 0;
                }
                else
                {
                    if (cmbAccount.SelectedIndex == 1)
                    {
                        cls.AccountFirst = -acc;
                    }
                    else
                    {
                        cls.AccountFirst = acc;
                    }
                }

                if (cls.HesabType == HesabType.Bank)
                {
                    res.AddError("لطفا برای تعریف حساب بانکی، از منوی حسابداری، حساب های بانکی اقدام نمایید");
                    return;
                }
                if (cls.HesabType == HesabType.Customer)
                {
                    res.AddError("لطفا برای تعریف اشخاص، از منوی اطلاعات پایه، مدیریت اشخاص اقدام نمایید");
                    return;
                }

                res.AddReturnedValue(await cls.SaveAsync());
            }
            catch (Exception ex)
            {
                WebErrorLog.ErrorInstence.StartErrorLog(ex);
                res.AddReturnedValue(ex);
            }
            finally
            {
                if (res.HasError)
                {
                    this.ShowError(res, "خطا در ثبت حساب تفصیلی");
                }
                else
                {
                    DialogResult = DialogResult.OK;
                    Close();
                }
            }
        }