private void button8_Click(object sender, EventArgs e)
        {
            try
            {
                string         name        = dataGridView2.CurrentRow.Cells[1].Value.ToString();
                SqlConnection  objcon1     = new SqlConnection("Data Source=Localhost;Initial Catalog=FoodDB; Integrated Security=True");
                SqlDataAdapter objadapter1 = new SqlDataAdapter("Select hazine from Foods where Name=N'" + name + "'", objcon1);
                DataSet        objset1     = new DataSet();
                objadapter1.Fill(objset1, "Foods");
                DataRow objdatarow1 = objset1.Tables["Foods"].Rows[0];

                string hazine  = objdatarow1["hazine"].ToString();
                Int64  hazinee = Int64.Parse(hazine);

                string tedad  = dataGridView2.CurrentRow.Cells[2].Value.ToString();
                string price  = dataGridView2.CurrentRow.Cells[3].Value.ToString();
                Int64  pricee = Int64.Parse(price);


                int tedade = int.Parse(tedad) - 1;
                if (tedade > 0)
                {
                    Int64       sood       = pricee - hazinee;
                    DBManagment objdbclass = new DBManagment();

                    objdbclass.Updatetable("Update Factor Set Number='" + tedade + "',SumPrice='" + tedade * pricee + "',Sood='" + sood * tedade + "'   where Name=N'" + name + "' and Factorid='" + Int64.Parse(txtfactorid.Text) + "'   ");
                    loadgridview2();
                    Int64 sum = pricee * tedade;
                    //txtProNet1.Text = sum.ToString();
                    //string takhfif = txtProtakhfif.TextValue.ToString();
                    //txtProNet2.Text = (Int64.Parse(txtProNet1.TextValue.ToString()) - Int64.Parse(takhfif)).ToString();
                    DBManagment   objDBClass = new DBManagment();
                    SqlConnection objcon2    = new SqlConnection("Data Source=Localhost;Initial Catalog=FoodDB; Integrated Security=True");

                    SqlDataAdapter objadapter2 = new SqlDataAdapter("Select SUM(SumPrice) as sum from Factor where Factorid='" + Int64.Parse(txtfactorid.Text) + "'", objcon2);
                    DataSet        objset2     = new DataSet();
                    objadapter2.Fill(objset2, "Factor");
                    DataRow objdatarow2 = objset2.Tables["Factor"].Rows[0];


                    txtProNet1.Text = objdatarow2["sum"].ToString();
                    string takhfif = txtProtakhfif.TextValue.ToString();
                    txtProNet2.Text = (Int64.Parse(txtProNet1.TextValue.ToString()) - Int64.Parse(takhfif)).ToString();
                }

                else
                {
                    MessageBox.Show("امکان کم کردن تعداد این غذا وجود ندارد", "توجه");
                }
            }
            catch
            {
                MessageBox.Show("امکان انجام عملیات مقدور نمی باشد", "توجه");
            }
        }
