Example #1
0
        private void setButton_Click(object sender, EventArgs e)
        {
            // Display form modelessly
            var waitform = new waitForm();

            waitform.StartPosition = FormStartPosition.Manual;
            waitform.Show(this);

            //  ALlow main UI thread to properly display please wait form.
            Application.DoEvents();
            SqlConnection con = new SqlConnection(this.connection);
            SqlCommand    cmdupparams; NumericUpDown nu;

            con.Open();
            for (int i = 1; i <= 17; i++)
            {
                cmdupparams = new SqlCommand("update parameters Set point = @p where name = @name;", con);
                cmdupparams.Parameters.AddWithValue("@name", parameters[i]);
                nu = (NumericUpDown)this.Controls.Find(parameters[i] + "NumericUpDown", true)[0];
                cmdupparams.Parameters.AddWithValue("@p", nu.Value);
                cmdupparams.ExecuteNonQuery();
            }
            con.Close();
            //update all family rates!
            updateFamilies();

            waitform.Close();
            FMessegeBox.FarsiMessegeBox.Show("فاکتورهای امتیازی و امتیازات خانوارها با موفقیت به روز گردید!", "تبریک!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Information, FMessegeBox.FMessegeBoxDefaultButton.button1);
        }
Example #2
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (memberDataGridView.RowCount + delDataGridView.SelectedCells.Count > this.packs)
            {
                FMessegeBox.FarsiMessegeBox.Show("مجموع تعداد افراد انتخاب شده از تعداد بسته‌های تعریف شده بیشتر است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            // Display form modelessly
            var waitform = new waitForm();

            waitform.StartPosition = FormStartPosition.Manual;
            waitform.Show(this);

            //  ALlow main UI thread to properly display please wait form.
            Application.DoEvents();
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            string folde, mId;

            for (int j = 0; j < delDataGridView.SelectedCells.Count; j++)
            {
                if (this.ctype == "همه خانوارها")
                {
                    mId        = delDataGridView.Rows[delDataGridView.SelectedCells[j].RowIndex].Cells[delDataGridView.SelectedCells[j].ColumnIndex + 4].Value.ToString();
                    folde      = delDataGridView.Rows[delDataGridView.SelectedCells[j].RowIndex].Cells[delDataGridView.SelectedCells[j].ColumnIndex].Value.ToString();
                    di1[folde] = di2[folde];
                    di2.Remove(folde);
                }
                else
                {
                    //FMessegeBox.FarsiMessegeBox.Show(delDataGridView.ColumnCount.ToString() + " " + delDataGridView.SelectedCells[0].RowIndex + " " + delDataGridView.SelectedCells[0].ColumnIndex);
                    mId      = delDataGridView.Rows[delDataGridView.SelectedCells[j].RowIndex].Cells[delDataGridView.SelectedCells[j].ColumnIndex].Value.ToString();
                    folde    = delDataGridView.Rows[delDataGridView.SelectedCells[j].RowIndex].Cells[delDataGridView.SelectedCells[j].ColumnIndex + 4].Value.ToString();
                    di1[mId] = di2[mId];
                    di2.Remove(mId);
                }
                SqlCommand cmdtransfer = new SqlCommand("BEGIN TRY begin tran t1; insert into OtherHelpsGlobalTmpList (hId, supporter_id, folder_id, name, family, fatherName, mId, packets, rate) select hId, supporter_id, folder_id, name, family, fatherName, mId, 1, rate from OtherHelpsGlobalDelList where mId = @mId and folder_id = @fId and hId = @hId; delete from OtherHelpsGlobalDelList where mid = @mId and folder_id = @fId and hId = @hId; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmdtransfer.Parameters.AddWithValue("@hId", this.id);
                cmdtransfer.Parameters.AddWithValue("@fId", folde);
                cmdtransfer.Parameters.AddWithValue("@mId", mId);
                cmdtransfer.ExecuteNonQuery();
            }
            SqlCommand cmdupdate;

            foreach (var dd in di1)
            {
                cmdupdate = new SqlCommand("update OtherHelpsGlobalTmpList Set packets = @packs where mId = @mId and folder_id = @fId and hId = @hId;", con);
                cmdupdate.Parameters.AddWithValue("@hId", this.id);
                if (this.ctype == "همه خانوارها")
                {
                    cmdupdate.Parameters.AddWithValue("@fId", dd.Key);
                    cmdupdate.Parameters.AddWithValue("@mId", dd.Value.Item3);
                }
                else
                {
                    cmdupdate.Parameters.AddWithValue("@fId", dd.Value.Item1);
                    cmdupdate.Parameters.AddWithValue("@mId", dd.Key);
                }
                cmdupdate.Parameters.AddWithValue("@packs", 1);
                cmdupdate.ExecuteNonQuery();
            }
            SqlCommand cmd;

            if (this.ctype == "همه خانوارها")
            {
                cmd = new SqlCommand("select folder_id as 'شماره پرونده', name as 'نام', family as 'نام خانوادگی', fatherName as 'نام پدر', mId as 'شماره ملی', supporter_id as 'شماره ملی سرپرست', cast(rate as decimal(10,3)) as 'امتیاز' from OtherHelpsGlobalTmpList where hId = @hId order by rate desc;", con);
            }
            else
            {
                cmd = new SqlCommand("select mId as 'شماره ملی', name as 'نام', family as 'نام خانوادگی', fatherName as 'نام پدر', folder_id as 'شماره پرونده', supporter_id as 'شماره ملی سرپرست', cast(rate as decimal(10,3)) as 'امتیاز' from OtherHelpsGlobalTmpList where hId = @hId order by rate desc;", con);
            }
            SqlDataAdapter da; DataTable dt;

            cmd.Parameters.AddWithValue("@hId", this.id);
            da = new SqlDataAdapter(cmd);
            dt = new DataTable();
            da.Fill(dt);
            memberDataGridView.DataSource = dt;
            memberDataGridView.Columns[6].DefaultCellStyle.Format = "#,##;#,##-";
            if (this.ctype == "همه خانوارها")
            {
                cmd = new SqlCommand("select folder_id as 'شماره پرونده', name as 'نام', family as 'نام خانوادگی', fatherName as 'نام پدر', mId as 'شماره ملی', supporter_id as 'شماره ملی سرپرست', cast(rate as decimal(10,3)) as 'امتیاز' from OtherHelpsGlobalDelList where hId = @hId order by rate desc;", con);
            }
            else
            {
                cmd = new SqlCommand("select mId as 'شماره ملی', name as 'نام', family as 'نام خانوادگی', fatherName as 'نام پدر', folder_id as 'شماره پرونده', supporter_id as 'شماره ملی سرپرست', cast(rate as decimal(10,3)) as 'امتیاز' from OtherHelpsGlobalDelList where hId = @hId order by rate desc;", con);
            }
            cmd.Parameters.AddWithValue("@hId", this.id);
            da = new SqlDataAdapter(cmd);
            dt = new DataTable();
            da.Fill(dt);
            delDataGridView.DataSource = dt;
            delDataGridView.Columns[6].DefaultCellStyle.Format = "#,##;#,##-";
            con.Close();
            waitform.Close();
        }
        private void addButton_Click(object sender, EventArgs e)
        {
            if (this.type == "نان" && memberDataGridView.RowCount + delDataGridView.SelectedCells.Count > 1)
            {
                FMessegeBox.FarsiMessegeBox.Show("برای کمک نان تنها یک مددجو قابل انتخاب است!", "خطا!", FMessegeBox.FMessegeBoxButtons.Ok, FMessegeBox.FMessegeBoxIcons.Error, FMessegeBox.FMessegeBoxDefaultButton.button1);
                return;
            }
            // Display form modelessly
            var waitform = new waitForm();

            waitform.StartPosition = FormStartPosition.Manual;
            waitform.Show(this);

            //  ALlow main UI thread to properly display please wait form.
            Application.DoEvents();
            SqlConnection con = new SqlConnection(this.connection);

            con.Open();
            string folde;

            for (int j = 0; j < delDataGridView.SelectedCells.Count; j++)
            {
                folde      = delDataGridView.Rows[delDataGridView.SelectedCells[j].RowIndex].Cells[delDataGridView.SelectedCells[j].ColumnIndex].Value.ToString();
                di1[folde] = di2[folde];
                di2.Remove(folde);
                SqlCommand cmdtransfer = new SqlCommand("BEGIN TRY begin tran t1; insert into tmpDefinedTableHelp (gId, supporter_id, name, family, fatherName, folder_id, packets, rate) select gId, supporter_id, name, family, fatherName, folder_id, packets, rate from delDefinedTableHelp where folder_id = @fId and gId = @gId; delete from delDefinedTableHelp where folder_id = @fId and gId = @gId; commit tran t1; END TRY BEGIN CATCH ROLLBACK END CATCH", con);
                cmdtransfer.Parameters.AddWithValue("@gId", this.id);
                cmdtransfer.Parameters.AddWithValue("@fId", folde);
                cmdtransfer.ExecuteNonQuery();
            }
            decimal sum = 0; int consumep = 0;

            li.Clear();
            foreach (var dd in di1)
            {
                if (dd.Value.Item3 > 0)
                {
                    sum += dd.Value.Item3;
                }
            }
            foreach (var dd in di)
            {
                if (di1.ContainsKey(dd.Key))
                {
                    int p = Convert.ToInt32(Math.Floor(((dd.Value.Item3 > 0) ? dd.Value.Item3 : 0) * this.packs / sum)); consumep += p;
                    di1[dd.Key] = new Tuple <string, int, decimal>(dd.Value.Item1, p, dd.Value.Item3);
                    if (dd.Value.Item3 > 0)
                    {
                        li.Add(new KeyValuePair <decimal, string>(((dd.Value.Item3 - p * this.packpoint < 0) ? 0 : dd.Value.Item3 - p * this.packpoint), dd.Key));
                    }
                }
            }
            arr = li.ToArray();
            arr.OrderBy((x => x.Key)).ToArray();
            int i = 0;

            while (consumep != this.packs)
            {
                di1[arr[i].Value] = new Tuple <string, int, decimal>(di1[arr[i].Value].Item1, di1[arr[i].Value].Item2 + 1, di1[arr[i].Value].Item3);
                i++;
                consumep++;
            }
            SqlCommand cmdupdate;

            foreach (var dd in di1)
            {
                cmdupdate = new SqlCommand("update tmpDefinedTableHelp Set packets = @packs where folder_id = @fId and gId = @gId;", con);
                cmdupdate.Parameters.AddWithValue("@gId", this.id);
                cmdupdate.Parameters.AddWithValue("@fId", dd.Key);
                cmdupdate.Parameters.AddWithValue("@packs", dd.Value.Item2);
                cmdupdate.ExecuteNonQuery();
            }
            SqlCommand     cmd = new SqlCommand("select folder_id as 'شماره پرونده', supporter_id as 'شماره ملی سرپرست', name as 'نام', family as 'نام خانوادگی', fatherName as 'نام پدر', packets as 'تعداد بسته', cast(rate as decimal(10,3)) as 'امتیاز' from tmpDefinedTableHelp where gId = @gId order by rate desc;", con);
            SqlDataAdapter da; DataTable dt;

            cmd.Parameters.AddWithValue("@gId", this.id);
            da = new SqlDataAdapter(cmd);
            dt = new DataTable();
            da.Fill(dt);
            memberDataGridView.DataSource = dt;
            cmd = new SqlCommand("select folder_id as 'شماره پرونده', supporter_id as 'شماره ملی سرپرست', name as 'نام', family as 'نام خانوادگی', fatherName as 'نام پدر', packets as 'تعداد بسته', cast(rate as decimal(10,3)) as 'امتیاز' from delDefinedTableHelp where gId = @gId order by rate desc;", con);
            cmd.Parameters.AddWithValue("@gId", this.id);
            da = new SqlDataAdapter(cmd);
            dt = new DataTable();
            da.Fill(dt);
            delDataGridView.DataSource = dt;
            con.Close();
            waitform.Close();
        }