Ejemplo n.º 1
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(explainTextBox.Text))
            {
                explainTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("توضیحات وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; insert into backAccountInfoHistory (id, name, bankName, ownerName, subdate, enactmentId, description) Values (@id, @name, @bname, @oname, @sdate, @eId, @des); delete from bankAccount where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);

            cmd.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
            cmd.Parameters.AddWithValue("@name", bankAccountNameTextBox.Text);
            cmd.Parameters.AddWithValue("@bname", bankNameTextBox.Text);
            cmd.Parameters.AddWithValue("@oname", bankAccountOwnerNameTextBox.Text);
            cmd.Parameters.AddWithValue("@sdate", endDateTimePickerX.SelectedDateInDateTime.Date);
            cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
            cmd.Parameters.AddWithValue("@des", "(حذف حساب) " + explainTextBox.Text);
            cmd.ExecuteNonQuery();
            con.Close();
            FMessegeBox.FarsiMessegeBox.Show("حساب با موفقیت حذف شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            this.Close();
        }
Ejemplo n.º 2
0
        private void editMemeberButton_Click(object sender, EventArgs e)
        {
            string id;

            if (!editMemberTextbox.Text.Any(char.IsWhiteSpace) && editMemberTextbox.Text.All(char.IsDigit))
            {
                id = ExtensionFunction.PersianToEnglish(editMemberTextbox.Text);
                SqlConnection con = new SqlConnection(this.connection);
                con.Open();
                SqlCommand cmdcheck = new SqlCommand("select count(*) as existance from member where id = @id", con);
                cmdcheck.Parameters.AddWithValue("@id", id);
                int exist = 0;
                using (SqlDataReader reader = cmdcheck.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        exist = int.Parse(String.Format("{0}", reader["existance"]));
                    }
                }
                con.Close();
                if (exist == 1)
                {
                    var newform = new editMemberForm2(id);
                    newform.ShowDialog(this);
                }
                else
                {
                    FMessegeBox.FarsiMessegeBox.Show("عضوی با این شماره ملی وجود ندارد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                }
            }
            else
            {
                FMessegeBox.FarsiMessegeBox.Show("!شماره ملی باید شامل اعداد و بدون هیچ فاصله‌ای باشد", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
            }
        }
Ejemplo n.º 3
0
        private void comebackButton_Click(object sender, EventArgs e)
        {
            string id;

            id = ExtensionFunction.PersianToEnglish(comebackTextbox.Text);
            SqlCommand    cmdcheck;
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            if (this.Text == "رجعت عضو")
            {
                cmdcheck = new SqlCommand("select count(*) as existance from abandoned where id = @id", con);
                cmdcheck.Parameters.AddWithValue("@id", id);
                int exist = 0;
                using (SqlDataReader reader = cmdcheck.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        exist = int.Parse(String.Format("{0}", reader["existance"]));
                    }
                }
                con.Close();
                if (exist == 1)
                {
                    var newform = new comebackForm2(id);
                    newform.ShowDialog(this);
                }
                else
                {
                    FMessegeBox.FarsiMessegeBox.Show("!عضوی با این شماره ملی در لیست اعضای معلق وجود ندارد", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                }
            }
            else
            {
                cmdcheck = new SqlCommand("select count(*) as existance from member, Inmember where member.id = Inmember.id and Inmember.kickdate is Null and member.id = @id", con);
                cmdcheck.Parameters.AddWithValue("@id", id);
                int exist = 0;
                using (SqlDataReader reader = cmdcheck.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        exist = int.Parse(String.Format("{0}", reader["existance"]));
                    }
                }
                con.Close();
                if (exist == 1)
                {
                    var newform = new comebackForm2(id);
                    newform.ShowDialog(this);
                }
                else
                {
                    FMessegeBox.FarsiMessegeBox.Show("!عضوی با این شماره ملی در لیست اعضای رجعت یافته وجود ندارد", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                }
            }
        }
Ejemplo n.º 4
0
        private void denyButton_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            SqlCommand cmd = new SqlCommand("update MarryHelpReq Set status = @rstat, enactmentId = @eId where id = @rId;", con);

            cmd.Parameters.AddWithValue("@rId", this.rId);
            cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
            cmd.Parameters.AddWithValue("@rstat", "رد شده");
            cmd.ExecuteNonQuery();
            con.Close();
            FMessegeBox.FarsiMessegeBox.Show("درخواست با موفقیت رد شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            this.Close();
        }
Ejemplo n.º 5
0
        private void delButton_Click(object sender, EventArgs e)
        {
            DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسیت به حذف ارائه این کمک اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);

            if (res != DialogResult.Yes)
            {
                return;
            }
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            string dpath = System.IO.Directory.GetFiles(this.helpPath + "\\" + this.id + "\\receipt")[0];

            System.IO.File.Delete(dpath);
            if (cashtype == "نقدی")
            {
                decimal    stock  = 0;
                SqlCommand cmdget = new SqlCommand("select stock from bankAccount where id = @bId;", con);
                cmdget.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        stock = reader.GetDecimal(0);
                    }
                }
                SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update OtherHelpsIndiv Set presdescription = Null, enddate = Null, status = @stat where id = @bId; update bankAccount set stock = @st where id = @id; delete from doc where id = @id and doctype = @dtype; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmd.Parameters.AddWithValue("@id", this.id);
                cmd.Parameters.AddWithValue("@stat", "ارائه");
                cmd.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                cmd.Parameters.AddWithValue("@st", stock + fee);
                cmd.Parameters.AddWithValue("@dtype", "OIhelp:receipt");
                cmd.ExecuteNonQuery();
            }
            else
            {
                SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update OtherHelpsIndiv Set presdescription = Null, enddate = Null, status = @stat where id = @id; update bankAccount set stock = @st where id = @id; delete from doc where id = @id and doctype = @dtype; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmd.Parameters.AddWithValue("@id", this.id);
                cmd.Parameters.AddWithValue("@stat", "ارائه");
                cmd.Parameters.AddWithValue("@dtype", "OIhelp:receipt");
                cmd.ExecuteNonQuery();
            }

            con.Close();
            FMessegeBox.FarsiMessegeBox.Show("ارائه کمک با موفقیت حذف شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            this.Close();
        }
Ejemplo n.º 6
0
 private void chooseButton_Click(object sender, EventArgs e)
 {
     if (membersView.Rows[membersView.SelectedCells[0].RowIndex].Cells[7].Value.ToString() == "نامشخص")
     {
         FMessegeBox.FarsiMessegeBox.Show("این تقاضا فایل یا اطلاعات بیشتری ندارد!", "توجه", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
     }
     else if(membersView.Rows[membersView.SelectedCells[0].RowIndex].Cells[6].Value.ToString() == "")
     {
         var newform = new observereqForm2_2(ExtensionFunction.PersianToEnglish(membersView.Rows[membersView.SelectedCells[0].RowIndex].Cells[membersView.SelectedCells[0].ColumnIndex].Value.ToString()));
         newform.ShowDialog(this);
     }
     else
     {
         var newform = new observereqForm3_2(ExtensionFunction.PersianToEnglish(membersView.Rows[membersView.SelectedCells[0].RowIndex].Cells[membersView.SelectedCells[0].ColumnIndex].Value.ToString()));
         newform.ShowDialog(this);
     }
 }
Ejemplo n.º 7
0
        private void setButton_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            SqlCommand cmdmember = new SqlCommand("select count(*) from member where id = @id and id = supporter_id;", con);

            cmdmember.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(idTextbox.Text));
            int c = 0;

            using (SqlDataReader reader = cmdmember.ExecuteReader())
            {
                if (reader.Read())
                {
                    c = reader.GetInt32(0);
                }
            }
            if (c != 0)
            {
                var newform = new newReqForm2(ExtensionFunction.PersianToEnglish(idTextbox.Text), "member");
                newform.ShowDialog(this);
            }
            else
            {
                SqlCommand cmdapplicant = new SqlCommand("select count(*) from otherApplicant where id = @id;", con);
                cmdapplicant.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(idTextbox.Text));
                c = 0;
                using (SqlDataReader reader = cmdapplicant.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        c = reader.GetInt32(0);
                    }
                }
                if (c != 0)
                {
                    var newform = new newReqForm2(ExtensionFunction.PersianToEnglish(idTextbox.Text), "applicant");
                    newform.ShowDialog(this);
                }
                else
                {
                    FMessegeBox.FarsiMessegeBox.Show("شماره ملی عضو موجود نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                }
            }
            con.Close();
        }
Ejemplo n.º 8
0
        private void setButton_Click(object sender, EventArgs e)
        {
            DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ثبت بودجه اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);

            if (res != DialogResult.Yes)
            {
                return;
            }
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            SqlCommand cmdsavehistory = new SqlCommand("BEGIN TRY begin tran t1; insert into budgetsCurrenciesHistory select @y, * from budgetsCurrencies; update budgetsCurrencies set amount = 0 where typename like '%Consume'; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
            SqlCommand cmdgetbsid     = new SqlCommand("select max(id) from budgetsets;", con);
            string     bsid           = "1398";

            using (SqlDataReader reader = cmdgetbsid.ExecuteReader())
            {
                if (reader.Read())
                {
                    bsid = reader.GetString(0);
                }
            }
            cmdsavehistory.Parameters.AddWithValue("@y", bsid);
            cmdsavehistory.ExecuteNonQuery();
            string     d   = DateTime.Now.Date.ToPersian(); d = d.Substring(0, 4) + d.Substring(5, 2) + d.Substring(8, 2);
            SqlCommand cmd = new SqlCommand("insert into budgetsets (id, subdate, enactmentId) Values(@id, @sdate, @eId);", con);

            cmd.Parameters.AddWithValue("@id", "bs" + d);
            cmd.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
            cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
            cmd.ExecuteNonQuery();
            NumericUpDown nu;

            foreach (var budget in budgets)
            {
                cmd = new SqlCommand("update budgetsCurrencies Set amount = @amount where typename = @tname;", con);
                nu  = (NumericUpDown)this.Controls.Find(budget + "NumericUpDown", true)[0];
                cmd.Parameters.AddWithValue("@amount", nu.Value);
                cmd.Parameters.AddWithValue("@tname", budget + "Budget");
                cmd.ExecuteNonQuery();
            }
            FMessegeBox.FarsiMessegeBox.Show("بودجه با موفقیت تعیین شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            con.Close();
            this.Close();
            con.Close();
        }
        private void chooseButton_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            SqlCommand cmd = new SqlCommand("select docpath from enactment where id = @id;", con);

            cmd.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(membersView.Rows[membersView.SelectedCells[0].RowIndex].Cells[membersView.SelectedCells[0].ColumnIndex + membersView.ColumnCount - 1].Value.ToString()));
            string p = "";

            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                if (reader.Read())
                {
                    p = reader.GetString(0);
                }
            }
            con.Close();
            System.Diagnostics.Process.Start(p);
        }
Ejemplo n.º 10
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            bool          flag = false;
            SqlConnection con  = new SqlConnection(this.connection);

            con.Open();
            SqlCommand cmd = new SqlCommand("select name, family from helper where id = @id;", con);

            cmd.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(helperIdTextbox.Text));
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                if (reader.Read())
                {
                    helperNameTextBox.Text = reader.GetString(0) + " " + reader.GetString(1);
                    flag = true;
                }
            }
            con.Close();
            if (!flag)
            {
                helperNameTextBox.Text = "";
            }
        }