Example #2
0
        public void bedehkar()
        {
            SqlConnection  objcon1     = new SqlConnection("Data Source=Localhost;Initial Catalog=FoodDB; Integrated Security=True");
            SqlDataAdapter objadapter1 = new SqlDataAdapter("  Select SUM(Money)as SUMMoney from SefareshMoney where Sefareshid='" + Int64.Parse(txtsefareshid0.Text) + "' ", objcon1);
            DataSet        objset1     = new DataSet();

            objadapter1.Fill(objset1, "SefareshMoney");
            DataRow objdatarow1 = objset1.Tables["SefareshMoney"].Rows[0];

            string summoney = objdatarow1["SUMMoney"].ToString();
            Int64  summoneyy;

            if (summoney == "")
            {
                summoneyy = Int64.Parse("0");
            }
            else
            {
                summoneyy = Int64.Parse(objdatarow1["SUMMoney"].ToString());
            }
            Int64 sumnahaei = Int64.Parse(txtProsumnahaei.TextValue.ToString());

            Int64 bedehkar = sumnahaei - summoneyy;

            txtprodiv.Text = bedehkar.ToString();
            if (bedehkar == 0)
            {
                string      Year       = FarsiLibrary.Utils.PersianDate.Now.Year.ToString();
                string      Month      = FarsiLibrary.Utils.PersianDate.Now.Month.ToString();
                string      Day        = FarsiLibrary.Utils.PersianDate.Now.Day.ToString();
                DBManagment objdbclass = new DBManagment();
                int         halat      = int.Parse("0");
                objdbclass.Updatetable("Update SefareshMoney Set FinishYear='" + Year + "',FinishMonth='" + Month + "',FinishDay='" + Day + "'  where Sefareshid='" + Int64.Parse(txtsefareshid0.Text) + "'  ");


                objdbclass.Updatetable("Update Sefaresh Set halat='" + halat + "' where Sefareshid='" + Int64.Parse(txtsefareshid0.Text) + "'  ");
            }
        }
        private void button7_Click(object sender, EventArgs e)
        {
            try{
                DBManagment objdbclass = new DBManagment();

                objdbclass.Updatetable("Update Sefaresh Set Number='" + Int32.Parse(txtnumberrr.Text) + "',Price='" + Int32.Parse(lblPriceeee.Text) + "',SumPrice='" + Int32.Parse(lblPriceeee.Text) * Int32.Parse(txtnumberrr.Text) + "',Sood='" + Int32.Parse(label31.Text) * Int32.Parse(txtnumberrr.Text) + "' where id='" + Int64.Parse(lbliddddd.Text) + "'  ");

                MessageBox.Show("ویرایش با موفقیت انجام شد");
                search("Select id,Name,Number,Price,SumPrice,OneSood from Sefaresh where Sefareshid='" + Int64.Parse(txtsefareshid0.Text) + "'");
                select("Select * from Sefaresh where Sefareshid='" + Int64.Parse(txtsefareshid0.Text) + "'");
                sumprice("  Select SUM(SumPrice)as SUM,SUM(Sood) as sood from Sefaresh where Sefareshid='" + Int64.Parse(txtsefareshid0.Text) + "'  ");
            }
            catch
            {
                MessageBox.Show("  عملیات ویرایش امکان پذیر نمی باشد");
            }
        }
        private void btbedit_Click(object sender, EventArgs e)
        {
            try
            {
                string MajlesDate = cmbyear.Text + "/" + cmbmonth.Text + "/" + cmbday.Text;

                Int64       sefareshid = Int64.Parse(lblsefareshid.Text);
                DBManagment objdbclass = new DBManagment();

                objdbclass.Updatetable("Update Sefaresh Set Des=N'" + txtdes.Text + "',MajlesDate='" + MajlesDate + "', MajlesDay='" + cmbday.Text + "',MajlesMonth='" + cmbmonth.Text + "',MajlesYear='" + cmbyear.Text + "',Takhfif='" + Int64.Parse(txtProtakhfif.TextValue.ToString()) + "' where Sefareshid='" + sefareshid + "'  ");
                MessageBox.Show("ویرایش با موفقیت انجام شد");
                //  Loadgridview();
            }
            catch
            {
                MessageBox.Show("  عملیات ویرایش امکان پذیر نمی باشد");
            }
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("آیا برای ویرایش اطمینان دارید ؟", "توجه", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
            {
                return;
            }
            try
            {
                DBManagment objdbclass = new DBManagment();

                objdbclass.Updatetable("Update Foods Set Name=N'" + textBox2.Text + "', hazine='" + Int32.Parse(txtProhazine.TextValue.ToString()) + "',price='" + Int32.Parse(txtProforosh.TextValue.ToString()) + "' where id='" + Int32.Parse(textBox1.Text) + "'  ");
                Loadgridview();
            }
            catch
            {
                MessageBox.Show("ویرایش امکان پذیر نیست");
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            bool successfullCreateAccount = true;

            try
            {
                Int64 sum = Int64.Parse(txtProNet1.TextValue.ToString());

                Int64  takhfifi;
                string takhfif = txtProtakhfif.TextValue.ToString();
                if (takhfif == "")
                {
                    takhfifi = Int64.Parse("0");
                }
                else
                {
                    takhfifi = Int64.Parse(txtProtakhfif.TextValue.ToString());
                    DBManagment objdbclass = new DBManagment();
                    objdbclass.Updatetable("Update Factor Set takhfif='" + Int32.Parse(txtProtakhfif.TextValue.ToString()) + "'  , status='" + int.Parse("1") + "'  where Factorid='" + Int64.Parse(txtfactorid.Text) + "'  ");
                }

                Int64 sumnahaei = sum - takhfifi;
                txtProNet2.Text = sumnahaei.ToString();
                //  txtProNet1.Text = (Int64.Parse(txtProNet1.TextValue.ToString()) + sum).ToString();
            }
            catch
            {
                successfullCreateAccount = false;
            }
            if (successfullCreateAccount)
            {
                printPreviewDialog1.Document = printDocument1;
                printPreviewDialog1.ShowDialog();
                this.Close();
            }
            if (successfullCreateAccount == false)
            {
                MessageBox.Show("امکان ثبت این فاکتور وجود ندارد", "توجه");

                DBManagment objclass = new DBManagment();
                objclass.Deleterowtable("Delete Factor where  Factorid='" + Int64.Parse(txtfactorid.Text) + "' ");
                loadgridview2();
            }
        }
        private void button5_Click(object sender, EventArgs e)
        {
            //  string name = dataGridView2.CurrentRow.Cells[1].Value.ToString();
            SqlConnection  objcon1     = new SqlConnection("Data Source=Localhost;Initial Catalog=FoodDB; Integrated Security=True");
            SqlDataAdapter objadapter1 = new SqlDataAdapter("Select SUM(Sood)as sumsood  from Sefaresh where Sefareshid='" + Int64.Parse(lbfactorid.Text) + "'", objcon1);
            DataSet        objset1     = new DataSet();

            objadapter1.Fill(objset1, "Sefaresh");
            DataRow objdatarow1 = objset1.Tables["Sefaresh"].Rows[0];
            string  sood        = objdatarow1["sumsood"].ToString();


            if (Int64.Parse(txtProtakhfif.TextValue.ToString()) > Int64.Parse(sood))
            {
                MessageBox.Show("امکان ثبت وجود ندارد تخفیف بیشتر از سود این فاکتور می باشد", "توجه");
            }
            else
            {
                bool   successfullCreateAccount = true;
                string test;
                try
                {
                    string takhfif;
                    if (txtProtakhfif.Text == "")
                    {
                        takhfif = "0";
                    }
                    else
                    {
                        takhfif = txtProtakhfif.TextValue.ToString();
                    }
                    string type       = "0";
                    string halat      = "1";
                    string MajlesDate = cmbyear.Text + "/" + cmbmonth.Text + "/" + cmbday.Text;
                    string dt         = cmbyear.Text + cmbmonth.Text + cmbday.Text;
                    if (txtdes.Text != "" && dt != "")
                    {
                        DBManagment objdbclass = new DBManagment();
                        objdbclass.Updatetable("Update Sefaresh Set MajlesDate='" + MajlesDate + "' ,MajlesYear='" + cmbyear.Text + "', MajlesMonth='" + cmbmonth.Text + "' ,MajlesDay='" + cmbday.Text + "',Des=N'" + txtdes.Text + "',Type='" + type + "',Takhfif='" + Int64.Parse(takhfif) + "',halat='" + Int16.Parse(halat) + "', status='" + int.Parse("1") + "'  where Sefareshid='" + Int64.Parse(lbfactorid.Text) + "'  ");

                        Int64 factor       = Int64.Parse(txtProNet1.TextValue.ToString());
                        Int64 takhfifi     = Int64.Parse(takhfif);
                        Int64 factornahaei = factor - takhfifi;
                        txtProNet2.Text = factornahaei.ToString();
                        printPreviewDialog1.Document = printDocument1;
                        printPreviewDialog1.ShowDialog();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("برای ثبت نهایی سفارش نام سفارش دهنده و تاریخ مجلس را پر کنید");
                    }
                }
                catch
                {
                    successfullCreateAccount = false;
                }

                if (successfullCreateAccount == false)
                {
                    MessageBox.Show("امکان ثبت این فاکتور وجود ندارد", "توجه");

                    DBManagment objclass = new DBManagment();
                    objclass.Deleterowtable("Delete Sefaresh where Sefareshid='" + Int64.Parse(lbfactorid.Text) + "' ");
                    Loadgridview2();
                }
            }
        }