Ejemplo n.º 1
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            var fb = this.DataContext as FormedBasket;

            if (dgSelectedItems.Items.Count > 0)
            {
                fb.FormedBasketItems.Clear();
                fb.FormedBasketItems.AddRange(dgSelectedItems.ItemsSource as List <FormedBasket_Item>);
            }
            fb.RelatedSectors = (lbSectors.ItemsSource as List <Sector>).Where(x => x.IsSelected).ToList();

            if (fb.IsValidate())
            {
                if (!fb.Id.HasValue)
                {
                    if (FormedBasket.InsertData(fb))
                    {
                        MyMessage.InsertMessage();
                    }
                }
                else
                {
                    if (FormedBasket.UpdateData(fb))
                    {
                        MyMessage.UpdateMessage();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static bool UpdateData(FormedBasket x)
        {
            BaseDataBase._NonQuery("delete from FormedBasket_Item where FormedBasket_Item.FormedBasketID = " + x.Id);
            bool b = BaseDataBase._StoredProcedure("sp_Update_FormedBasket"
                                                   , new SqlParameter("@Id", x.Id)
                                                   , new SqlParameter("@Name", x.Name)
                                                   , new SqlParameter("@IsActive", x.IsActive)
                                                   , new SqlParameter("@IsUrgent", x.IsUrgent)
                                                   , new SqlParameter("@Notes", x.Notes)
                                                   , new SqlParameter("@LastUserID", BaseDataBase.CurrentUser.ID));

            foreach (var item in x.FormedBasketItems)
            {
                if (item.FormedBasket == null)
                {
                    item.FormedBasket = x;
                }
                FormedBasket_Item.InsertData(item);
            }
            if (x.id.HasValue)
            {
                FormedBasket_Sector.SaveFormedBasketSectors(x);
            }
            return(b);
        }
Ejemplo n.º 3
0
 public static bool DeleteData(FormedBasket x)
 {
     if (x.id.HasValue)
     {
         FormedBasket_Sector.DeleteFormedBasketSectors(x);
     }
     return(BaseDataBase._StoredProcedure("sp_Delete_FormedBasket"
                                          , new SqlParameter("@Id", x.Id)));
 }
Ejemplo n.º 4
0
        internal static List <FormedBasket> GetFormedBasketByFamilyID(int familyID)
        {
            List <FormedBasket> xx  = new List <FormedBasket>();
            SqlConnection       con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand          com = new SqlCommand("sp_Get_All_FormedBasketByFamilyID", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            com.Parameters.Add(new SqlParameter("@FamilyID", familyID));
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                while (rd.Read())
                {
                    FormedBasket x = new FormedBasket();

                    if (!(rd["Id"] is DBNull))
                    {
                        x.Id = int.Parse(rd["Id"].ToString());
                    }
                    x.Name = rd["Name"].ToString();
                    if (!(rd["IsActive"] is DBNull))
                    {
                        x.IsActive = bool.Parse(rd["IsActive"].ToString());
                    }
                    if (!(rd["IsUrgent"] is DBNull))
                    {
                        x.IsUrgent = bool.Parse(rd["IsUrgent"].ToString());
                    }
                    x.Notes = rd["Notes"].ToString();
                    if (!(rd["LastUserID"] is DBNull))
                    {
                        x.LastUserID = int.Parse(rd["LastUserID"].ToString());
                    }
                    x.FormedBasketItems = FormedBasket_Item.GetAllBasket_ItemByBasket(x);
                    xx.Add(x);
                }
                rd.Close();
            }
            catch
            {
                xx = null;
            }
            finally
            {
                con.Close();
            }
            return(xx);
        }
Ejemplo n.º 5
0
        public static FormedBasket GetItemByID(int id)
        {
            FormedBasket  x   = new FormedBasket();
            SqlConnection con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand    com = new SqlCommand("sp_Get_ID_FormedBasket", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            SqlParameter pr = new SqlParameter("@ID", id);

            com.Parameters.Add(pr);
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                if (rd.Read())
                {
                    if (!(rd["Id"] is DBNull))
                    {
                        x.Id = int.Parse(rd["Id"].ToString());
                    }
                    x.Name = rd["Name"].ToString();
                    if (!(rd["IsActive"] is DBNull))
                    {
                        x.IsActive = bool.Parse(rd["IsActive"].ToString());
                    }
                    if (!(rd["IsUrgent"] is DBNull))
                    {
                        x.IsUrgent = bool.Parse(rd["IsUrgent"].ToString());
                    }
                    x.Notes = rd["Notes"].ToString();
                    if (!(rd["LastUserID"] is DBNull))
                    {
                        x.LastUserID = int.Parse(rd["LastUserID"].ToString());
                    }

                    x.FormedBasketItems = FormedBasket_Item.GetAllBasket_ItemByBasket(x);
                }
                rd.Close();
            }
            catch
            {
                x = null;
            }
            finally
            {
                con.Close();
            }
            return(x);
        }
Ejemplo n.º 6
0
        public static FormedBasket_Item GetBasket_ItemByID(int FormedBasketID, int ItemID)
        {
            FormedBasket_Item x   = new FormedBasket_Item();
            SqlConnection     con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand        com = new SqlCommand("sp_Get_ID_FormedBasket_Item", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            SqlParameter pr1 = new SqlParameter("@FormedBasketID", FormedBasketID);

            com.Parameters.Add(pr1);
            SqlParameter pr2 = new SqlParameter("@ItemID", ItemID);

            com.Parameters.Add(pr2);
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                if (rd.Read())
                {
                    if (!(rd["FormedBasketID"] is DBNull))
                    {
                        x.FormedBasket = FormedBasket.GetItemByID(int.Parse(rd["FormedBasketID"].ToString()));
                    }
                    if (!(rd["ItemID"] is DBNull))
                    {
                        x.RelatedItem = Item.GetItemByID(int.Parse(rd["ItemID"].ToString()));
                    }
                    if (!(rd["Quantity"] is DBNull))
                    {
                        x.Quantity = double.Parse(rd["Quantity"].ToString());
                    }
                    if (!(rd["LastUserID"] is DBNull))
                    {
                        x.LastUserID = int.Parse(rd["LastUserID"].ToString());
                    }
                }
                rd.Close();
            }
            catch
            {
                x = null;
            }
            finally
            {
                con.Close();
            }
            return(x);
        }
Ejemplo n.º 7
0
        public static List <FormedBasket_Item> GetAllBasket_ItemByBasket(FormedBasket FormedBasket)
        {
            List <FormedBasket_Item> xx  = new List <FormedBasket_Item>();
            SqlConnection            con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand com = new SqlCommand("sp_Get_All_FormedBasket_Item_ByFormedBasketID", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            SqlParameter pr1 = new SqlParameter("@FormedBasketID", FormedBasket.Id);

            com.Parameters.Add(pr1);
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                while (rd.Read())
                {
                    FormedBasket_Item x = new FormedBasket_Item();
                    x.FormedBasket = FormedBasket;
                    if (!(rd["ItemID"] is DBNull))
                    {
                        x.RelatedItem = Item.GetItemByID(int.Parse(rd["ItemID"].ToString()));
                    }
                    if (!(rd["Quantity"] is DBNull))
                    {
                        x.Quantity = double.Parse(rd["Quantity"].ToString());
                    }
                    if (!(rd["LastUserID"] is DBNull))
                    {
                        x.LastUserID = int.Parse(rd["LastUserID"].ToString());
                    }
                    xx.Add(x);
                }
                rd.Close();
            }
            catch
            {
                xx = null;
            }
            finally
            {
                con.Close();
            }
            return(xx);
        }
Ejemplo n.º 8
0
 private void cmboFormedBasket_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (IsLoaded && cmboFormedBasket.SelectedItem != null)
     {
         brdrBack.Visibility = Visibility.Collapsed;
         var id = (int)(cmboFormedBasket.SelectedItem as DataRowView)["Id"];
         var fb = FormedBasket.GetItemByID(id);
         this.DataContext            = null;
         lbMainItems.ItemsSource     = null;
         dgSelectedItems.ItemsSource = null;
         this.DataContext            = fb;
         dgSelectedItems.ItemsSource = new List <FormedBasket_Item>();
         (dgSelectedItems.ItemsSource as List <FormedBasket_Item>).AddRange(fb.FormedBasketItems);
         lbMainItems.ItemsSource = (from x in Item.AllItems where !IsItemExist(x) select x).ToList <Item>();
         RefreshPanel();
         lbSectors.ItemsSource = null;
         lbSectors.ItemsSource = Sector.GetAllSectorByFormedBasketID(fb.Id.Value);
     }
 }
Ejemplo n.º 9
0
        public static bool InsertData(FormedBasket x)
        {
            x.Id = BaseDataBase._StoredProcedureReturnable("sp_Add_FormedBasket"
                                                           , new SqlParameter("@Id", System.Data.SqlDbType.Int)
                                                           , new SqlParameter("@Name", x.Name)
                                                           , new SqlParameter("@IsActive", x.IsActive)
                                                           , new SqlParameter("@IsUrgent", x.IsUrgent)
                                                           , new SqlParameter("@Notes", x.Notes)
                                                           , new SqlParameter("@LastUserID", BaseDataBase.CurrentUser.ID));

            foreach (var item in x.FormedBasketItems)
            {
                if (item.FormedBasket == null)
                {
                    item.FormedBasket = x;
                    FormedBasket_Item.InsertData(item);
                }
            }
            if (x.id.HasValue)
            {
                FormedBasket_Sector.SaveFormedBasketSectors(x);
            }
            return(x.Id.HasValue);
        }
Ejemplo n.º 10
0
 internal static bool DeleteFormedBasketSectors(FormedBasket fb)
 {
     try
     {
         BaseDataBase._NonQuery("delete from FormedBasket_Sector where FormedBasketID = " + fb.Id.Value);
         return(true);
     }
     catch (Exception ex) { MyMessageBox.Show(ex.Message); return(false); }
 }
Ejemplo n.º 11
0
 
 public class FormedBasket_Sector : ModelViewContext
    { 
 public static bool SaveFormedBasketSectors(FormedBasket fb)
                                                             {
                                                                 try
                                                                 {
                                                                     BaseDataBase._NonQuery("delete from FormedBasket_Sector where FormedBasketID = " + fb.Id.Value);
                                                                     foreach (var sector in fb.RelatedSectors)
                                                                     {
                                                                         BaseDataBase._NonQuery($"INSERT INTO [dbo].[FormedBasket_Sector]([FormedBasketID],[SectorID],[LastUserID]) VALUES({fb.Id}, {sector.ID}, {BaseDataBase.CurrentUser.ID})");
                                                                     }
                                                                     return(true);
                                                                 }
                                                                 catch (Exception ex) { MyMessageBox.Show(ex.Message); return(false); }
                                                             }
Ejemplo n.º 12
0
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var o = this.DataContext as Order;

            if (o.Type != 1)
            {
                List <Item> lst = null;
                lst = await Item.GetAllItemsByInventory(o.InventoryID);

                if (lst == null || lst.Count == 0)
                {
                    MyMessageBox.Show("المستودع الذي تم اختياره لا يحوي أي مادة حاليّاً");
                    DialogResult = false;
                    return;
                }

                if (o.Id.HasValue)
                {
                    foreach (var item in o.OIs)
                    {
                        if (lst.Select(x => x.Id).Contains(item.Item.Id))
                        {
                            item.Item.CurrentQuantity = item.Quantity + lst.Where(x => x.Id == item.Item.Id).First().CurrentQuantity;
                        }
                        else
                        {
                            item.Item.CurrentQuantity = item.Quantity;
                        }
                    }
                    dgSelectedItems.ItemsSource = o.OIs;
                    lbMainItems.ItemsSource     = (from x in lst where !IsItemExist(x) select x).ToList <Item>();
                }
                else
                {
                    if (o.OIs.Count > 0)
                    {
                        foreach (var item in o.OIs)
                        {
                            if (lst.Select(x => x.Id).Contains(item.Item.Id))
                            {
                                item.Item.CurrentQuantity = item.Quantity + lst.Where(x => x.Id == item.Item.Id).First().CurrentQuantity;
                            }
                            else
                            {
                                item.Item.CurrentQuantity = item.Quantity;
                            }
                        }
                        dgSelectedItems.ItemsSource = o.OIs;
                        lbMainItems.ItemsSource     = (from x in lst where !IsItemExist(x) select x).ToList <Item>();
                    }
                    else
                    {
                        dgSelectedItems.ItemsSource = new List <Order_Item>();
                        lbMainItems.ItemsSource     = lst;
                    }
                }

                if (lst != null && (o.Type == 3 || o.Type == 4))
                {
                    var FormedItems = o.Type == 3 ? FormedBasket.GetFormedBasketByFamilyID(o.FamilyID.Value).Where(x => x.IsUrgent == o.IsUrgentOrder).ToList() : FormedBasket.ActiveItems;
                    if (FormedItems != null && FormedItems.Count > 0)
                    {
                        FormedBasketSelectControl w = new FormedBasketSelectControl(FormedItems);
                        if (w.ShowDialog() == true)
                        {
                            var fb = w.lstFormedBakset.SelectedItem as FormedBasket;
                            foreach (var item in fb.FormedBasketItems)
                            {
                                if ((lbMainItems.ItemsSource as List <Item>).Where(x => x.Id == item.RelatedItem.Id).FirstOrDefault() == null)
                                {
                                    MyMessageBox.Show("المادة (" + item.RelatedItem.Name + ") غير موجودة في قائمة المواد الحالية\nلم يتم اضافة تشكيلة المواد");
                                    return;
                                }
                            }
                            foreach (var item in fb.FormedBasketItems)
                            {
                                Item       i = (lbMainItems.ItemsSource as List <Item>).Where(x => x.Id == item.RelatedItem.Id).FirstOrDefault();
                                Order_Item s = new Order_Item();
                                s.Item     = i;
                                s.Quantity = item.Quantity;
                                (dgSelectedItems.ItemsSource as List <Order_Item>).Add(s);
                                (lbMainItems.ItemsSource as List <Item>).Remove(i);
                            }
                        }
                    }
                }
            }
            else
            {
                if (o.Id.HasValue)
                {
                    dgSelectedItems.ItemsSource = o.OIs;
                    lbMainItems.ItemsSource     = (from x in Item.AllItems where !IsItemExist(x) select x).ToList <Item>();
                }
                else
                {
                    dgSelectedItems.ItemsSource = o.OIs;
                    lbMainItems.ItemsSource     = (from x in Item.AllItems where !IsItemExist(x) select x).ToList <Item>();
                }
            }


            //Criteria
            if (o != null && !o.Id.HasValue && o.FamilyID.HasValue)
            {
                var OIs = Order_Item.GetFamilyCriteria(o.FamilyID.Value);
                if (OIs != null && OIs.Count > 0)
                {
                    foreach (var s in OIs)
                    {
                        foreach (var i in lbMainItems.ItemsSource as List <Item> )
                        {
                            if (i.Id.HasValue && i.Id.Value == s.Item.Id.Value)
                            {
                                s.Item.Id = i.Id;
                                (dgSelectedItems.ItemsSource as List <Order_Item>).Add(s);
                                (lbMainItems.ItemsSource as List <Item>).Remove(i);
                                break;
                            }
                        }
                    }
                }
            }

            RefreshPanel();
        }