Exemplo n.º 1
0
        //selection

        private void txtBuyID_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                PharmaLinq           = new Linq.PharmaLinqDataContext(flag.Con);
                btnSaveBuy.IsEnabled = true;
                if (txtBuyID.Text != (PharmaLinq.Buys.Where(item => item.Exist == true).Max(item => item.ID_Buy) + 1).ToString())
                {
                    Linq.Buy buy = PharmaLinq.Buys.Single(item => item.Exist == true && item.ID_Buy == Convert.ToInt32(txtBuyID.Text));
                    txtBarcode.IsEnabled = true;
                    txtBarcode.Clear();
                    txtBuyDate.SelectedDate = buy.DateBuy;
                    txtUser.Text            = PharmaLinq.Users.Single(item => item.Exist == true && item.ID_User == IDUser).User_Name;
                    buyCost          = Convert.ToDouble(buy.BuyCost);
                    txtbBuyCost.Text = buyCost.ToString();

                    DelDt.Clear();
                    Dt.Clear();
                    Dt = flag.Fill_DataGrid_join("SELECT  [ID_Buy],BuysAction.ID_Product,Products.Name,Products.BarCode,[BuysAction].Cost,[Quantit_BuysAction],[BuysAction].EX_Date,[totatCost],ID_BuyAction FROM [dbo].[BuysAction] inner join Products on Products.ID_Product=BuysAction.ID_Product where BuysAction.Exist ='true' And  ID_Buy = '" + txtBuyID.Text + "'");
                    dgBill.DataContext = Dt;
                    dtcount            = Dt.Rows.Count;
                }
            }
            catch (Exception ex)
            {
                flag.Con.Close();
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void btnSaveBuy_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (dgBill.Items.Count > 0)
                {
                    PharmaLinq = new Linq.PharmaLinqDataContext(flag.Con);
                    int j = 0;



                    Linq.Buy buy = new Linq.Buy();

                    if (isnew == false)
                    {
                        buyCost = 0;
                        for (int i = 0; i < dgBill.Items.Count; i++)
                        {
                            try
                            {
                                for (j = 0; j < DelDt.Rows.Count; j++)
                                {
                                    if (Convert.ToInt32(Dt.Rows[i].ItemArray[8]) == Convert.ToInt32(DelDt.Rows[j].ItemArray[0]))
                                    {
                                        goto skip;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                            buyCost += Convert.ToDouble(Dt.Rows[i].ItemArray[7]);
                            skip :;
                        }

                        buy = PharmaLinq.Buys.Single(item => item.Exist == true && item.ID_Buy == Convert.ToInt32(txtBuyID.Text));
                        j   = 0;
                    }

                    buy.BuyCost  = Convert.ToDecimal(buyCost);
                    buy.ID_Caule = (int)PharmaLinq.Caules.SingleOrDefault(item => item.Exist == true && item.CauleName == cmbCaule.Text).ID_Caule;
                    buy.ID_User  = IDUser;
                    buy.Exist    = true;

                    for (int i = 0; i < dgBill.Items.Count; i++)
                    {
                        Linq.Product    product   = PharmaLinq.Products.SingleOrDefault(item => item.ID_Product == Convert.ToInt32(Dt.Rows[i].ItemArray[1]));
                        Linq.BuysAction buyaction = new Linq.BuysAction();

                        product.Cost = Convert.ToDouble(Dt.Rows[i].ItemArray[4]);
                        if (isnew == false && (i + 1) <= dtcount)
                        {
                            buyaction = PharmaLinq.BuysActions.Single(item => item.Exist == true && item.ID_Buy == Convert.ToInt32(txtBuyID.Text) && item.ID_BuyAction == Convert.ToInt32(Dt.Rows[i].ItemArray[8]));
                            if (product.BiggerUnit == "الثانوية")
                            {
                                product.Quantity     -= ((int)PharmaLinq.BuysActions.Single(item => item.Exist == true && item.ID_Buy == Convert.ToInt32(txtBuyID.Text) && item.ID_BuyAction == Convert.ToInt32(Dt.Rows[i].ItemArray[8])).Quantit_BuysAction % (int)product.SubQuantity);
                                product.UnitQuantity -= ((int)PharmaLinq.BuysActions.Single(item => item.Exist == true && item.ID_Buy == Convert.ToInt32(txtBuyID.Text) && item.ID_BuyAction == Convert.ToInt32(Dt.Rows[i].ItemArray[8])).Quantit_BuysAction / (int)product.SubQuantity);

                                if (product.UnitQuantity < 0)
                                {
                                    product.UnitQuantity = 0;
                                    product.Quantity     = 0;
                                }

                                if (product.Quantity < 0)
                                {
                                    product.Quantity += (int)product.SubQuantity;
                                    product.UnitQuantity--;
                                }
                            }
                            else
                            {
                                product.Quantity -= (int)PharmaLinq.BuysActions.Single(item => item.Exist == true && item.ID_Buy == Convert.ToInt32(txtBuyID.Text) && item.ID_BuyAction == Convert.ToInt32(Dt.Rows[i].ItemArray[8])).Quantit_BuysAction;

                                if (product.Quantity < 0)
                                {
                                    product.Quantity = 0;
                                }
                            }
                        }
                        try
                        {
                            for (j = 0; j < DelDt.Rows.Count; j++)
                            {
                                if (Convert.ToInt32(Dt.Rows[i].ItemArray[8]) == Convert.ToInt32(DelDt.Rows[j].ItemArray[0]))
                                {
                                    buyaction.Exist = false;
                                    goto skip;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        if (product.BiggerUnit == "الثانوية")
                        {
                            product.Quantity     += (Convert.ToInt32(Dt.Rows[i].ItemArray[5]) % (int)product.SubQuantity);
                            product.UnitQuantity += (Convert.ToInt32(Dt.Rows[i].ItemArray[5]) / product.SubQuantity);

                            if (product.Quantity >= product.SubQuantity)
                            {
                                product.Quantity -= (int)product.SubQuantity;
                                product.UnitQuantity++;
                            }
                        }
                        else
                        {
                            product.Quantity += Convert.ToInt32(Dt.Rows[i].ItemArray[5]);
                        }
                        product.EX_Date = Convert.ToString(Dt.Rows[i].ItemArray[6]);

                        buyaction.ID_Buy             = Convert.ToInt32(Dt.Rows[i].ItemArray[0]);
                        buyaction.ID_Product         = Convert.ToInt32(Dt.Rows[i].ItemArray[1]);
                        buyaction.Cost               = Convert.ToDecimal(Dt.Rows[i].ItemArray[4]);
                        buyaction.Quantit_BuysAction = Convert.ToInt32(Dt.Rows[i].ItemArray[5]);
                        buyaction.EX_Date            = Convert.ToString(Dt.Rows[i].ItemArray[6]);
                        buyaction.totatCost          = Convert.ToDecimal(Dt.Rows[i].ItemArray[7]);
                        buyaction.Exist              = true;

                        if (isnew == true || (i + 1) > dtcount)
                        {
                            PharmaLinq.BuysActions.InsertOnSubmit(buyaction);
                        }
                        skip :;
                        PharmaLinq.SubmitChanges();
                    }

                    if (isnew == true)
                    {
                        buy.ID_Buy  = Convert.ToInt32(txtBuyID.Text);
                        buy.DateBuy = txtBuyDate.SelectedDate;
                        PharmaLinq.Buys.InsertOnSubmit(buy);
                    }

                    MessageBox.Show("تم حفظ الفاتورة");

                    PharmaLinq.SubmitChanges();


                    USC_BUYS USC_Buy = new USC_BUYS
                    {
                        IDUser = IDUser
                    };
                    MainWindow.GetMainForm.GridUsc.Children.Clear();
                    MainWindow.GetMainForm.GridUsc.Children.Add(USC_Buy);
                }
                else
                {
                    MessageBox.Show("يجب اضافة مشتريات");
                }
            }
            catch (Exception ex)
            {
                flag.Con.Close();
                MessageBox.Show(ex.Message);
            }
        }