Ejemplo n.º 11
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (typeComboBox.Text.Length == 0)
            {
                FMessegeBox.FarsiMessegeBox.Show("نوع کمک انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }

            /*if (String.IsNullOrWhiteSpace(helperIdTextbox.Text))
             * {
             *  helperIdTextbox.BackColor = Color.Tomato;
             *  FMessegeBox.FarsiMessegeBox.Show("شناسه ملی اهداکننده وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
             *  return;
             * }*/
            if (!helperIdTextbox.Text.All(char.IsDigit) || helperIdTextbox.TextLength != 10)
            {
                helperIdTextbox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("شناسه ملی اهداکننده باید فقط شامل ارقام و 10 رقم باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (!String.IsNullOrWhiteSpace(helperIdTextbox.Text) && String.IsNullOrWhiteSpace(helperNameTextBox.Text))
            {
                helperIdTextbox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("شماره ملی وارد شده ولی نام اهداکننده بررسی نشده یا وجود ندارد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (docLabel.BackColor == Color.Red)
            {
                FMessegeBox.FarsiMessegeBox.Show("فایل رسید انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(explainTextBox.Text))
            {
                explainTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("ذکر توضیحات الزامی است. توضیحی وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (typeComboBox.Text == "نقدی" && bankAccountNumberTextBox.TextLength == 0)
            {
                FMessegeBox.FarsiMessegeBox.Show("حساب مورد نظر انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ثبت دریافت این کمک اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);

            if (res != DialogResult.Yes)
            {
                return;
            }
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            string     d = DateTime.Now.Date.ToPersian(); d = "Rec" + d.Substring(0, 4) + d.Substring(5, 2) + d.Substring(8, 2);
            SqlCommand cmdgetid = new SqlCommand("select id from recHelps where id like '" + d + "%';", con);
            int        index = 1, mx = 1;

            using (SqlDataReader reader = cmdgetid.ExecuteReader())
            {
                while (reader.Read())
                {
                    string s = String.Format("{0}", reader["id"]);
                    if (s == "")
                    {
                        index = 1;
                    }
                    else
                    {
                        index = Convert.ToInt32(s.Substring(11)) + 1;
                    }
                    mx = Math.Max(mx, index);
                }
            }
            d = d + mx.ToString();
            decimal stock = 0;

            if (cashRadioButton.Checked)
            {
                SqlCommand cmdget = new SqlCommand("select stock from bankAccount where id = @id", con);
                cmdget.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        stock = reader.GetDecimal(0);
                    }
                }
            }
            else
            {
                SqlCommand cmdget = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                switch (typeComboBox.Text)
                {
                case "گوشت":
                    cmdget.Parameters.AddWithValue("@id", "meat");
                    break;

                case "خواربار":
                    cmdget.Parameters.AddWithValue("@id", "grocery");
                    break;

                case "مرغ":
                    cmdget.Parameters.AddWithValue("@id", "chicken");
                    break;

                case "ازدواج":
                    cmdget.Parameters.AddWithValue("@id", "marry");
                    break;

                case "ایتام":
                    cmdget.Parameters.AddWithValue("@id", "orphan");
                    break;

                case "متفرقه":
                    cmdget.Parameters.AddWithValue("@id", "stock");
                    break;
                }
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        stock = reader.GetDecimal(0);
                    }
                }
            }

            string fileName   = System.IO.Path.GetFileName(doc);
            string targetPath = this.recHelpPath + "\\" + d + "\\";

            System.IO.Directory.CreateDirectory(targetPath);
            string destFile = System.IO.Path.Combine(targetPath, fileName);

            System.IO.File.Copy(doc, destFile, false);
            SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; insert into recHelps(id, type, fee, packet, recdate, subdate, helperId, helperName, bankAccountId, bankAccountName, description, cashtype) Values(@id, @typ, @fee, @pack, @rdate, @sdate, @hId, @hName, @bId, @bName, @des, @cashtype); insert into recHelpsHistory (id, type, fee, packet, recdate, subdate, helperId, helperName, bankAccountId, bankAccountName, description, cashtype) Values(@id, @typ, @fee, @pack, @rdate, @sdate, @hId, @hName, @bId, @bName, @des, @cashtype); insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @sdate, @dtype); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);

            cmd.Parameters.AddWithValue("@id", d);
            cmd.Parameters.AddWithValue("@typ", typeComboBox.Text);
            cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
            cmd.Parameters.AddWithValue("@pack", packetNumericUpDown.Value);
            cmd.Parameters.AddWithValue("@rdate", recDateTimePickerX.SelectedDateInDateTime.Date);
            cmd.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
            cmd.Parameters.AddWithValue("@hId", ExtensionFunction.PersianToEnglish(helperIdTextbox.Text));
            cmd.Parameters.AddWithValue("@hName", helperNameTextBox.Text);
            cmd.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
            cmd.Parameters.AddWithValue("@bName", bankAccountNameComboBox.Text);
            cmd.Parameters.AddWithValue("@des", explainTextBox.Text);
            if (cashRadioButton.Checked)
            {
                cmd.Parameters.AddWithValue("@cashtype", "نقدی");
            }
            else
            {
                cmd.Parameters.AddWithValue("@cashtype", "غیرنقدی");
            }
            cmd.Parameters.AddWithValue("@dname", fileName);
            cmd.Parameters.AddWithValue("@dpath", destFile);
            cmd.Parameters.AddWithValue("@dtype", "recHelp");
            cmd.ExecuteNonQuery();
            SqlCommand cmd2;

            if (cashRadioButton.Checked)
            {
                cmd2 = new SqlCommand("update bankAccount set stock = @st where id = @id;", con);
                cmd2.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                cmd2.Parameters.AddWithValue("@st", stock + feeNumericUpDown.Value);
                cmd2.ExecuteNonQuery();
            }
            else if (typeComboBox.Text == "گوشت")
            {
                cmd2 = new SqlCommand("update budgetsCurrencies set amount = @amount where typename = @typ;", con);
                cmd2.Parameters.AddWithValue("@typ", "meat");
                cmd2.Parameters.AddWithValue("@amount", stock + feeNumericUpDown.Value);
                cmd2.ExecuteNonQuery();
            }
            else if (typeComboBox.Text == "مرغ")
            {
                cmd2 = new SqlCommand("update budgetsCurrencies set amount = @amount where typename = @typ;", con);
                cmd2.Parameters.AddWithValue("@typ", "chicken");
                cmd2.Parameters.AddWithValue("@amount", stock + feeNumericUpDown.Value);
                cmd2.ExecuteNonQuery();
            }
            else if (typeComboBox.Text == "خواربار")
            {
                cmd2 = new SqlCommand("update budgetsCurrencies set amount = @amount where typename = @typ;", con);
                cmd2.Parameters.AddWithValue("@typ", "grocery");
                cmd2.Parameters.AddWithValue("@amount", stock + feeNumericUpDown.Value);
                cmd2.ExecuteNonQuery();
            }
            else if (typeComboBox.Text == "ازدواج")
            {
                cmd2 = new SqlCommand("update budgetsCurrencies set amount = @amount where typename = @typ;", con);
                cmd2.Parameters.AddWithValue("@typ", "marry");
                cmd2.Parameters.AddWithValue("@amount", stock + feeNumericUpDown.Value);
                cmd2.ExecuteNonQuery();
            }
            else if (typeComboBox.Text == "ایتام")
            {
                cmd2 = new SqlCommand("update budgetsCurrencies set amount = @amount where typename = @typ;", con);
                cmd2.Parameters.AddWithValue("@typ", "orphan");
                cmd2.Parameters.AddWithValue("@amount", stock + feeNumericUpDown.Value);
                cmd2.ExecuteNonQuery();
            }
            else if (typeComboBox.Text == "متفرقه")
            {
                cmd2 = new SqlCommand("update budgetsCurrencies set amount = @amount where typename = @typ;", con);
                cmd2.Parameters.AddWithValue("@typ", "stock");
                cmd2.Parameters.AddWithValue("@amount", stock + feeNumericUpDown.Value);
                cmd2.ExecuteNonQuery();
            }
            FMessegeBox.FarsiMessegeBox.Show("دریافت کمک با موفقیت ثبت شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            con.Close();
            this.Close();
        }
Ejemplo n.º 12
0
        private void setButton_Click(object sender, EventArgs e)
        {
            if (this.Text == "تایید معرفی‌نامه تحصیلی")
            {
                SqlConnection con = new SqlConnection(this.connection);
                con.Open();

                decimal    budget = 0, consume = 0, stock = 0;
                SqlCommand cmdget  = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                SqlCommand cmdget2 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                SqlCommand cmdget3 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                cmdget.Parameters.AddWithValue("@id", "eduBudget");
                cmdget2.Parameters.AddWithValue("@id", "eduConsume");
                cmdget3.Parameters.AddWithValue("@id", "stock");
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        budget = reader.GetDecimal(0);
                    }
                }
                using (SqlDataReader reader = cmdget2.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        consume = reader.GetDecimal(0);
                    }
                }
                using (SqlDataReader reader = cmdget3.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        stock = reader.GetDecimal(0);
                    }
                }
                if (feeNumericUpDown.Value > this.fee && consume + feeNumericUpDown.Value - this.fee > budget)
                {
                    FMessegeBox.FarsiMessegeBox.Show("این درخواست خارج از محدوده بودجه تعریف شده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
                else if (feeNumericUpDown.Value > this.fee && feeNumericUpDown.Value - this.fee > stock)
                {
                    FMessegeBox.FarsiMessegeBox.Show("موجودی کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
                else
                {
                    res = true;
                    SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1;update StudyHelps Set fenactmentId = @feId, status = @stat, fee = @fee where id = @id; update budgetsCurrencies Set amount = @amount2 where typename = @tname2; update budgetsCurrencies Set amount = @amount3 where typename = @tname3; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd.Parameters.AddWithValue("@id", this.id);
                    cmd.Parameters.AddWithValue("@feId", ExtensionFunction.PersianToEnglish(enactmentTextbox2.Text));
                    cmd.Parameters.AddWithValue("@stat", "نهایی");
                    cmd.Parameters.AddWithValue("@amount2", consume + feeNumericUpDown.Value - this.fee);
                    cmd.Parameters.AddWithValue("@amount3", stock - feeNumericUpDown.Value + this.fee);
                    cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
                    cmd.Parameters.AddWithValue("@tname2", "eduConsume");
                    cmd.Parameters.AddWithValue("@tname3", "stock");
                    cmd.ExecuteNonQuery();
                    con.Close();
                    FMessegeBox.FarsiMessegeBox.Show("کمک با موفقیت تایید و نهایی شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    this.Close();
                }
            }
            else if (this.Text == "ویرایش تایید معرفی‌نامه تحصیلی")
            {
                SqlConnection con = new SqlConnection(this.connection);
                con.Open();

                decimal    budget = 0, consume = 0, stock = 0;
                SqlCommand cmdget  = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                SqlCommand cmdget2 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                SqlCommand cmdget3 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                cmdget.Parameters.AddWithValue("@id", "eduBudget");
                cmdget2.Parameters.AddWithValue("@id", "eduConsume");
                cmdget3.Parameters.AddWithValue("@id", "stock");
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        budget = reader.GetDecimal(0);
                    }
                }
                using (SqlDataReader reader = cmdget2.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        consume = reader.GetDecimal(0);
                    }
                }
                using (SqlDataReader reader = cmdget3.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        stock = reader.GetDecimal(0);
                    }
                }
                if (feeNumericUpDown.Value > this.fee && consume + feeNumericUpDown.Value - this.fee > budget)
                {
                    FMessegeBox.FarsiMessegeBox.Show("این درخواست خارج از محدوده بودجه تعریف شده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
                else if (feeNumericUpDown.Value > this.fee && feeNumericUpDown.Value - this.fee > stock)
                {
                    FMessegeBox.FarsiMessegeBox.Show("موجودی کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
                else
                {
                    res = true;
                    SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1;update StudyHelps Set fenactmentId = @feId, fee = @fee where id = @id; update budgetsCurrencies Set amount = @amount2 where typename = @tname2; update budgetsCurrencies Set amount = @amount3 where typename = @tname3; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd.Parameters.AddWithValue("@id", this.id);
                    cmd.Parameters.AddWithValue("@feId", ExtensionFunction.PersianToEnglish(enactmentTextbox2.Text));
                    cmd.Parameters.AddWithValue("@amount2", consume + feeNumericUpDown.Value - this.fee);
                    cmd.Parameters.AddWithValue("@amount3", stock - feeNumericUpDown.Value + this.fee);
                    cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
                    cmd.Parameters.AddWithValue("@tname2", "eduConsume");
                    cmd.Parameters.AddWithValue("@tname3", "stock");
                    cmd.ExecuteNonQuery();
                    con.Close();
                    FMessegeBox.FarsiMessegeBox.Show("تایید کمک با موفقیت ویرایش شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    this.Close();
                }
            }
            else if (this.Text == "ارائه معرفی‌نامه تحصیلی")
            {
                res = true;
                SqlConnection con = new SqlConnection(this.connection);
                con.Open();
                SqlCommand cmdup = new SqlCommand("BEGIN TRY begin tran t1; update StudyHelps Set status = @stat, enddate = @edate where id = @id; insert into StudyRecList (hId, supporter_id, folder_id, name, family, stuId) select hId, supporter_id, folder_id, name, family, stuId from StudyFinList where hId = @id; delete from StudyFinList where hId = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmdup.Parameters.AddWithValue("@id", this.id);
                cmdup.Parameters.AddWithValue("@stat", "پایان‌یافته");
                cmdup.Parameters.AddWithValue("@edate", DateTime.Now.Date);
                cmdup.ExecuteNonQuery();
                con.Close();
                FMessegeBox.FarsiMessegeBox.Show("کمک با موفقیت پایان یافت!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
                this.Close();
            }
            else
            {
                res = true;
                FMessegeBox.FarsiMessegeBox.Show("ارائه کمک با موفقیت ویرایش شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
                this.Close();
            }
        }
Ejemplo n.º 13
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(bankAccountNameTextBox.Text))
            {
                bankAccountNameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام حساب وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (!bankAccountNumberTextBox.Text.All(char.IsDigit))
            {
                bankAccountNumberTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("شماره حساب باید فقط شامل ارقام باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(bankNameTextBox.Text))
            {
                bankNameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام بانک وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }

            /*if (!bankNameTextBox.Text.All(c => char.IsWhiteSpace(c) || char.IsLetter(c)))
             * {
             *  bankNameTextBox.BackColor = Color.Tomato;
             *  FMessegeBox.FarsiMessegeBox.Show("نام بانک باید فقط شامل حروف و فاصله باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
             *  return;
             * }*/
            if (String.IsNullOrWhiteSpace(bankAccountOwnerNameTextBox.Text))
            {
                bankAccountOwnerNameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام صاحب حساب وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (!bankAccountOwnerNameTextBox.Text.All(c => char.IsWhiteSpace(c) || char.IsLetter(c)))
            {
                bankAccountOwnerNameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام صاحب حساب باید فقط شامل حروف و فاصله باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }

            if (String.IsNullOrWhiteSpace(explainTextBox.Text))
            {
                explainTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("توضیحات وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            if (this.id != ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text))
            {
                int        c        = 0;
                SqlCommand cmdcheck = new SqlCommand("select count(*) from bankAccount where id = @id;", con);
                using (SqlDataReader reader = cmdcheck.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        c = reader.GetInt32(0);
                    }
                }
                if (c != 0)
                {
                    bankAccountNumberTextBox.BackColor = Color.Tomato;
                    FMessegeBox.FarsiMessegeBox.Show("شماره حساب وارد شده متعلق به یک حساب دیگر موجود در سیستم می‌باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
            }
            SqlCommand cmd = new SqlCommand("update backAccountInfoHistory set id = @newId where id = @id; insert into backAccountInfoHistory (id, name, bankName, ownerName, subdate, enactmentId, description) Values (@newId, @name, @bname, @oname, @sdate, @eId, @des); update bankAccount set id = @newId, name = @name, bankName = @bname, ownerName = @oname where id = @id;", con);

            cmd.Parameters.AddWithValue("@id", this.id);
            cmd.Parameters.AddWithValue("@newId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
            cmd.Parameters.AddWithValue("@name", bankAccountNameTextBox.Text);
            cmd.Parameters.AddWithValue("@bname", bankNameTextBox.Text);
            cmd.Parameters.AddWithValue("@oname", bankAccountOwnerNameTextBox.Text);
            cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
            cmd.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
            cmd.Parameters.AddWithValue("@des", explainTextBox.Text);
            cmd.ExecuteNonQuery();
            con.Close();
            FMessegeBox.FarsiMessegeBox.Show("حساب با موفقیت ویرایش شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            this.Close();
        }
Ejemplo n.º 14
0
        private void setButton_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            SqlCommand cmdcheck;

            if (this.Text == "بررسی تقاضا" || this.Text == "ویرایش تقاضا")
            {
                cmdcheck = new SqlCommand("select count(*) from request where applicantId = sup and id = @id and result is Null;", con);
                cmdcheck.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(idTextbox.Text));
                int c = 0;
                using (SqlDataReader reader = cmdcheck.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        c = reader.GetInt32(0);
                    }
                }
                if (c != 0)
                {
                    if (this.Text == "بررسی تقاضا")
                    {
                        var newform = new checkReqForm(ExtensionFunction.PersianToEnglish(idTextbox.Text), "check");
                        newform.ShowDialog(this);
                    }
                    else
                    {
                        var newform = new newReqForm2(ExtensionFunction.PersianToEnglish(idTextbox.Text), "edit");
                        newform.ShowDialog(this);
                    }
                }
                else
                {
                    FMessegeBox.FarsiMessegeBox.Show("شماره تقاضا موجود نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                }
            }
            else if (this.Text == "ثبت ارائه معرفی‌نامه" || this.Text == "ویرایش بررسی")
            {
                if (this.Text == "ویرایش بررسی")
                {
                    cmdcheck = new SqlCommand("select count(*) from request where applicantId = sup and id = @id and result is not Null and deliveryDate is Null;", con);
                }
                else
                {
                    cmdcheck = new SqlCommand("select count(*) from request where applicantId = sup and id = @id and result = N'تایید' and deliveryDate is Null;", con);
                }
                cmdcheck.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(idTextbox.Text));
                int c = 0;
                using (SqlDataReader reader = cmdcheck.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        c = reader.GetInt32(0);
                    }
                }
                if (c != 0)
                {
                    if (this.Text == "ثبت ارائه معرفی‌نامه")
                    {
                        var newform = new responseReqForm(ExtensionFunction.PersianToEnglish(idTextbox.Text), "response");
                        newform.ShowDialog(this);
                    }
                    else
                    {
                        var newform = new checkReqForm(ExtensionFunction.PersianToEnglish(idTextbox.Text), "edit");
                        newform.ShowDialog(this);
                    }
                }
                else
                {
                    FMessegeBox.FarsiMessegeBox.Show("شماره تقاضا موجود نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                }
            }
            else if (this.Text == "ویرایش مصوبه")
            {
                cmdcheck = new SqlCommand("select count(*) from enactment where id = @id;", con);
                cmdcheck.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(idTextbox.Text));
                int c = 0;
                using (SqlDataReader reader = cmdcheck.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        c = reader.GetInt32(0);
                    }
                }
                if (c != 0)
                {
                    var newform = new editEnactmentForm(ExtensionFunction.PersianToEnglish(idTextbox.Text));
                    newform.ShowDialog(this);
                }
                else
                {
                    FMessegeBox.FarsiMessegeBox.Show("شماره مصوبه موجود نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                }
            }
            else
            {
                cmdcheck = new SqlCommand("select count(*) from request where applicantId = sup and id = @id and deliveryDate is not Null;", con);
                cmdcheck.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(idTextbox.Text));
                int c = 0;
                using (SqlDataReader reader = cmdcheck.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        c = reader.GetInt32(0);
                    }
                }
                if (c != 0)
                {
                    var newform = new responseReqForm(ExtensionFunction.PersianToEnglish(idTextbox.Text), "edit");
                    newform.ShowDialog(this);
                }
                else
                {
                    FMessegeBox.FarsiMessegeBox.Show("شماره تقاضا موجود نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                }
            }
            con.Close();
        }
Ejemplo n.º 15
0
        private void setButton_Click(object sender, EventArgs e)
        {
            if (this.Text == "ارائه کمک ازدواج")
            {
                if (this.type == "نقدی")
                {
                    if (bankAccountNameComboBox.SelectedIndex == -1)
                    {
                        FMessegeBox.FarsiMessegeBox.Show("حساب بانکی انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                        return;
                    }
                    if (receiptLabel.BackColor == Color.Red)
                    {
                        FMessegeBox.FarsiMessegeBox.Show("فیش پرداخت بارگزاری نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                        return;
                    }
                    SqlConnection con = new SqlConnection(this.connection);
                    con.Open();
                    decimal    stock    = 0;
                    SqlCommand cmdgetst = new SqlCommand("select stock from bankAccount where id = @bId;", con);
                    cmdgetst.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    using (SqlDataReader reader = cmdgetst.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            stock = reader.GetDecimal(0);
                        }
                    }
                    if (stock < fee)
                    {
                        FMessegeBox.FarsiMessegeBox.Show("موجودی حساب کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                        return;
                    }
                    DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ثبت ارائه این کمک اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    if (res != DialogResult.Yes)
                    {
                        return;
                    }
                    string fileName   = System.IO.Path.GetFileName(RF);
                    string targetPath = this.helpPath + "\\" + this.id + "\\receipt";
                    string destFile   = System.IO.Path.Combine(targetPath, fileName);
                    System.IO.File.Copy(addOpenFileDialog.FileName, destFile, false);
                    SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update MarryHelps Set presdescription = @des, enddate = @edate, status = @stat, bankAccountName = @bName, bankAccountId = @bId where id = @id; update bankAccount set stock = @st where id = @bId; insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @edate, @dtype); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd.Parameters.AddWithValue("@id", this.id);
                    cmd.Parameters.AddWithValue("@des", "(توضیحات ارائه: " + explainTextBox2.Text + ")");
                    cmd.Parameters.AddWithValue("@edate", DateTime.Now.Date);
                    cmd.Parameters.AddWithValue("@stat", "پایان‌یافته: ارائه شده");
                    cmd.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmd.Parameters.AddWithValue("@st", stock - fee);
                    cmd.Parameters.AddWithValue("@bName", bankAccountNameComboBox.Text);
                    cmd.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmd.Parameters.AddWithValue("@dname", fileName);
                    cmd.Parameters.AddWithValue("@dpath", destFile);
                    cmd.Parameters.AddWithValue("@dtype", "Mhelp:receipt");
                    cmd.ExecuteNonQuery();
                    con.Close();
                    FMessegeBox.FarsiMessegeBox.Show("کمک با موفقیت به مددجو ارائه شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    this.Close();
                }
                else
                {
                    if (receiptLabel.BackColor == Color.Red)
                    {
                        FMessegeBox.FarsiMessegeBox.Show("رسید بارگزاری نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                        return;
                    }

                    SqlConnection con = new SqlConnection(this.connection);
                    con.Open();
                    string fileName   = System.IO.Path.GetFileName(RF);
                    string targetPath = this.helpPath + "\\" + this.id + "\\receipt";
                    string destFile   = System.IO.Path.Combine(targetPath, fileName);
                    System.IO.File.Copy(addOpenFileDialog.FileName, destFile, false);
                    SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update MarryHelps Set presdescription = @des, enddate = @edate, status = @stat where id = @id; insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @edate, @dtype); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd.Parameters.AddWithValue("@id", this.id);
                    cmd.Parameters.AddWithValue("@des", "(توضیحات ارائه: " + explainTextBox2.Text + ")");
                    cmd.Parameters.AddWithValue("@edate", DateTime.Now.Date);
                    cmd.Parameters.AddWithValue("@stat", "پایان‌یافته: ارائه شده");
                    cmd.Parameters.AddWithValue("@dname", fileName);
                    cmd.Parameters.AddWithValue("@dpath", destFile);
                    cmd.Parameters.AddWithValue("@dtype", "Mhelp:receipt");
                    cmd.ExecuteNonQuery();
                    con.Close();
                    FMessegeBox.FarsiMessegeBox.Show("کمک با موفقیت به مددجو ارائه شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    this.Close();
                }
            }
            else
            {
                SqlConnection con = new SqlConnection(this.connection);
                con.Open();
                decimal prestock = 0, stock = 0;
                if (this.prebId != ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text))
                {
                    SqlCommand cmdgetst = new SqlCommand("select stock from bankAccount where id = @bId;", con);
                    cmdgetst.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    using (SqlDataReader reader = cmdgetst.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            stock = reader.GetDecimal(0);
                        }
                    }
                    cmdgetst = new SqlCommand("select stock from bankAccount where id = @bId;", con);
                    cmdgetst.Parameters.AddWithValue("@bId", this.prebId);
                    using (SqlDataReader reader = cmdgetst.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            prestock = reader.GetDecimal(0);
                        }
                    }
                }
                if (stock < fee)
                {
                    FMessegeBox.FarsiMessegeBox.Show("موجودی حساب قبلی برای ویرایش کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
                DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ثبت ارائه این کمک اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);
                if (res != DialogResult.Yes)
                {
                    return;
                }
                if (this.prebId != ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text))
                {
                    SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @st where id = @prev; update bankAccount set stock = @newst where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd.Parameters.AddWithValue("@prev", this.prebId);
                    cmd.Parameters.AddWithValue("@st", prestock + fee);
                    cmd.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmd.Parameters.AddWithValue("@newst", stock - fee);
                    cmd.ExecuteNonQuery();
                }
                if (receiptLabel.BackColor == Color.GreenYellow)
                {
                    string dpath = System.IO.Directory.GetFiles(this.helpPath + "\\" + this.id + "\\receipt")[0];
                    System.IO.File.Delete(dpath);
                    string fileName   = System.IO.Path.GetFileName(RF);
                    string targetPath = this.helpPath + "\\" + this.id + "\\receipt";
                    string destFile   = System.IO.Path.Combine(targetPath, fileName);
                    System.IO.File.Copy(addOpenFileDialog.FileName, destFile, false);
                    SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update MarryHelps Set presdescription = @des where id = @id; update doc Set docname = @dname, docpath = @dpath, subdate = @edate where id = @id and doctype = @dtype; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd.Parameters.AddWithValue("@id", this.id);
                    cmd.Parameters.AddWithValue("@des", this.explain + "(توضیحات ویرایش ارائه: " + explainTextBox2.Text + ")");
                    cmd.Parameters.AddWithValue("@edate", DateTime.Now.Date);
                    cmd.Parameters.AddWithValue("@dname", fileName);
                    cmd.Parameters.AddWithValue("@dpath", destFile);
                    cmd.Parameters.AddWithValue("@dtype", "Mhelp:receipt");
                    cmd.ExecuteNonQuery();
                }
                else
                {
                    SqlCommand cmd = new SqlCommand("update MarryHelps Set presdescription = @des where id = @id;", con);
                    cmd.Parameters.AddWithValue("@id", this.id);
                    cmd.Parameters.AddWithValue("@des", this.explain + "(توضیحات ویرایش ارائه: " + explainTextBox2.Text + ")");
                    cmd.ExecuteNonQuery();
                }
                con.Close();
                FMessegeBox.FarsiMessegeBox.Show("ارائه کمک با موفقیت ویرایش شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
                this.Close();
            }
        }
Ejemplo n.º 16
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (typeComboBox.Text.Length == 0)
            {
                FMessegeBox.FarsiMessegeBox.Show("نوع کمک انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(buyerNameTextBox.Text))
            {
                buyerNameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام خریدار وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (docLabel.BackColor == Color.Red)
            {
                FMessegeBox.FarsiMessegeBox.Show("فایل رسید انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(explainTextBox.Text))
            {
                explainTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("ذکر توضیحات الزامی است. توضیحی وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (bankAccountNameComboBox.SelectedIndex == -1)
            {
                FMessegeBox.FarsiMessegeBox.Show("حساب مورد نظر انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            decimal    stock = 0, amount = 0, prestock = 0, preamount = 0;
            SqlCommand cmdgetst = new SqlCommand("select stock from bankAccount where id = @id;", con);

            cmdgetst.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
            using (SqlDataReader reader = cmdgetst.ExecuteReader())
            {
                if (reader.Read())
                {
                    stock = reader.GetDecimal(0);
                }
            }
            if (this.prebId != ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text))
            {
                cmdgetst = new SqlCommand("select stock from bankAccount where id = @id;", con);
                cmdgetst.Parameters.AddWithValue("@id", this.prebId);
                using (SqlDataReader reader = cmdgetst.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        prestock = reader.GetDecimal(0);
                    }
                }
                if (stock < feeNumericUpDown.Value)
                {
                    FMessegeBox.FarsiMessegeBox.Show("موجودی حساب جدید کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
            }
            else if (feeNumericUpDown.Value > preFee && stock < feeNumericUpDown.Value - preFee)
            {
                FMessegeBox.FarsiMessegeBox.Show("موجودی حساب کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (pretype == "اداری فرهنگی" && typeComboBox.Text == "اداری فرهنگی")
            {
                decimal    budget = 0, consume = 0;
                SqlCommand cmdget  = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                SqlCommand cmdget2 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                cmdget.Parameters.AddWithValue("@id", "cultureBudget");
                cmdget2.Parameters.AddWithValue("@id", "cultureConsume");
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        budget = reader.GetDecimal(0);
                    }
                }
                using (SqlDataReader reader = cmdget2.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        consume = reader.GetDecimal(0);
                    }
                }
                if (feeNumericUpDown.Value > preFee && consume + feeNumericUpDown.Value - preFee > budget)
                {
                    FMessegeBox.FarsiMessegeBox.Show("این درخواست خارج از محدوده بودجه تعریف شده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
                DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ویرایش خرید این کمک اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);
                if (res != DialogResult.Yes)
                {
                    return;
                }

                SqlCommand cmdupam, cmdupst;
                if (this.prebId != ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text))
                {
                    cmdupst = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @st where id = @prev; update bankAccount set stock = @newst where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmdupst.Parameters.AddWithValue("@prev", this.prebId);
                    cmdupst.Parameters.AddWithValue("@st", prestock + preFee);
                    cmdupst.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmdupst.Parameters.AddWithValue("@newst", stock - feeNumericUpDown.Value);
                    cmdupst.ExecuteNonQuery();
                }
                else if (preFee != feeNumericUpDown.Value)
                {
                    cmdupst = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @newst where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmdupst.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmdupst.Parameters.AddWithValue("@newst", stock + preFee - feeNumericUpDown.Value);
                    cmdupst.ExecuteNonQuery();
                }
                if (docLabel.BackColor == Color.YellowGreen)
                {
                    string fileName   = System.IO.Path.GetFileName(doc);
                    string targetPath = this.buyHelpPath + "\\" + this.id + "\\";
                    System.IO.Directory.Delete(targetPath, true);
                    System.IO.Directory.CreateDirectory(targetPath);
                    string destFile = System.IO.Path.Combine(targetPath, fileName);
                    System.IO.File.Copy(doc, destFile, false);
                    SqlCommand cmdupdatefile = new SqlCommand("BEGIN TRY begin tran t1; delete from doc where id = @id; insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @sdate, @dtype); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmdupdatefile.Parameters.AddWithValue("@id", this.id);
                    cmdupdatefile.Parameters.AddWithValue("@dname", fileName);
                    cmdupdatefile.Parameters.AddWithValue("@dpath", destFile);
                    cmdupdatefile.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                    cmdupdatefile.Parameters.AddWithValue("@dtype", "buyHelp");
                    cmdupdatefile.ExecuteNonQuery();
                }
                SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update buyHelps set type = @typ, fee = @fee, packet = @pack, buydate = @bdate, subdate = @sdate, buyerName = @buname, bankAccountId = @bId, bankAccountName = @bName, description = @des where id = @id; insert into buyHelpsHistory (id, type, fee, packet, buydate, subdate, buyerName, bankAccountId, bankAccountName, description, enactmentId) Values(@id, @typ, @fee, @pack, @bdate, @sdate, @buName, @bId, @bName, @des, @eId); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmd.Parameters.AddWithValue("@id", this.id);
                cmd.Parameters.AddWithValue("@typ", typeComboBox.Text);
                cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@pack", packetNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@bdate", buyDateTimePickerX.SelectedDateInDateTime.Date);
                cmd.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                cmd.Parameters.AddWithValue("@buName", buyerNameTextBox.Text);
                cmd.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                cmd.Parameters.AddWithValue("@bName", bankAccountNameComboBox.Text);
                cmd.Parameters.AddWithValue("@newst", stock - feeNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@des", explainTextBox.Text);
                cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
                cmd.ExecuteNonQuery();
            }
            else if (pretype == "اداری فرهنگی" && typeComboBox.Text != "اداری فرهنگی")
            {
                SqlCommand cmdgetam = new SqlCommand("select amount from budgetsCurrencies where typename = @id;", con);
                switch (typeComboBox.Text)
                {
                case "گوشت":
                    cmdgetam.Parameters.AddWithValue("@id", "meat");
                    break;

                case "خواربار":
                    cmdgetam.Parameters.AddWithValue("@id", "grocery");
                    break;

                case "مرغ":
                    cmdgetam.Parameters.AddWithValue("@id", "chicken");
                    break;

                case "متفرقه":
                    cmdgetam.Parameters.AddWithValue("@id", "stock");
                    break;
                }
                using (SqlDataReader reader = cmdgetam.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        amount = reader.GetDecimal(0);
                    }
                }
                cmdgetam = new SqlCommand("select amount from budgetsCurrencies where typename = @id;", con);
                cmdgetam.Parameters.AddWithValue("@id", "cultureConsume");
                using (SqlDataReader reader = cmdgetam.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        preamount = reader.GetDecimal(0);
                    }
                }
                DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ویرایش خرید این کمک اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);
                if (res != DialogResult.Yes)
                {
                    return;
                }

                SqlCommand cmdupam, cmdupst;
                if (this.prebId != ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text))
                {
                    cmdupst = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @st where id = @prev; update bankAccount set stock = @newst where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmdupst.Parameters.AddWithValue("@prev", this.prebId);
                    cmdupst.Parameters.AddWithValue("@st", prestock + preFee);
                    cmdupst.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmdupst.Parameters.AddWithValue("@newst", stock - feeNumericUpDown.Value);
                    cmdupst.ExecuteNonQuery();
                }
                else if (preFee != feeNumericUpDown.Value)
                {
                    cmdupst = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @newst where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmdupst.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmdupst.Parameters.AddWithValue("@newst", stock + preFee - feeNumericUpDown.Value);
                    cmdupst.ExecuteNonQuery();
                }

                cmdupam = new SqlCommand("BEGIN TRY begin tran t1; update budgetsCurrencies set amount = @am where typename = @prev; update budgetsCurrencies set amount = @newam where typename = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmdupam.Parameters.AddWithValue("@prev", "cultureConsume");
                if (typeComboBox.Text == "گوشت")
                {
                    cmdupam.Parameters.AddWithValue("@id", "meat");
                }
                else if (typeComboBox.Text == "مرغ")
                {
                    cmdupam.Parameters.AddWithValue("@id", "chicken");
                }
                else if (typeComboBox.Text == "خواربار")
                {
                    cmdupam.Parameters.AddWithValue("@id", "grocery");
                }
                else if (typeComboBox.Text == "متفرقه")
                {
                    cmdupam.Parameters.AddWithValue("@id", "stock");
                }
                cmdupam.Parameters.AddWithValue("@am", preamount - preFee);
                cmdupam.Parameters.AddWithValue("@newam", amount + feeNumericUpDown.Value);
                cmdupam.ExecuteNonQuery();
                if (docLabel.BackColor == Color.YellowGreen)
                {
                    string fileName   = System.IO.Path.GetFileName(doc);
                    string targetPath = this.buyHelpPath + "\\" + this.id + "\\";
                    System.IO.Directory.Delete(targetPath, true);
                    System.IO.Directory.CreateDirectory(targetPath);
                    string destFile = System.IO.Path.Combine(targetPath, fileName);
                    System.IO.File.Copy(doc, destFile, false);
                    SqlCommand cmdupdatefile = new SqlCommand("BEGIN TRY begin tran t1; delete from doc where id = @id; insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @sdate, @dtype); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmdupdatefile.Parameters.AddWithValue("@id", this.id);
                    cmdupdatefile.Parameters.AddWithValue("@dname", fileName);
                    cmdupdatefile.Parameters.AddWithValue("@dpath", destFile);
                    cmdupdatefile.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                    cmdupdatefile.Parameters.AddWithValue("@dtype", "buyHelp");
                    cmdupdatefile.ExecuteNonQuery();
                }
                SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update buyHelps set type = @typ, fee = @fee, packet = @pack, buydate = @bdate, subdate = @sdate, buyerName = @buname, bankAccountId = @bId, bankAccountName = @bName, description = @des where id = @id; insert into buyHelpsHistory (id, type, fee, packet, buydate, subdate, buyerName, bankAccountId, bankAccountName, description, enactmentId) Values(@id, @typ, @fee, @pack, @bdate, @sdate, @buName, @bId, @bName, @des, @eId); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmd.Parameters.AddWithValue("@id", this.id);
                cmd.Parameters.AddWithValue("@typ", typeComboBox.Text);
                cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@pack", packetNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@bdate", buyDateTimePickerX.SelectedDateInDateTime.Date);
                cmd.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                cmd.Parameters.AddWithValue("@buName", buyerNameTextBox.Text);
                cmd.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                cmd.Parameters.AddWithValue("@bName", bankAccountNameComboBox.Text);
                cmd.Parameters.AddWithValue("@newst", stock - feeNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@des", explainTextBox.Text);
                cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
                cmd.ExecuteNonQuery();
            }
            else if (pretype != "اداری فرهنگی" && typeComboBox.Text == "اداری فرهنگی")
            {
                decimal    budget = 0, consume = 0;
                SqlCommand cmdget  = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                SqlCommand cmdget2 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                cmdget.Parameters.AddWithValue("@id", "cultureBudget");
                cmdget2.Parameters.AddWithValue("@id", "cultureConsume");
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        budget = reader.GetDecimal(0);
                    }
                }
                using (SqlDataReader reader = cmdget2.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        consume = reader.GetDecimal(0);
                    }
                }
                if (feeNumericUpDown.Value > preFee && consume + feeNumericUpDown.Value - preFee > budget)
                {
                    FMessegeBox.FarsiMessegeBox.Show("این درخواست خارج از محدوده بودجه تعریف شده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
                SqlCommand cmdgetam = new SqlCommand("select amount from budgetsCurrencies where typename = @id;", con);
                switch (this.pretype)
                {
                case "گوشت":
                    cmdgetam.Parameters.AddWithValue("@id", "meat");
                    break;

                case "خواربار":
                    cmdgetam.Parameters.AddWithValue("@id", "grocery");
                    break;

                case "مرغ":
                    cmdgetam.Parameters.AddWithValue("@id", "chicken");
                    break;

                case "متفرقه":
                    cmdgetam.Parameters.AddWithValue("@id", "stock");
                    break;
                }
                using (SqlDataReader reader = cmdgetam.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        preamount = reader.GetDecimal(0);
                    }
                }
                if (preamount < preFee)
                {
                    FMessegeBox.FarsiMessegeBox.Show(String.Format("موجودی {0} برای عودت ارزش ریالی کافی نیست!", this.pretype), "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
                DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ویرایش خرید این کمک اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);
                if (res != DialogResult.Yes)
                {
                    return;
                }

                SqlCommand cmdupam, cmdupst;
                if (this.prebId != ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text))
                {
                    cmdupst = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @st where id = @prev; update bankAccount set stock = @newst where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmdupst.Parameters.AddWithValue("@prev", this.prebId);
                    cmdupst.Parameters.AddWithValue("@st", prestock + preFee);
                    cmdupst.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmdupst.Parameters.AddWithValue("@newst", stock - feeNumericUpDown.Value);
                    cmdupst.ExecuteNonQuery();
                }
                else if (preFee != feeNumericUpDown.Value)
                {
                    cmdupst = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @newst where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmdupst.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmdupst.Parameters.AddWithValue("@newst", stock + preFee - feeNumericUpDown.Value);
                    cmdupst.ExecuteNonQuery();
                }
                cmdupam = new SqlCommand("BEGIN TRY begin tran t1; update budgetsCurrencies set amount = @am where typename = @prev; update budgetsCurrencies set amount = @newam where typename = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                switch (this.pretype)
                {
                case "گوشت":
                    cmdupam.Parameters.AddWithValue("@prev", "meat");
                    break;

                case "خواربار":
                    cmdupam.Parameters.AddWithValue("@prev", "grocery");
                    break;

                case "مرغ":
                    cmdupam.Parameters.AddWithValue("@prev", "chicken");
                    break;

                case "متفرقه":
                    cmdupam.Parameters.AddWithValue("@prev", "stock");
                    break;
                }
                cmdupam.Parameters.AddWithValue("@id", "cultureConsume");
                cmdupam.Parameters.AddWithValue("@am", preamount - preFee);
                cmdupam.Parameters.AddWithValue("@newam", amount + feeNumericUpDown.Value);
                cmdupam.ExecuteNonQuery();
                if (docLabel.BackColor == Color.YellowGreen)
                {
                    string fileName   = System.IO.Path.GetFileName(doc);
                    string targetPath = this.buyHelpPath + "\\" + this.id + "\\";
                    System.IO.Directory.Delete(targetPath, true);
                    System.IO.Directory.CreateDirectory(targetPath);
                    string destFile = System.IO.Path.Combine(targetPath, fileName);
                    System.IO.File.Copy(doc, destFile, false);
                    SqlCommand cmdupdatefile = new SqlCommand("BEGIN TRY begin tran t1; delete from doc where id = @id; insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @sdate, @dtype); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmdupdatefile.Parameters.AddWithValue("@id", this.id);
                    cmdupdatefile.Parameters.AddWithValue("@dname", fileName);
                    cmdupdatefile.Parameters.AddWithValue("@dpath", destFile);
                    cmdupdatefile.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                    cmdupdatefile.Parameters.AddWithValue("@dtype", "buyHelp");
                    cmdupdatefile.ExecuteNonQuery();
                }
                SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update buyHelps set type = @typ, fee = @fee, packet = @pack, buydate = @bdate, subdate = @sdate, buyerName = @buname, bankAccountId = @bId, bankAccountName = @bName, description = @des where id = @id; insert into buyHelpsHistory (id, type, fee, packet, buydate, subdate, buyerName, bankAccountId, bankAccountName, description, enactmentId) Values(@id, @typ, @fee, @pack, @bdate, @sdate, @buName, @bId, @bName, @des, @eId); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmd.Parameters.AddWithValue("@id", this.id);
                cmd.Parameters.AddWithValue("@typ", typeComboBox.Text);
                cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@pack", packetNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@bdate", buyDateTimePickerX.SelectedDateInDateTime.Date);
                cmd.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                cmd.Parameters.AddWithValue("@buName", buyerNameTextBox.Text);
                cmd.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                cmd.Parameters.AddWithValue("@bName", bankAccountNameComboBox.Text);
                cmd.Parameters.AddWithValue("@newst", stock - feeNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@des", explainTextBox.Text);
                cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
                cmd.ExecuteNonQuery();
            }
            else
            {
                SqlCommand cmdgetam = new SqlCommand("select amount from budgetsCurrencies where typename = @id;", con);
                switch (typeComboBox.Text)
                {
                case "گوشت":
                    cmdgetam.Parameters.AddWithValue("@id", "meat");
                    break;

                case "خواربار":
                    cmdgetam.Parameters.AddWithValue("@id", "grocery");
                    break;

                case "مرغ":
                    cmdgetam.Parameters.AddWithValue("@id", "chicken");
                    break;

                case "متفرقه":
                    cmdgetam.Parameters.AddWithValue("@id", "stock");
                    break;
                }
                using (SqlDataReader reader = cmdgetam.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        amount = reader.GetDecimal(0);
                    }
                }
                if (this.pretype != typeComboBox.Text)
                {
                    cmdgetam = new SqlCommand("select amount from budgetsCurrencies where typename = @id;", con);
                    switch (this.pretype)
                    {
                    case "گوشت":
                        cmdgetam.Parameters.AddWithValue("@id", "meat");
                        break;

                    case "خواربار":
                        cmdgetam.Parameters.AddWithValue("@id", "grocery");
                        break;

                    case "مرغ":
                        cmdgetam.Parameters.AddWithValue("@id", "chicken");
                        break;

                    case "متفرقه":
                        cmdgetam.Parameters.AddWithValue("@id", "stock");
                        break;
                    }
                    using (SqlDataReader reader = cmdgetam.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            preamount = reader.GetDecimal(0);
                        }
                    }
                    if (preamount < preFee)
                    {
                        FMessegeBox.FarsiMessegeBox.Show(String.Format("موجودی {0} برای عودت ارزش ریالی کافی نیست!", this.pretype), "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                        return;
                    }
                }
                else if (preFee > feeNumericUpDown.Value && amount < preFee - feeNumericUpDown.Value)
                {
                    FMessegeBox.FarsiMessegeBox.Show(String.Format("موجودی {0} برای اصلاح کافی نیست!", typeComboBox.Text), "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
                DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ویرایش خرید این کمک اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);
                if (res != DialogResult.Yes)
                {
                    return;
                }

                SqlCommand cmdupam, cmdupst;
                if (this.prebId != ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text))
                {
                    cmdupst = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @st where id = @prev; update bankAccount set stock = @newst where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmdupst.Parameters.AddWithValue("@prev", this.prebId);
                    cmdupst.Parameters.AddWithValue("@st", prestock + preFee);
                    cmdupst.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmdupst.Parameters.AddWithValue("@newst", stock - feeNumericUpDown.Value);
                    cmdupst.ExecuteNonQuery();
                }
                else if (preFee != feeNumericUpDown.Value)
                {
                    cmdupst = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @newst where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmdupst.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmdupst.Parameters.AddWithValue("@newst", stock + preFee - feeNumericUpDown.Value);
                    cmdupst.ExecuteNonQuery();
                }
                if (this.pretype != typeComboBox.Text)
                {
                    cmdupam = new SqlCommand("BEGIN TRY begin tran t1; update budgetsCurrencies set amount = @am where typename = @prev; update budgetsCurrencies set amount = @newam where typename = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    switch (this.pretype)
                    {
                    case "گوشت":
                        cmdupam.Parameters.AddWithValue("@prev", "meat");
                        break;

                    case "خواربار":
                        cmdupam.Parameters.AddWithValue("@prev", "grocery");
                        break;

                    case "مرغ":
                        cmdupam.Parameters.AddWithValue("@prev", "chicken");
                        break;

                    case "متفرقه":
                        cmdupam.Parameters.AddWithValue("@prev", "stock");
                        break;
                    }
                    if (typeComboBox.Text == "گوشت")
                    {
                        cmdupam.Parameters.AddWithValue("@id", "meat");
                    }
                    else if (typeComboBox.Text == "مرغ")
                    {
                        cmdupam.Parameters.AddWithValue("@id", "chicken");
                    }
                    else if (typeComboBox.Text == "خواربار")
                    {
                        cmdupam.Parameters.AddWithValue("@id", "grocery");
                    }
                    else if (typeComboBox.Text == "متفرقه")
                    {
                        cmdupam.Parameters.AddWithValue("@id", "stock");
                    }
                    cmdupam.Parameters.AddWithValue("@am", preamount - preFee);
                    cmdupam.Parameters.AddWithValue("@newam", amount + feeNumericUpDown.Value);
                    cmdupam.ExecuteNonQuery();
                }
                else if (preFee != feeNumericUpDown.Value)
                {
                    cmdupam = new SqlCommand("BEGIN TRY begin tran t1; update budgetsCurrencies set amount = @newam where typename = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    if (typeComboBox.Text == "گوشت")
                    {
                        cmdupam.Parameters.AddWithValue("@id", "meat");
                    }
                    else if (typeComboBox.Text == "مرغ")
                    {
                        cmdupam.Parameters.AddWithValue("@id", "chicken");
                    }
                    else if (typeComboBox.Text == "خواربار")
                    {
                        cmdupam.Parameters.AddWithValue("@id", "grocery");
                    }
                    else if (typeComboBox.Text == "متفرقه")
                    {
                        cmdupam.Parameters.AddWithValue("@id", "stock");
                    }
                    cmdupam.Parameters.AddWithValue("@newam", amount + feeNumericUpDown.Value - preFee);
                    cmdupam.ExecuteNonQuery();
                }
                if (docLabel.BackColor == Color.YellowGreen)
                {
                    string fileName   = System.IO.Path.GetFileName(doc);
                    string targetPath = this.buyHelpPath + "\\" + this.id + "\\";
                    System.IO.Directory.Delete(targetPath, true);
                    System.IO.Directory.CreateDirectory(targetPath);
                    string destFile = System.IO.Path.Combine(targetPath, fileName);
                    System.IO.File.Copy(doc, destFile, false);
                    SqlCommand cmdupdatefile = new SqlCommand("BEGIN TRY begin tran t1; delete from doc where id = @id; insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @sdate, @dtype); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmdupdatefile.Parameters.AddWithValue("@id", this.id);
                    cmdupdatefile.Parameters.AddWithValue("@dname", fileName);
                    cmdupdatefile.Parameters.AddWithValue("@dpath", destFile);
                    cmdupdatefile.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                    cmdupdatefile.Parameters.AddWithValue("@dtype", "buyHelp");
                    cmdupdatefile.ExecuteNonQuery();
                }
                SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update buyHelps set type = @typ, fee = @fee, packet = @pack, buydate = @bdate, subdate = @sdate, buyerName = @buname, bankAccountId = @bId, bankAccountName = @bName, description = @des where id = @id; insert into buyHelpsHistory (id, type, fee, packet, buydate, subdate, buyerName, bankAccountId, bankAccountName, description, enactmentId) Values(@id, @typ, @fee, @pack, @bdate, @sdate, @buName, @bId, @bName, @des, @eId); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmd.Parameters.AddWithValue("@id", this.id);
                cmd.Parameters.AddWithValue("@typ", typeComboBox.Text);
                cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@pack", packetNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@bdate", buyDateTimePickerX.SelectedDateInDateTime.Date);
                cmd.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                cmd.Parameters.AddWithValue("@buName", buyerNameTextBox.Text);
                cmd.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                cmd.Parameters.AddWithValue("@bName", bankAccountNameComboBox.Text);
                cmd.Parameters.AddWithValue("@newst", stock - feeNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@des", explainTextBox.Text);
                cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
                cmd.ExecuteNonQuery();
            }
            FMessegeBox.FarsiMessegeBox.Show("خرید کمک با موفقیت ویرایش شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            con.Close();
            this.Close();
        }
Ejemplo n.º 17
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(bankAccountNameTextBox.Text))
            {
                bankAccountNameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام حساب وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (!bankAccountNumberTextBox.Text.All(char.IsDigit))
            {
                bankAccountNumberTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("شماره حساب باید فقط شامل ارقام باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(bankNameTextBox.Text))
            {
                bankNameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام بانک وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }

            /*if (!bankNameTextBox.Text.All(c => char.IsWhiteSpace(c) || char.IsLetter(c)))
             * {
             *  bankNameTextBox.BackColor = Color.Tomato;
             *  FMessegeBox.FarsiMessegeBox.Show("نام بانک باید فقط شامل حروف و فاصله باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
             *  return;
             * }*/
            if (String.IsNullOrWhiteSpace(bankAccountOwnerNameTextBox.Text))
            {
                bankAccountOwnerNameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام صاحب حساب وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }

            /*if (!bankAccountOwnerNameTextBox.Text.All(c => char.IsWhiteSpace(c) || char.IsLetter(c)))
             * {
             *  bankAccountOwnerNameTextBox.BackColor = Color.Tomato;
             *  FMessegeBox.FarsiMessegeBox.Show("نام صاحب حساب باید فقط شامل حروف و فاصله باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
             *  return;
             * }*/

            if (String.IsNullOrWhiteSpace(explainTextBox.Text))
            {
                explainTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("توضیحات وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            SqlCommand cmdcheck = new SqlCommand("select id, name from bankAccount;", con);
            List <KeyValuePair <string, string> > li = new List <KeyValuePair <string, string> >();

            using (SqlDataReader reader = cmdcheck.ExecuteReader())
            {
                while (reader.Read())
                {
                    li.Add(new KeyValuePair <string, string>(reader.GetString(0), reader.GetString(0)));
                }
            }
            bool flag = true;

            foreach (var ac in li)
            {
                if (ac.Key == bankAccountNumberTextBox.Text || ac.Value == bankAccountNameTextBox.Text)
                {
                    flag = false;
                    break;
                }
            }
            if (!flag)
            {
                FMessegeBox.FarsiMessegeBox.Show("حساب دیگری با این نام یا شماره حساب موجود است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; insert into bankAccount (id, name, bankName, stock, ownerName) Values(@id, @name, @bname, @st, @oname); insert into backAccountInfoHistory (id, name, bankName, ownerName, subdate, enactmentId, description) Values (@id, @name, @bname, @oname, @sdate, @eId, @des); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);

            cmd.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
            cmd.Parameters.AddWithValue("@name", bankAccountNameTextBox.Text);
            cmd.Parameters.AddWithValue("@bname", bankNameTextBox.Text);
            cmd.Parameters.AddWithValue("@st", 0);
            cmd.Parameters.AddWithValue("@oname", bankAccountOwnerNameTextBox.Text);
            cmd.Parameters.AddWithValue("@sdate", createDateTimePickerX.SelectedDateInDateTime.Date);
            cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
            cmd.Parameters.AddWithValue("@des", "(ایجاد حساب)" + explainTextBox.Text);
            cmd.ExecuteNonQuery();
            con.Close();
            FMessegeBox.FarsiMessegeBox.Show("حساب با موفقیت ثبت شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            this.Close();
        }
        private void addButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(idTextBox.Text))
            {
                idTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("شماره نامه وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(titleTextBox.Text))
            {
                titleTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("عنوان وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(senderTextBox.Text))
            {
                senderTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("فرستنده وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(signerTextBox.Text))
            {
                signerTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("امضاکننده وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (docLabel.BackColor == Color.Red)
            {
                FMessegeBox.FarsiMessegeBox.Show("فایل نامه انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (attachmentCheckBox.Checked && attachmentLabel.BackColor == Color.Red)
            {
                FMessegeBox.FarsiMessegeBox.Show("فایل‌های پیوست انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ویرایش نامه اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);

            if (res != DialogResult.Yes)
            {
                return;
            }

            SqlConnection con = new SqlConnection(this.connection);

            con.Open();

            if (docLabel.BackColor == Color.YellowGreen)
            {
                string fileName = System.IO.Path.GetFileName(doc);
                string iddir    = this.receivedLettersPath + "\\" + this.id;
                System.IO.Directory.CreateDirectory(iddir);
                string targetPath = iddir + "\\" + "doc";
                System.IO.Directory.Delete(targetPath, true);
                System.IO.Directory.CreateDirectory(targetPath);
                string destFile = System.IO.Path.Combine(targetPath, fileName);
                System.IO.File.Copy(doc, destFile, false);
                SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update receivedLetters set id_i = @id_i, title = @title, sender = @sender, signer = @signer, attachment = @attach, recdate = @recdate, subdate = @subdate where id = @id; insert into receivedLettersHistory (id_i, id, title, sender, signer, attachment, recdate, subdate, enactmentId) Values(@id_i, @id, @title, @sender, @signer, @attach, @recdate, @subdate, @eId); delete from doc where id = @id and doctype = 'Letter'; insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @subdate, @dtype); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmd.Parameters.AddWithValue("@id_i", idTextBox.Text);
                cmd.Parameters.AddWithValue("@id", this.id);
                cmd.Parameters.AddWithValue("@title", titleTextBox.Text);
                cmd.Parameters.AddWithValue("@sender", senderTextBox.Text);
                cmd.Parameters.AddWithValue("@signer", signerTextBox.Text);
                cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
                if (attachmentCheckBox.Checked)
                {
                    cmd.Parameters.AddWithValue("@attach", "بله");
                }
                else
                {
                    cmd.Parameters.AddWithValue("@attach", "خیر");
                    SqlCommand cmddel = new SqlCommand("delete from doc where id = @id and doctype = 'LetterAttachment';", con);
                    cmddel.Parameters.AddWithValue("@id", this.id);
                    cmddel.ExecuteNonQuery();
                    if (System.IO.Directory.Exists(this.receivedLettersPath + "\\" + this.id + "\\attachments"))
                    {
                        System.IO.Directory.Delete(this.receivedLettersPath + "\\" + this.id + "\\attachments", true);
                    }
                }
                cmd.Parameters.AddWithValue("@recdate", recDateTimePickerX.SelectedDateInDateTime.Date);
                cmd.Parameters.AddWithValue("@subdate", DateTime.Now.Date);
                cmd.Parameters.AddWithValue("@dname", fileName);
                cmd.Parameters.AddWithValue("@dpath", destFile);
                cmd.Parameters.AddWithValue("@dtype", "Letter");
                cmd.ExecuteNonQuery();
            }
            else
            {
                SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update receivedLetters set id_i = @id_i, title = @title, sender = @sender, signer = @signer, attachment = @attach, recdate = @recdate, subdate = @subdate where id = @id; insert into receivedLettersHistory (id_i, id, title, sender, signer, attachment, recdate, subdate, enactmentId) Values(@id_i, @id, @title, @sender, @signer, @attach, @recdate, @subdate, @eId); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmd.Parameters.AddWithValue("@id_i", idTextBox.Text);
                cmd.Parameters.AddWithValue("@id", this.id);
                cmd.Parameters.AddWithValue("@title", titleTextBox.Text);
                cmd.Parameters.AddWithValue("@sender", senderTextBox.Text);
                cmd.Parameters.AddWithValue("@signer", signerTextBox.Text);
                cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
                if (attachmentCheckBox.Checked)
                {
                    cmd.Parameters.AddWithValue("@attach", "بله");
                }
                else
                {
                    cmd.Parameters.AddWithValue("@attach", "خیر");
                    SqlCommand cmddel = new SqlCommand("delete from doc where id = @id and doctype = 'LetterAttachment';", con);
                    cmddel.Parameters.AddWithValue("@id", this.id);
                    cmddel.ExecuteNonQuery();
                    if (System.IO.Directory.Exists(this.receivedLettersPath + "\\" + this.id + "\\attachments"))
                    {
                        System.IO.Directory.Delete(this.receivedLettersPath + "\\" + this.id + "\\attachments", true);
                    }
                }
                cmd.Parameters.AddWithValue("@recdate", recDateTimePickerX.SelectedDateInDateTime.Date);
                cmd.Parameters.AddWithValue("@subdate", DateTime.Now.Date);
                cmd.ExecuteNonQuery();
            }
            con.Close();
            FMessegeBox.FarsiMessegeBox.Show("نامه دریافتی با موفقیت ویرایش شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            this.Close();
        }
Ejemplo n.º 19
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(idTextBox.Text))
            {
                idTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("شماره ملی مددکار وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (!idTextBox.Text.All(char.IsDigit) || idTextBox.TextLength != 10)
            {
                idTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("شماره ملی مددکار باید فقط شامل ارقام و 10 رقم باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(nameTextBox.Text))
            {
                nameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام مددکار وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (!nameTextBox.Text.All(c => char.IsWhiteSpace(c) || char.IsLetter(c)))
            {
                nameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام مددکار باید فقط شامل حروف و فاصله باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(familyTextBox.Text))
            {
                familyTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام خانوادگی مددکار وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (!familyTextBox.Text.All(c => char.IsWhiteSpace(c) || char.IsLetter(c)))
            {
                familyTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام خانوادگی مددکار باید فقط شامل حروف و فاصله باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(phoneTextBox.Text))
            {
                phoneTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("شماره تلفن مددکار وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (!phoneTextBox.Text.All(char.IsDigit))
            {
                phoneTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("شماره تلفن مددکار باید فقط شامل ارقام و 10 رقم باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(addressTextBox.Text))
            {
                addressTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("آدرس مددکار وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ویرایش این مددکار اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);

            if (res != DialogResult.Yes)
            {
                return;
            }
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; delete from helper where id = @prev; insert into helper(id, name, family, phone, address, subdate) Values(@id, @name, @family, @phone, @address, @sdate); insert into helperInfoHistory (id, name, family, phone, address, subdate) Values(@id, @name, @family, @phone, @address, @sdate); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);

            cmd.Parameters.AddWithValue("@prev", this.id);
            cmd.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(idTextBox.Text));
            cmd.Parameters.AddWithValue("@name", nameTextBox.Text);
            cmd.Parameters.AddWithValue("@family", familyTextBox.Text);
            cmd.Parameters.AddWithValue("@phone", ExtensionFunction.PersianToEnglish(phoneTextBox.Text));
            cmd.Parameters.AddWithValue("@address", addressTextBox.Text);
            cmd.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
            cmd.ExecuteNonQuery();
            FMessegeBox.FarsiMessegeBox.Show("اطلاعات مددکار با موفقیت ویرایش شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            con.Close();
            this.Close();
        }
Ejemplo n.º 20
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(idTextBox.Text))
            {
                idTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("شماره نامه وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(titleTextBox.Text))
            {
                titleTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("عنوان وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(senderTextBox.Text))
            {
                senderTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("فرستنده وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(signerTextBox.Text))
            {
                signerTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("امضاکننده وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (docLabel.BackColor == Color.Red)
            {
                FMessegeBox.FarsiMessegeBox.Show("فایل نامه انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (attachmentCheckBox.Checked && attachmentLabel.BackColor == Color.Red)
            {
                FMessegeBox.FarsiMessegeBox.Show("فایل‌های پیوست انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ثبت نامه اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);

            if (res != DialogResult.Yes)
            {
                return;
            }
            this.id = "RL" + ExtensionFunction.PersianToEnglish(idTextBox.Text);
            string fileName = System.IO.Path.GetFileName(doc);
            string iddir    = this.receivedLettersPath + "\\" + this.id;

            System.IO.Directory.CreateDirectory(iddir);
            string targetPath = iddir + "\\" + "doc";

            System.IO.Directory.CreateDirectory(targetPath);
            string destFile = System.IO.Path.Combine(targetPath, fileName);

            System.IO.File.Copy(doc, destFile, false);
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; insert into receivedLetters (id_i, id, title, sender, signer, attachment, recdate, subdate) Values(@id_i, @id, @title, @sender, @signer, @attach, @recdate, @subdate); insert into receivedLettersHistory (id_i, id, title, sender, signer, attachment, recdate, subdate) Values(@id_i, @id, @title, @sender, @signer, @attach, @recdate, @subdate); insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @subdate, @dtype); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);

            cmd.Parameters.AddWithValue("@id", this.id);
            cmd.Parameters.AddWithValue("@id_i", idTextBox.Text);
            cmd.Parameters.AddWithValue("@title", titleTextBox.Text);
            cmd.Parameters.AddWithValue("@sender", senderTextBox.Text);
            cmd.Parameters.AddWithValue("@signer", signerTextBox.Text);
            if (attachmentCheckBox.Checked)
            {
                cmd.Parameters.AddWithValue("@attach", "بله");
            }
            else
            {
                cmd.Parameters.AddWithValue("@attach", "خیر");
            }
            cmd.Parameters.AddWithValue("@recdate", recDateTimePickerX.SelectedDateInDateTime.Date);
            cmd.Parameters.AddWithValue("@subdate", DateTime.Now.Date);
            cmd.Parameters.AddWithValue("@dname", fileName);
            cmd.Parameters.AddWithValue("@dpath", destFile);
            cmd.Parameters.AddWithValue("@dtype", "Letter");
            cmd.ExecuteNonQuery();
            if (attachmentCheckBox.Checked)
            {
                this.attachments = attli.ToArray();
                foreach (string attachment in this.attachments)
                {
                    int i = 2;
                    fileName   = System.IO.Path.GetFileName(attachment);
                    targetPath = iddir + "\\" + "attachments";
                    System.IO.Directory.CreateDirectory(targetPath);
                    destFile = System.IO.Path.Combine(targetPath, fileName);
                    while (System.IO.File.Exists(destFile))
                    {
                        destFile = System.IO.Path.Combine(targetPath, fileName + "(" + i.ToString() + ")");
                        i++;
                    }
                    System.IO.File.Copy(doc, destFile, false);
                    SqlCommand cmdattach = new SqlCommand("insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @subdate, @dtype);", con);
                    cmdattach.Parameters.AddWithValue("@id", this.id);
                    cmdattach.Parameters.AddWithValue("@subdate", DateTime.Now.Date);
                    cmdattach.Parameters.AddWithValue("@dname", fileName);
                    cmdattach.Parameters.AddWithValue("@dpath", destFile);
                    cmdattach.Parameters.AddWithValue("@dtype", "LetterAttachment");
                    cmdattach.ExecuteNonQuery();
                }
            }
            con.Close();
            FMessegeBox.FarsiMessegeBox.Show("نامه دریافتی با موفقیت ثبت شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            this.Close();
        }
Ejemplo n.º 21
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (!helperIdTextbox.Text.All(char.IsDigit) || helperIdTextbox.TextLength != 10)
            {
                helperIdTextbox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("شناسه ملی اهداکننده باید فقط شامل ارقام و 10 رقم باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (!String.IsNullOrWhiteSpace(helperIdTextbox.Text) && String.IsNullOrWhiteSpace(helperNameTextBox.Text))
            {
                helperIdTextbox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("شماره ملی وارد شده ولی نام اهداکننده بررسی نشده یا وجود ندارد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(explainTextBox.Text))
            {
                explainTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("ذکر توضیحات الزامی است. توضیحی وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }

            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            decimal stock = 0, prestock = 0;

            if (cashRadioButton.Checked && this.precashtype == "نقدی")
            {
                SqlCommand cmdget = new SqlCommand("select stock from bankAccount where id = @id", con);
                cmdget.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        stock = reader.GetDecimal(0);
                    }
                }
                if (this.prebId != ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text))
                {
                    SqlCommand cmdget2 = new SqlCommand("select stock from bankAccount where id = @id", con);
                    cmdget2.Parameters.AddWithValue("@id", this.prebId);
                    using (SqlDataReader reader = cmdget2.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            prestock = reader.GetDecimal(0);
                        }
                    }
                }
            }
            else if (cashRadioButton.Checked && this.precashtype != "نقدی")
            {
                SqlCommand cmdget = new SqlCommand("select stock from bankAccount where id = @id", con);
                cmdget.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        stock = reader.GetDecimal(0);
                    }
                }
                SqlCommand cmdget2 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                switch (typeTextBox.Text)
                {
                case "گوشت":
                    cmdget2.Parameters.AddWithValue("@id", "meat");
                    break;

                case "خواربار":
                    cmdget2.Parameters.AddWithValue("@id", "grocery");
                    break;

                case "مرغ":
                    cmdget2.Parameters.AddWithValue("@id", "chicken");
                    break;

                case "ازدواج":
                    cmdget2.Parameters.AddWithValue("@id", "marry");
                    break;

                case "ایتام":
                    cmdget2.Parameters.AddWithValue("@id", "orphan");
                    break;

                case "متفرقه":
                    cmdget2.Parameters.AddWithValue("@id", "stock");
                    break;
                }
                using (SqlDataReader reader = cmdget2.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        prestock = reader.GetDecimal(0);
                    }
                }
            }
            else if (!cashRadioButton.Checked && this.precashtype == "نقدی")
            {
                SqlCommand cmdget2 = new SqlCommand("select stock from bankAccount where id = @id", con);
                cmdget2.Parameters.AddWithValue("@id", this.prebId);
                using (SqlDataReader reader = cmdget2.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        prestock = reader.GetDecimal(0);
                    }
                }
                SqlCommand cmdget = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                switch (typeTextBox.Text)
                {
                case "گوشت":
                    cmdget.Parameters.AddWithValue("@id", "meat");
                    break;

                case "خواربار":
                    cmdget.Parameters.AddWithValue("@id", "grocery");
                    break;

                case "مرغ":
                    cmdget.Parameters.AddWithValue("@id", "chicken");
                    break;

                case "ازدواج":
                    cmdget.Parameters.AddWithValue("@id", "marry");
                    break;

                case "ایتام":
                    cmdget.Parameters.AddWithValue("@id", "orphan");
                    break;

                case "متفرقه":
                    cmdget.Parameters.AddWithValue("@id", "stock");
                    break;
                }
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        stock = reader.GetDecimal(0);
                    }
                }
            }
            else
            {
                SqlCommand cmdget = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                switch (typeTextBox.Text)
                {
                case "گوشت":
                    cmdget.Parameters.AddWithValue("@id", "meat");
                    break;

                case "خواربار":
                    cmdget.Parameters.AddWithValue("@id", "grocery");
                    break;

                case "مرغ":
                    cmdget.Parameters.AddWithValue("@id", "chicken");
                    break;

                case "ازدواج":
                    cmdget.Parameters.AddWithValue("@id", "marry");
                    break;

                case "ایتام":
                    cmdget.Parameters.AddWithValue("@id", "orphan");
                    break;

                case "متفرقه":
                    cmdget.Parameters.AddWithValue("@id", "stock");
                    break;
                }
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        stock = reader.GetDecimal(0);
                    }
                }
            }
            if ((this.precashtype == "نقدی" && (nonCashRadioButton.Checked || this.prebId != ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text))) || (this.precashtype == "غیرنقدی" && cashRadioButton.Checked))
            {
                if (prestock < preFee)
                {
                    FMessegeBox.FarsiMessegeBox.Show("موجودی حساب قبلی از ارزش ریالی ثبت شده قبلی کمتر می‌باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
            }
            if ((this.precashtype == "نقدی" && cashRadioButton.Checked) || (this.precashtype == "غیرنقدی" && nonCashRadioButton.Checked))
            {
                if (feeNumericUpDown.Value < preFee && stock < preFee - feeNumericUpDown.Value)
                {
                    FMessegeBox.FarsiMessegeBox.Show("موجودی برای ویرایش کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
            }

            DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ثبت دریافت این کمک اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);

            if (res != DialogResult.Yes)
            {
                return;
            }
            if (docLabel.BackColor == Color.YellowGreen)
            {
                string fileName   = System.IO.Path.GetFileName(doc);
                string targetPath = this.recHelpPath + "\\" + this.id + "\\";
                System.IO.Directory.Delete(targetPath, true);
                System.IO.Directory.CreateDirectory(targetPath);
                string destFile = System.IO.Path.Combine(targetPath, fileName);
                System.IO.File.Copy(doc, destFile, false);
                SqlCommand cmdupdatefile = new SqlCommand("BEGIN TRY begin tran t1; delete from doc where id = @id; insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @sdate, @dtype); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmdupdatefile.Parameters.AddWithValue("@id", this.id);
                cmdupdatefile.Parameters.AddWithValue("@dname", fileName);
                cmdupdatefile.Parameters.AddWithValue("@dpath", destFile);
                cmdupdatefile.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                cmdupdatefile.Parameters.AddWithValue("@dtype", "recHelp");
                cmdupdatefile.ExecuteNonQuery();
            }

            SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update recHelps set fee = @fee, packet = @pack, recdate = @rdate, subdate = @sdate, helperId = @hId, helperName = @hName, bankAccountId = @bId, bankAccountName = @bName, description = @des, cashtype = @cashtype where id = @id; insert into recHelpsHistory (id, type, fee, packet, recdate, subdate, helperId, helperName, bankAccountId, bankAccountName, description, enactmentId, cashtype) Values(@id, @typ, @fee, @pack, @rdate, @sdate, @hId, @hName, @bId, @bName, @des, @eId, @cashtype); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);

            cmd.Parameters.AddWithValue("@id", this.id);
            cmd.Parameters.AddWithValue("@typ", typeTextBox.Text);
            cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
            cmd.Parameters.AddWithValue("@pack", packetNumericUpDown.Value);
            cmd.Parameters.AddWithValue("@rdate", recDateTimePickerX.SelectedDateInDateTime.Date);
            cmd.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
            cmd.Parameters.AddWithValue("@hId", ExtensionFunction.PersianToEnglish(helperIdTextbox.Text));
            cmd.Parameters.AddWithValue("@hName", helperNameTextBox.Text);
            cmd.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
            cmd.Parameters.AddWithValue("@bName", bankAccountNameComboBox.Text);
            cmd.Parameters.AddWithValue("@des", explainTextBox.Text);
            cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
            if (cashRadioButton.Checked)
            {
                cmd.Parameters.AddWithValue("@cashtype", "نقدی");
            }
            else
            {
                cmd.Parameters.AddWithValue("@cashtype", "غیرنقدی");
            }
            cmd.ExecuteNonQuery();
            SqlCommand cmd2;

            if (this.precashtype == "نقدی" && cashRadioButton.Checked)
            {
                if (this.prebId != ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text))
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @st where id = @prev; update bankAccount set stock = @newst where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", this.prebId);
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else
                {
                    cmd2 = new SqlCommand("update bankAccount set stock = @st where id = @id;", con);
                    cmd2.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmd2.Parameters.AddWithValue("@st", stock - (preFee - feeNumericUpDown.Value));
                    cmd2.ExecuteNonQuery();
                }
            }
            else if (typeTextBox.Text == "گوشت")
            {
                if (this.precashtype == "نقدی" && nonCashRadioButton.Checked)
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @st where id = @prev; update budgetsCurrencies set amount = @newst where typename = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", this.prebId);
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", "meet");
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else if (this.precashtype == "غیرنقدی" && cashRadioButton.Checked)
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update budgetsCurrencies set amount = @st where typename = @prev; update bankAccount set stock = @st where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", "meet");
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else
                {
                    cmd2 = new SqlCommand("update budgetsCurrencies set amount = @amount where typename = @typ;", con);
                    cmd2.Parameters.AddWithValue("@typ", "meat");
                    cmd2.Parameters.AddWithValue("@amount", stock - (preFee - feeNumericUpDown.Value));
                    cmd2.ExecuteNonQuery();
                }
            }
            else if (typeTextBox.Text == "مرغ")
            {
                if (this.precashtype == "نقدی" && nonCashRadioButton.Checked)
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @st where id = @prev; update budgetsCurrencies set amount = @newst where typename = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", this.prebId);
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", "chicken");
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else if (this.precashtype == "غیرنقدی" && cashRadioButton.Checked)
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update budgetsCurrencies set amount = @st where typename = @prev; update bankAccount set stock = @st where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", "chicken");
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else
                {
                    cmd2 = new SqlCommand("update budgetsCurrencies set amount = @amount where typename = @typ;", con);
                    cmd2.Parameters.AddWithValue("@typ", "chicken");
                    cmd2.Parameters.AddWithValue("@amount", stock - (preFee - feeNumericUpDown.Value));
                    cmd2.ExecuteNonQuery();
                }
            }
            else if (typeTextBox.Text == "خواربار")
            {
                if (this.precashtype == "نقدی" && nonCashRadioButton.Checked)
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @st where id = @prev; update budgetsCurrencies set amount = @newst where typename = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", this.prebId);
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", "grocery");
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else if (this.precashtype == "غیرنقدی" && cashRadioButton.Checked)
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update budgetsCurrencies set amount = @st where typename = @prev; update bankAccount set stock = @st where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", "grocery");
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else
                {
                    cmd2 = new SqlCommand("update budgetsCurrencies set amount = @amount where typename = @typ;", con);
                    cmd2.Parameters.AddWithValue("@typ", "grocery");
                    cmd2.Parameters.AddWithValue("@amount", stock - (preFee - feeNumericUpDown.Value));
                    cmd2.ExecuteNonQuery();
                }
            }
            else if (typeTextBox.Text == "ازدواج")
            {
                if (this.precashtype == "نقدی" && nonCashRadioButton.Checked)
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @st where id = @prev; update budgetsCurrencies set amount = @newst where typename = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", this.prebId);
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", "marry");
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else if (this.precashtype == "غیرنقدی" && cashRadioButton.Checked)
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update budgetsCurrencies set amount = @st where typename = @prev; update bankAccount set stock = @st where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", "marry");
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else
                {
                    cmd2 = new SqlCommand("update budgetsCurrencies set amount = @amount where typename = @typ;", con);
                    cmd2.Parameters.AddWithValue("@typ", "marry");
                    cmd2.Parameters.AddWithValue("@amount", stock - (preFee - feeNumericUpDown.Value));
                    cmd2.ExecuteNonQuery();
                }
            }
            else if (typeTextBox.Text == "ایتام")
            {
                if (this.precashtype == "نقدی" && nonCashRadioButton.Checked)
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @st where id = @prev; update budgetsCurrencies set amount = @newst where typename = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", this.prebId);
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", "orphan");
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else if (this.precashtype == "غیرنقدی" && cashRadioButton.Checked)
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update budgetsCurrencies set amount = @st where typename = @prev; update bankAccount set stock = @st where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", "orphan");
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else
                {
                    cmd2 = new SqlCommand("update budgetsCurrencies set amount = @amount where typename = @typ;", con);
                    cmd2.Parameters.AddWithValue("@typ", "orphan");
                    cmd2.Parameters.AddWithValue("@amount", stock - (preFee - feeNumericUpDown.Value));
                    cmd2.ExecuteNonQuery();
                }
            }
            else if (typeTextBox.Text == "متفرقه")
            {
                if (this.precashtype == "نقدی" && nonCashRadioButton.Checked)
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @st where id = @prev; update budgetsCurrencies set amount = @newst where typename = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", this.prebId);
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", "stock");
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else if (this.precashtype == "غیرنقدی" && cashRadioButton.Checked)
                {
                    cmd2 = new SqlCommand("BEGIN TRY begin tran t1; update budgetsCurrencies set amount = @st where typename = @prev; update bankAccount set stock = @st where id = @id; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                    cmd2.Parameters.AddWithValue("@prev", "stock");
                    cmd2.Parameters.AddWithValue("@st", prestock - preFee);
                    cmd2.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                    cmd2.Parameters.AddWithValue("@newst", stock + feeNumericUpDown.Value);
                    cmd2.ExecuteNonQuery();
                }
                else
                {
                    cmd2 = new SqlCommand("update budgetsCurrencies set amount = @amount where typename = @typ;", con);
                    cmd2.Parameters.AddWithValue("@typ", "stock");
                    cmd2.Parameters.AddWithValue("@amount", stock - (preFee - feeNumericUpDown.Value));
                    cmd2.ExecuteNonQuery();
                }
            }
            FMessegeBox.FarsiMessegeBox.Show("دریافت کمک با موفقیت ویرایش شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            con.Close();
            this.Close();
        }
Ejemplo n.º 22
0
        private void setButton_Click(object sender, EventArgs e)
        {
            var newform = new editSendingLetterForm2(ExtensionFunction.PersianToEnglish(idTextbox.Text));

            newform.ShowDialog(this);
        }
Ejemplo n.º 23
0
 private void bankAccountNameComboBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     bankAccountNumberTextBox.Text = ExtensionFunction.PersianToEnglish(li[bankAccountNameComboBox.SelectedIndex].Key);
 }
        private void addButton_Click(object sender, EventArgs e)
        {
            if (srcBankAccountNameComboBox.Enabled && srcBankAccountNameComboBox.SelectedIndex == -1)
            {
                FMessegeBox.FarsiMessegeBox.Show("حساب مبدا انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (dstBankAccountNameComboBox.Enabled && dstBankAccountNameComboBox.SelectedIndex == -1)
            {
                FMessegeBox.FarsiMessegeBox.Show("حساب مقصد انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (srcBankAccountNameComboBox.Enabled && dstBankAccountNameComboBox.Enabled && srcBankAccountNameComboBox.SelectedIndex == dstBankAccountNameComboBox.SelectedIndex)
            {
                FMessegeBox.FarsiMessegeBox.Show("حساب مبدا و مقصد نمی‌تواند یکسان باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(transporterNameTextBox.Text))
            {
                transporterNameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام انتقال‌دهنده وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (!transporterNameTextBox.Text.All(c => char.IsWhiteSpace(c) || char.IsLetter(c)))
            {
                transporterNameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام انتقال‌دهنده باید فقط شامل حروف و فاصله باشد!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (docLabel.BackColor == Color.Red)
            {
                FMessegeBox.FarsiMessegeBox.Show("فایل رسید انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(explainTextBox.Text))
            {
                explainTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("توضیحات وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }

            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            SqlCommand cmdgetstock = new SqlCommand("select stock from bankAccount where id = @id;", con);
            decimal    srcstock    = 0;

            cmdgetstock.Parameters.AddWithValue("@id", li[srcBankAccountNameComboBox.SelectedIndex].Key);
            using (SqlDataReader reader = cmdgetstock.ExecuteReader())
            {
                if (reader.Read())
                {
                    srcstock = reader.GetDecimal(0);
                }
            }
            decimal    dststock = 0;
            SqlCommand cmdget   = new SqlCommand("select stock from bankAccount where id = @id", con);

            cmdget.Parameters.AddWithValue("@id", li[dstBankAccountNameComboBox.SelectedIndex].Key);
            using (SqlDataReader reader = cmdget.ExecuteReader())
            {
                if (reader.Read())
                {
                    dststock = reader.GetDecimal(0);
                }
            }

            if (preFee + preTax < (feeNumericUpDown.Value + taxNumericUpDown.Value) && srcstock < (feeNumericUpDown.Value + taxNumericUpDown.Value) - (preFee + preTax))
            {
                FMessegeBox.FarsiMessegeBox.Show(String.Format("موجودی حساب مبدا {0} ریال و ما به تفاوت {0} ریال است و موجودی کافی نیست!", srcstock, (feeNumericUpDown.Value + taxNumericUpDown.Value) - (preFee + preTax)), "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            else if (preFee + preTax > (feeNumericUpDown.Value + taxNumericUpDown.Value) && dststock < (preFee + preTax) - (feeNumericUpDown.Value + taxNumericUpDown.Value))
            {
                FMessegeBox.FarsiMessegeBox.Show(String.Format("موجودی حساب مقصد {0} ریال و ما به تفاوت {0} ریال است و موجودی کافی نیست!", srcstock, (feeNumericUpDown.Value + taxNumericUpDown.Value) - (preFee + preTax)), "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }

            DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ویرایش انتقال اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);

            if (res != DialogResult.Yes)
            {
                return;
            }

            if (docLabel.BackColor == Color.YellowGreen)
            {
                string fileName   = System.IO.Path.GetFileName(doc);
                string targetPath = this.moneyTransferPath + "\\" + this.id + "\\";
                System.IO.Directory.Delete(targetPath, true);
                System.IO.Directory.CreateDirectory(targetPath);
                string destFile = System.IO.Path.Combine(targetPath, fileName);
                System.IO.File.Copy(doc, destFile, false);
                SqlCommand cmdupdatefile = new SqlCommand("BEGIN TRY begin tran t1; delete from doc where id = @id; insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @sdate, @dtype); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmdupdatefile.Parameters.AddWithValue("@id", this.id);
                cmdupdatefile.Parameters.AddWithValue("@dname", fileName);
                cmdupdatefile.Parameters.AddWithValue("@dpath", destFile);
                cmdupdatefile.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                cmdupdatefile.Parameters.AddWithValue("@dtype", "moneyTransfer");
                cmdupdatefile.ExecuteNonQuery();
            }

            if (srcBankAccountNameComboBox.Text != "حساب حذف شده" && srcBankAccountNameComboBox.Text != "حساب حذف شده" && (preFee + preTax != (feeNumericUpDown.Value + taxNumericUpDown.Value)))
            {
                SqlCommand cmdupdate = new SqlCommand("BEGIN TRY begin tran t1; update bankAccount set stock = @srcst where id = @srcid; update bankAccount set stock = @dstst where id = @dstid; update moneyTransfer set fee = @fee, tax = @tax, transporterName = @tname, subdate = @sdate, transferdate = @tdate, description = @des where id = @id; insert into moneyTransferHistory (id, srcid, dstid, fee, tax, transporterName, subdate, transferdate, enactmentId, description) Values (@id, @srcid, @dstid, @fee, @tax, @tname, @sdate, @tdate, @eId, @des); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmdupdate.Parameters.AddWithValue("@srcst", srcstock - ((feeNumericUpDown.Value + taxNumericUpDown.Value) - (preFee + preTax)));
                cmdupdate.Parameters.AddWithValue("@dstst", dststock - ((preFee + preTax) - (feeNumericUpDown.Value + taxNumericUpDown.Value)));
                cmdupdate.Parameters.AddWithValue("@srcid", li[srcBankAccountNameComboBox.SelectedIndex].Key);
                cmdupdate.Parameters.AddWithValue("@dstid", li[dstBankAccountNameComboBox.SelectedIndex].Key);
                cmdupdate.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                cmdupdate.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
                cmdupdate.Parameters.AddWithValue("@tax", taxNumericUpDown.Value);
                cmdupdate.Parameters.AddWithValue("@tname", transporterNameTextBox.Text);
                cmdupdate.Parameters.AddWithValue("@id", this.id);
                cmdupdate.Parameters.AddWithValue("@tdate", transferDateTimePickerX.SelectedDateInDateTime.Date);
                cmdupdate.Parameters.AddWithValue("@des", explainTextBox.Text);
                cmdupdate.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
                cmdupdate.ExecuteNonQuery();
            }
            else
            {
                SqlCommand cmdupdate = new SqlCommand("BEGIN TRY begin tran t1; update moneyTransfer set transporterName = @tname, subdate = @sdate, transferdate = @tdate, description = @des where id = @id; insert into moneyTransferHistory (id, srcid, dstid, fee, tax, transporterName, subdate, transferdate, enactmentId, description) Values (@id, @srcid, @dstid, @fee, @tax, @tname, @sdate, @tdate, @eId, @des); commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmdupdate.Parameters.AddWithValue("@srcid", li[srcBankAccountNameComboBox.SelectedIndex].Key);
                cmdupdate.Parameters.AddWithValue("@dstid", li[dstBankAccountNameComboBox.SelectedIndex].Key);
                cmdupdate.Parameters.AddWithValue("@id", this.id);
                cmdupdate.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
                cmdupdate.Parameters.AddWithValue("@tax", taxNumericUpDown.Value);
                cmdupdate.Parameters.AddWithValue("@tname", transporterNameTextBox.Text);
                cmdupdate.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                cmdupdate.Parameters.AddWithValue("@tdate", transferDateTimePickerX.SelectedDateInDateTime.Date);
                cmdupdate.Parameters.AddWithValue("@des", explainTextBox.Text);
                cmdupdate.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
                cmdupdate.ExecuteNonQuery();
            }
            con.Close();
            FMessegeBox.FarsiMessegeBox.Show("انتقال با موفقیت ویرایش شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            this.Close();
        }
 private void setButton_Click(object sender, EventArgs e)
 {
     if (this.Text == "تایید کمک متفرقه فردی")
     {
         SqlConnection con = new SqlConnection(this.connection);
         con.Open();
         decimal    budget = 0, consume = 0, stock = 0, familyBudget = 0;
         SqlCommand cmdget  = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
         SqlCommand cmdget2 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
         SqlCommand cmdget3 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
         cmdget.Parameters.AddWithValue("@id", "othersBudget");
         cmdget2.Parameters.AddWithValue("@id", "othersConsume");
         cmdget3.Parameters.AddWithValue("@id", "stock");
         using (SqlDataReader reader = cmdget.ExecuteReader())
         {
             if (reader.Read())
             {
                 budget = reader.GetDecimal(0);
             }
         }
         using (SqlDataReader reader = cmdget2.ExecuteReader())
         {
             if (reader.Read())
             {
                 consume = reader.GetDecimal(0);
             }
         }
         using (SqlDataReader reader = cmdget3.ExecuteReader())
         {
             if (reader.Read())
             {
                 stock = reader.GetDecimal(0);
             }
         }
         if (feeNumericUpDown.Value > this.fee && consume + feeNumericUpDown.Value - this.fee > budget)
         {
             FMessegeBox.FarsiMessegeBox.Show("این درخواست خارج از محدوده بودجه تعریف شده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
             return;
         }
         else if (feeNumericUpDown.Value > this.fee && feeNumericUpDown.Value - this.fee > stock)
         {
             FMessegeBox.FarsiMessegeBox.Show("موجودی کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
             return;
         }
         else
         {
             DialogResult dr = FMessegeBox.FarsiMessegeBox.Show("با تایید کمک، ویرایش اعمال پیش از تایید غیر ممکن خواهد شد. آیا نسبت به تایید اطمینان دارید؟", "هشدار!", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);
             if (dr != DialogResult.Yes)
             {
                 return;
             }
             SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update OtherHelpsIndiv Set confirmdescription = @des, confirmdate = @cdate, status = @stat, fee = @fee, fenactmentId = @feId where id = @id; update budgetsCurrencies Set amount = @amount2 where typename = @tname2; update budgetsCurrencies Set amount = @amount3 where typename = @tname3; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
             cmd.Parameters.AddWithValue("@id", this.id);
             cmd.Parameters.AddWithValue("@des", "(توضیحات تایید: " + explainTextBox2.Text + ")");
             cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
             cmd.Parameters.AddWithValue("@feId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
             cmd.Parameters.AddWithValue("@cdate", DateTime.Now.Date);
             cmd.Parameters.AddWithValue("@stat", "نهایی");
             cmd.Parameters.AddWithValue("@amount2", consume + feeNumericUpDown.Value - this.fee);
             cmd.Parameters.AddWithValue("@tname2", "othersConsume");
             cmd.Parameters.AddWithValue("@amount3", stock - feeNumericUpDown.Value + this.fee);
             cmd.Parameters.AddWithValue("@tname3", "stock");
             cmd.ExecuteNonQuery();
             con.Close();
             FMessegeBox.FarsiMessegeBox.Show("کمک با موفقیت تایید و نهایی شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
             this.Close();
         }
     }
     else
     {
         SqlConnection con = new SqlConnection(this.connection);
         con.Open();
         decimal    budget = 0, consume = 0, stock = 0, familyBudget = 0;
         SqlCommand cmdget  = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
         SqlCommand cmdget2 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
         SqlCommand cmdget3 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
         cmdget.Parameters.AddWithValue("@id", "othersBudget");
         cmdget2.Parameters.AddWithValue("@id", "othersConsume");
         cmdget3.Parameters.AddWithValue("@id", "stock");
         using (SqlDataReader reader = cmdget.ExecuteReader())
         {
             if (reader.Read())
             {
                 budget = reader.GetDecimal(0);
             }
         }
         using (SqlDataReader reader = cmdget2.ExecuteReader())
         {
             if (reader.Read())
             {
                 consume = reader.GetDecimal(0);
             }
         }
         using (SqlDataReader reader = cmdget3.ExecuteReader())
         {
             if (reader.Read())
             {
                 stock = reader.GetDecimal(0);
             }
         }
         if (feeNumericUpDown.Value > this.fee && consume + feeNumericUpDown.Value - this.fee > budget)
         {
             FMessegeBox.FarsiMessegeBox.Show("این درخواست خارج از محدوده بودجه تعریف شده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
             return;
         }
         else if (feeNumericUpDown.Value > this.fee && feeNumericUpDown.Value - this.fee > stock)
         {
             FMessegeBox.FarsiMessegeBox.Show("موجودی کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
             return;
         }
         else
         {
             SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; update OtherHelpsIndiv Set confirmdescription = @des, fee = @fee, fenactmentId = @feId where id = @id; update budgetsCurrencies Set amount = @amount2 where typename = @tname2; update budgetsCurrencies Set amount = @amount3 where typename = @tname3; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
             cmd.Parameters.AddWithValue("@id", this.id);
             cmd.Parameters.AddWithValue("@des", this.explain + "(توضیحات ویرایش تایید: " + explainTextBox2.Text + ")");
             cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
             cmd.Parameters.AddWithValue("@feId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
             cmd.Parameters.AddWithValue("@amount2", consume + feeNumericUpDown.Value - this.fee);
             cmd.Parameters.AddWithValue("@tname2", "othersConsume");
             cmd.Parameters.AddWithValue("@amount3", stock - feeNumericUpDown.Value + this.fee);
             cmd.Parameters.AddWithValue("@tname3", "stock");
             cmd.ExecuteNonQuery();
             con.Close();
             FMessegeBox.FarsiMessegeBox.Show("ویرایش تایید کمک با موفقیت انجام شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
             this.Close();
         }
     }
 }
Ejemplo n.º 26
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (typeComboBox.Text.Length == 0)
            {
                FMessegeBox.FarsiMessegeBox.Show("نوع کمک انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(buyerNameTextBox.Text))
            {
                buyerNameTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("نام خریدار وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (docLabel.BackColor == Color.Red)
            {
                FMessegeBox.FarsiMessegeBox.Show("فایل رسید انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (String.IsNullOrWhiteSpace(explainTextBox.Text))
            {
                explainTextBox.BackColor = Color.Tomato;
                FMessegeBox.FarsiMessegeBox.Show("ذکر توضیحات الزامی است. توضیحی وارد نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            if (bankAccountNameComboBox.SelectedIndex == -1)
            {
                FMessegeBox.FarsiMessegeBox.Show("حساب مورد نظر انتخاب نشده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            decimal budget = 0, consume = 0, stock = 0, amount = 0;

            if (typeComboBox.Text == "اداری فرهنگی")
            {
                SqlCommand cmdgetst = new SqlCommand("select stock from bankAccount where id = @id;", con);
                SqlCommand cmdget   = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                SqlCommand cmdget2  = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                cmdget.Parameters.AddWithValue("@id", "cultureBudget");
                cmdget2.Parameters.AddWithValue("@id", "cultureConsume");
                cmdgetst.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        budget = reader.GetDecimal(0);
                    }
                }
                using (SqlDataReader reader = cmdget2.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        consume = reader.GetDecimal(0);
                    }
                }
                using (SqlDataReader reader = cmdgetst.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        stock = reader.GetDecimal(0);
                    }
                }
                if (consume + feeNumericUpDown.Value > budget)
                {
                    FMessegeBox.FarsiMessegeBox.Show("این درخواست خارج از محدوده بودجه تعریف شده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                }
                if (stock < feeNumericUpDown.Value)
                {
                    FMessegeBox.FarsiMessegeBox.Show("موجودی حساب کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
                DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ثبت خرید این کمک اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);
                if (res != DialogResult.Yes)
                {
                    return;
                }
                string     d = DateTime.Now.Date.ToPersian(); d = "Buy" + d.Substring(0, 4) + d.Substring(5, 2) + d.Substring(8, 2);
                SqlCommand cmdgetid = new SqlCommand("select id from recHelps where id like '" + d + "%';", con);
                int        index = 1, mx = 1;
                using (SqlDataReader reader = cmdgetid.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string s = String.Format("{0}", reader["id"]);
                        if (s == "")
                        {
                            index = 1;
                        }
                        else
                        {
                            index = Convert.ToInt32(s.Substring(11)) + 1;
                        }
                        mx = Math.Max(mx, index);
                    }
                }
                d = d + mx.ToString();
                string fileName   = System.IO.Path.GetFileName(doc);
                string targetPath = this.buyHelpPath + "\\" + d + "\\";
                System.IO.Directory.CreateDirectory(targetPath);
                string destFile = System.IO.Path.Combine(targetPath, fileName);
                System.IO.File.Copy(doc, destFile, false);

                SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; insert into buyHelps(id, type, fee, packet, buydate, subdate, buyerName, bankAccountId, bankAccountName, description) Values(@id, @typ, @fee, @pack, @bdate, @sdate, @buName, @bId, @bName, @des); insert into buyHelpsHistory (id, type, fee, packet, buydate, subdate, buyerName, bankAccountId, bankAccountName, description) Values(@id, @typ, @fee, @pack, @bdate, @sdate, @buName, @bId, @bName, @des); insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @sdate, @dtype); update budgetsCurrencies set amount = @amount where typename = @dtyp; update bankAccount set stock = @newst where id = @bId; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmd.Parameters.AddWithValue("@id", d);
                cmd.Parameters.AddWithValue("@typ", typeComboBox.Text);
                cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@pack", packetNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@bdate", buyDateTimePickerX.SelectedDateInDateTime.Date);
                cmd.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                cmd.Parameters.AddWithValue("@buName", buyerNameTextBox.Text);
                cmd.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                cmd.Parameters.AddWithValue("@bName", bankAccountNameComboBox.Text);
                cmd.Parameters.AddWithValue("@newst", stock - feeNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@des", explainTextBox.Text);
                cmd.Parameters.AddWithValue("@dname", fileName);
                cmd.Parameters.AddWithValue("@dpath", destFile);
                cmd.Parameters.AddWithValue("@dtype", "buyHelp");
                cmd.Parameters.AddWithValue("@dtyp", "cultureConsume");
                cmd.Parameters.AddWithValue("@amount", consume + feeNumericUpDown.Value);
                cmd.ExecuteNonQuery();
            }
            else
            {
                SqlCommand cmdgetst = new SqlCommand("select stock from bankAccount where id = @id;", con);
                cmdgetst.Parameters.AddWithValue("@id", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                using (SqlDataReader reader = cmdgetst.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        stock = reader.GetDecimal(0);
                    }
                }
                if (stock < feeNumericUpDown.Value)
                {
                    FMessegeBox.FarsiMessegeBox.Show("موجودی حساب کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                    return;
                }
                DialogResult res = FMessegeBox.FarsiMessegeBox.Show("آیا نسبت به ثبت خرید این کمک اطمینان دارید؟", "پرسش", FMessegeBox.FMessegeBoxButtons.YesNo, FMessegeBox.FMessegeBoxIcons.Question, FMessegeBox.FMessegeBoxDefaultButton.button1);
                if (res != DialogResult.Yes)
                {
                    return;
                }
                string     d = DateTime.Now.Date.ToPersian(); d = "Buy" + d.Substring(0, 4) + d.Substring(5, 2) + d.Substring(8, 2);
                SqlCommand cmdgetid = new SqlCommand("select id from recHelps where id like '" + d + "%';", con);
                int        index = 1, mx = 1;
                using (SqlDataReader reader = cmdgetid.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string s = String.Format("{0}", reader["id"]);
                        if (s == "")
                        {
                            index = 1;
                        }
                        else
                        {
                            index = Convert.ToInt32(s.Substring(11)) + 1;
                        }
                        mx = Math.Max(mx, index);
                    }
                }
                d = d + mx.ToString();
                SqlCommand cmdget = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
                switch (typeComboBox.Text)
                {
                case "گوشت":
                    cmdget.Parameters.AddWithValue("@id", "meat");
                    break;

                case "خواربار":
                    cmdget.Parameters.AddWithValue("@id", "grocery");
                    break;

                case "مرغ":
                    cmdget.Parameters.AddWithValue("@id", "chicken");
                    break;

                case "متفرقه":
                    cmdget.Parameters.AddWithValue("@id", "stock");
                    break;
                }
                using (SqlDataReader reader = cmdget.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        amount = reader.GetDecimal(0);
                    }
                }
                string fileName   = System.IO.Path.GetFileName(doc);
                string targetPath = this.buyHelpPath + "\\" + d + "\\";
                System.IO.Directory.CreateDirectory(targetPath);
                string destFile = System.IO.Path.Combine(targetPath, fileName);
                System.IO.File.Copy(doc, destFile, false);

                SqlCommand cmd = new SqlCommand("BEGIN TRY begin tran t1; insert into buyHelps(id, type, fee, packet, buydate, subdate, buyerName, bankAccountId, bankAccountName, description) Values(@id, @typ, @fee, @pack, @bdate, @sdate, @buName, @bId, @bName, @des); insert into buyHelpsHistory (id, type, fee, packet, buydate, subdate, buyerName, bankAccountId, bankAccountName, description) Values(@id, @typ, @fee, @pack, @bdate, @sdate, @buName, @bId, @bName, @des); insert into doc(id, docname, docpath, subdate, doctype) Values(@id, @dname, @dpath, @sdate, @dtype); update budgetsCurrencies set amount = @amount where typename = @dtyp; update bankAccount set stock = @newst where id = @bId; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmd.Parameters.AddWithValue("@id", d);
                cmd.Parameters.AddWithValue("@typ", typeComboBox.Text);
                cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@pack", packetNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@bdate", buyDateTimePickerX.SelectedDateInDateTime.Date);
                cmd.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                cmd.Parameters.AddWithValue("@buName", buyerNameTextBox.Text);
                cmd.Parameters.AddWithValue("@bId", ExtensionFunction.PersianToEnglish(bankAccountNumberTextBox.Text));
                cmd.Parameters.AddWithValue("@bName", bankAccountNameComboBox.Text);
                cmd.Parameters.AddWithValue("@newst", stock - feeNumericUpDown.Value);
                cmd.Parameters.AddWithValue("@des", explainTextBox.Text);
                cmd.Parameters.AddWithValue("@dname", fileName);
                cmd.Parameters.AddWithValue("@dpath", destFile);
                cmd.Parameters.AddWithValue("@dtype", "buyHelp");

                if (typeComboBox.Text == "گوشت")
                {
                    cmd.Parameters.AddWithValue("@dtyp", "meat");
                    cmd.Parameters.AddWithValue("@amount", amount + feeNumericUpDown.Value);
                }
                else if (typeComboBox.Text == "مرغ")
                {
                    cmd.Parameters.AddWithValue("@dtyp", "chicken");
                    cmd.Parameters.AddWithValue("@amount", amount + feeNumericUpDown.Value);
                }
                else if (typeComboBox.Text == "خواربار")
                {
                    cmd.Parameters.AddWithValue("@dtyp", "grocery");
                    cmd.Parameters.AddWithValue("@amount", amount + feeNumericUpDown.Value);
                }
                else if (typeComboBox.Text == "متفرقه")
                {
                    cmd.Parameters.AddWithValue("@dtyp", "stock");
                    cmd.Parameters.AddWithValue("@amount", amount + feeNumericUpDown.Value);
                }
                cmd.ExecuteNonQuery();
            }


            FMessegeBox.FarsiMessegeBox.Show("خرید کمک با موفقیت ثبت شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
            con.Close();
            this.Close();
        }
Ejemplo n.º 27
0
        private void chooseButton_Click(object sender, EventArgs e)
        {
            var newform = new observeBudgetsetsForm2(ExtensionFunction.PersianToEnglish(membersView.Rows[membersView.SelectedCells[0].RowIndex].Cells[membersView.SelectedCells[0].ColumnIndex].Value.ToString()));

            newform.ShowDialog(this);
        }
Ejemplo n.º 28
0
        private void setButton_Click(object sender, EventArgs e)
        {
            var newform = new reportHelpsForm(this.typ, ExtensionFunction.PersianToEnglish(idTextbox.Text));

            newform.ShowDialog(this);
        }
Ejemplo n.º 29
0
 private void setButton_Click(object sender, EventArgs e)
 {
     if (rad)
     {
         this.Close();
     }
     else
     {
         SqlConnection con = new SqlConnection(this.connection);
         con.Open();
         if (this.Text == "بررسی درخواست کمک ازدواج")
         {
             decimal    budget = 0, consume = 0, stock = 0;
             SqlCommand cmdget  = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
             SqlCommand cmdget2 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
             SqlCommand cmdget3 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
             cmdget.Parameters.AddWithValue("@id", "marryBudget");
             cmdget2.Parameters.AddWithValue("@id", "marryConsume");
             cmdget3.Parameters.AddWithValue("@id", "marry");
             using (SqlDataReader reader = cmdget.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     budget = reader.GetDecimal(0);
                 }
             }
             using (SqlDataReader reader = cmdget2.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     consume = reader.GetDecimal(0);
                 }
             }
             using (SqlDataReader reader = cmdget3.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     stock = reader.GetDecimal(0);
                 }
             }
             if (consume + feeNumericUpDown.Value > budget)
             {
                 FMessegeBox.FarsiMessegeBox.Show("این درخواست خارج از محدوده بودجه تعریف شده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
             }
             else if (typeComboBox.Text == "غیرنقدی" && feeNumericUpDown.Value > stock)
             {
                 FMessegeBox.FarsiMessegeBox.Show("موجودی کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
             }
             else
             {
                 string     d        = DateTime.Now.Date.ToPersian(); d = "M" + d.Substring(0, 4) + d.Substring(5, 2) + d.Substring(8, 2);
                 SqlCommand cmdgetid = new SqlCommand("select id from MarryHelps where id like '" + d + "%';", con);
                 int        index    = 1;
                 using (SqlDataReader reader = cmdgetid.ExecuteReader())
                 {
                     if (reader.Read())
                     {
                         string s = String.Format("{0}", reader["id"]);
                         if (s == "")
                         {
                             index = 1;
                         }
                         else
                         {
                             index = Convert.ToInt32(s.Substring(9)) + 1;
                         }
                     }
                 }
                 d       = d + index.ToString();
                 this.id = d;
                 System.IO.Directory.CreateDirectory(this.helpPath + "\\" + this.id);
                 System.IO.Directory.CreateDirectory(this.helpPath + "\\" + this.id + "\\receipt");
                 SqlCommand cmd;
                 if (typeComboBox.Text == "غیرنقدی")
                 {
                     cmd = new SqlCommand("BEGIN TRY begin tran t1; insert into MarryHelps (id, type, reqId, subdate, description, enactmentId, status, fee) Values (@id, @typ, @rId, @sdate, @des, @eId, @stat, @fee); update MarryHelpReq Set status = @rstat, enactmentId = @eId where id = @rId; update budgetsCurrencies Set amount = @amount2 where typename = @tname2; update budgetsCurrencies Set amount = @amount3 where typename = @tname3; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                     cmd.Parameters.AddWithValue("@amount3", stock - feeNumericUpDown.Value);
                     cmd.Parameters.AddWithValue("@tname3", "marry");
                 }
                 else
                 {
                     cmd = new SqlCommand("BEGIN TRY begin tran t1; insert into MarryHelps (id, type, reqId, subdate, description, enactmentId, status, fee) Values (@id, @typ, @rId, @sdate, @des, @eId, @stat, @fee); update MarryHelpReq Set status = @rstat, enactmentId = @eId where id = @rId; update budgetsCurrencies Set amount = @amount2 where typename = @tname2; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                 }
                 cmd.Parameters.AddWithValue("@id", this.id);
                 cmd.Parameters.AddWithValue("@typ", typeComboBox.Text);
                 cmd.Parameters.AddWithValue("@rId", this.rId);
                 cmd.Parameters.AddWithValue("@sdate", DateTime.Now.Date);
                 cmd.Parameters.AddWithValue("@des", "(توضیحات کمک: " + explainTextBox2.Text + ")");
                 cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
                 if (typeComboBox.Text == "غیرنقدی خیریه دیگر")
                 {
                     cmd.Parameters.AddWithValue("@stat", "ارسال معرفی‌نامه");
                     System.IO.Directory.CreateDirectory(this.helpPath + "\\" + this.id + "\\intro");
                     System.IO.Directory.CreateDirectory(this.helpPath + "\\" + this.id + "\\assignment");
                 }
                 else
                 {
                     cmd.Parameters.AddWithValue("@stat", "ارائه");
                 }
                 cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
                 cmd.Parameters.AddWithValue("@rstat", "تایید");
                 cmd.Parameters.AddWithValue("@amount2", consume + feeNumericUpDown.Value);
                 cmd.Parameters.AddWithValue("@tname2", "marryConsume");
                 cmd.ExecuteNonQuery();
                 FMessegeBox.FarsiMessegeBox.Show("کمک با موفقیت ثبت شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
                 con.Close();
                 this.Close();
             }
         }
         else
         {
             decimal    budget = 0, consume = 0, stock = 0;
             SqlCommand cmdget  = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
             SqlCommand cmdget2 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
             SqlCommand cmdget3 = new SqlCommand("select amount from budgetsCurrencies where typename = @id", con);
             cmdget.Parameters.AddWithValue("@id", "marryBudget");
             cmdget2.Parameters.AddWithValue("@id", "marryConsume");
             cmdget3.Parameters.AddWithValue("@id", "marry");
             using (SqlDataReader reader = cmdget.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     budget = reader.GetDecimal(0);
                 }
             }
             using (SqlDataReader reader = cmdget2.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     consume = reader.GetDecimal(0);
                 }
             }
             using (SqlDataReader reader = cmdget3.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     stock = reader.GetDecimal(0);
                 }
             }
             if (feeNumericUpDown.Value > this.fee && consume + feeNumericUpDown.Value - this.fee > budget)
             {
                 FMessegeBox.FarsiMessegeBox.Show("این درخواست خارج از محدوده بودجه تعریف شده است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                 return;
             }
             else if (typeComboBox.Text == "غیرنقدی" && feeNumericUpDown.Value > this.fee && feeNumericUpDown.Value - this.fee > stock)
             {
                 FMessegeBox.FarsiMessegeBox.Show("موجودی کافی نیست!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                 return;
             }
             else
             {
                 SqlCommand cmd;
                 if (typeComboBox.Text == "غیرنقدی")
                 {
                     cmd = new SqlCommand("BEGIN TRY begin tran t1; update MarryHelps Set description = @des, fee = @fee, enactmentId = @eId where id = @id; update MarryHelpReq Set enactmentId = @eId where id = @rId; update budgetsCurrencies Set amount = @amount2 where typename = @tname2; update budgetsCurrencies Set amount = @amount3 where typename = @tname3; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                     cmd.Parameters.AddWithValue("@amount3", stock - feeNumericUpDown.Value + this.fee);
                     cmd.Parameters.AddWithValue("@tname3", "marry");
                 }
                 else
                 {
                     cmd = new SqlCommand("BEGIN TRY begin tran t1; update MarryHelps Set description = @des, fee = @fee, enactmentId = @eId where id = @id; update MarryHelpReq Set enactmentId = @eId where id = @rId; update budgetsCurrencies Set amount = @amount2 where typename = @tname2; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                 }
                 cmd.Parameters.AddWithValue("@id", this.id);
                 cmd.Parameters.AddWithValue("@rId", this.rId);
                 cmd.Parameters.AddWithValue("@des", this.explain + " " + "(توضیحات ویرایش کمک: " + explainTextBox2.Text + ")");
                 cmd.Parameters.AddWithValue("@eId", ExtensionFunction.PersianToEnglish(enactmentTextbox.Text));
                 cmd.Parameters.AddWithValue("@fee", feeNumericUpDown.Value);
                 cmd.Parameters.AddWithValue("@amount2", consume + feeNumericUpDown.Value - this.fee);
                 cmd.Parameters.AddWithValue("@tname2", "marryConsume");
                 cmd.ExecuteNonQuery();
                 FMessegeBox.FarsiMessegeBox.Show("کمک با موفقیت ویرایش شد!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
                 con.Close();
                 this.Close();
             }
         }
     }
 }
Ejemplo n.º 30
0
        private void setButton_Click(object sender, EventArgs e)
        {
            var newform = new bankAccountTransferEditForm2(ExtensionFunction.PersianToEnglish(idTextbox.Text));

            newform.ShowDialog(this);
        }