示例#1
0
        void save()
        {
            if (txtName.Text.Trim() == string.Empty || txtPass.Text.Trim() == string.Empty || txtUser.Text.Trim() == string.Empty)
            {
                MessageBox.Show("الرجاء عدم ترك حقول فارغة");
                return;
            }

            if (user.id == 0)
            {
                db = new DAL.dbDataContext();
                db.users.InsertOnSubmit(user);
                SetData();
                db.SubmitChanges();
            }
            else
            {
                SetData();
                db.SubmitChanges();
            }

            MessageBox.Show("تم الحفظ بنجاح");
            dgvUsers.DataSource = db.users;
            New();
        }
示例#2
0
        public override void Save()
        {
            if (!IsDataValidated())
            {
                return;
            }

            var db = new DAL.dbDataContext();

            DAL.Account account;

            if (cusVendor.ID == 0)
            {
                db.CustomersAndVendors.InsertOnSubmit(cusVendor);
                account = new DAL.Account();
                db.Accounts.InsertOnSubmit(account);
            }
            else
            {
                db.CustomersAndVendors.Attach(cusVendor);
                account = db.Accounts.Single(s => s.ID == cusVendor.AccountID);
            }

            SetData();
            account.Name = cusVendor.Name;
            db.SubmitChanges();
            cusVendor.AccountID = account.ID;
            db.SubmitChanges();

            base.Save();
        }
示例#3
0
        public override void Save()
        {
            if (txt_Name.Text.Trim() == String.Empty)
            {
                txt_Name.ErrorText = "برجاء ادخال اسم الخزنة";
                return;
            }

            var db = new DAL.dbDataContext();

            DAL.Account account;
            if (drawer.ID == 0)
            {
                account = new DAL.Account();
                db.Drawers.InsertOnSubmit(drawer);
                db.Accounts.InsertOnSubmit(account);
            }
            else
            {
                db.Drawers.Attach(drawer);
                account = db.Accounts.Single(s => s.ID == drawer.AccountID);
            }

            SetData();
            account.Name = drawer.Name;
            db.SubmitChanges();
            drawer.AccountID = account.ID;
            db.SubmitChanges();

            base.Save();
        }
示例#4
0
        void save()
        {
            if (Cmb_stores.SelectedValue == null)
            {
                MessageBox.Show("الرجاء اختيار مخزن");
                return;
            }
            var db = new DAL.dbDataContext();

            if (movement_header.id == 0)
            {
                movement_header = new DAL.movements_header();
                db.movements_headers.InsertOnSubmit(movement_header);
                SetData();
                db.SubmitChanges();
            }
            foreach (DataGridViewRow row in dgvItems.Rows)
            {
                movement = new DAL.movement();
                movement.movements_header = movement_header;
                movement.item_id          = Convert.ToInt32(row.Cells["item_id"].Value);
                movement.unit_id          = Convert.ToInt32(row.Cells["unit_id"].Value);
                movement.qty = Convert.ToDecimal(row.Cells["qty"].Value);
                //movement.qty_unit = Convert.ToDecimal(row.Cells["unit_qty"].Value);
                db.movements.InsertOnSubmit(movement);
                db.SubmitChanges();
            }
            MessageBox.Show("تم الحفظ بنجاح");
            New();
        }
示例#5
0
        public override void Save()
        {
            if (textEdit1.Text.Trim() == string.Empty)
            {
                textEdit1.ErrorText = "برجاء ادخال اسم الفرع";
                return;
            }
            DAL.Account SalesAccount          = new DAL.Account();
            DAL.Account SalesReturnAccount    = new DAL.Account();
            DAL.Account InventoryAccount      = new DAL.Account();
            DAL.Account CostOfSoldGoodsAccont = new DAL.Account();

            var db = new DAL.dbDataContext();

            if (store.ID == 0)
            {
                db.Stores.InsertOnSubmit(store);

                db.Accounts.InsertOnSubmit(SalesAccount);
                db.Accounts.InsertOnSubmit(SalesReturnAccount);
                db.Accounts.InsertOnSubmit(InventoryAccount);
                db.Accounts.InsertOnSubmit(CostOfSoldGoodsAccont);

                store.DiscountAllowedAccountID = Session.Defaults.DiscountAllowedAccount;
                store.DiscountReveiedAccountID = Session.Defaults.DiscountReceivedAccount;
            }
            else
            {
                db.Stores.Attach(store);

                SalesAccount          = db.Accounts.Single(x => x.ID == store.SalesAccountID);
                SalesReturnAccount    = db.Accounts.Single(x => x.ID == store.SalesReturnAccountID);
                InventoryAccount      = db.Accounts.Single(x => x.ID == store.InventoryAccountID);
                CostOfSoldGoodsAccont = db.Accounts.Single(x => x.ID == store.CostOfSoldGoodsAccountID);
            }

            SetData();
            SalesAccount.Name          = store.Name + "- مبيعات";
            SalesReturnAccount.Name    = store.Name + "- مردود مبيعات";
            InventoryAccount.Name      = store.Name + "- المخزون";
            CostOfSoldGoodsAccont.Name = store.Name + "- تكلفه البضاعه المباعه";
            db.SubmitChanges();

            store.SalesAccountID           = SalesAccount.ID;
            store.SalesReturnAccountID     = SalesReturnAccount.ID;
            store.InventoryAccountID       = InventoryAccount.ID;
            store.CostOfSoldGoodsAccountID = CostOfSoldGoodsAccont.ID;

            db.SubmitChanges();
            base.Save();
        }
示例#6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Trim() == string.Empty)
            {
                MessageBox.Show("الرجاء عدم ترك حقل الاسم فارغ");
                return;
            }
            if (Cmb_stores.SelectedValue == null)
            {
                MessageBox.Show("الرجاء اختيار مخزن");
                return;
            }
            if (Cmb_stores.SelectedValue == null)
            {
                MessageBox.Show("الرجاء اختيار وحدة رئيسية");
                return;
            }

            if (item.id == 0)
            {
                db = new DAL.dbDataContext();
                db.items.InsertOnSubmit(item);
                unit_relation.item     = item;
                unit_relation.sup_unit = Convert.ToInt32(Cmb_unites.SelectedValue.ToString());
                unit_relation.ratio    = 1;
                db.unites_relations.InsertOnSubmit(unit_relation);
                SetData();
                db.SubmitChanges();
                foreach (DataGridViewRow row in dgv_subUnits.Rows)
                {
                    //unit_relation = new DAL.unites_relation();
                    //unit_relation.item_id = item.id;
                    //unit_relation.sup_unit = Convert.ToInt32(row.Cells["unit_id"].Value);
                    //unit_relation.ratio = Convert.ToInt32(row.Cells["ratioN"].Value);
                    //db.unites_relations.InsertOnSubmit(unit_relation);
                    //db.SubmitChanges();
                }
            }
            else
            {
                unit_relation          = db.unites_relations.Where(i => i.item_id == item.id).Where(i => i.ratio == 1).First();
                unit_relation.sup_unit = Convert.ToInt32(Cmb_unites.SelectedValue.ToString());
                SetData();
                db.SubmitChanges();
            }

            MessageBox.Show("تم إضافة الصنف بنجاح");
            refreshItems();
            New();
        }
示例#7
0
        public override void New()
        {
            product = new DAL.Product()
            {
                Code     = GetNewProductCode(),
                IsActive = true
            };
            var db    = new DAL.dbDataContext();
            var categ = db.ProductCategories.Where(x => db.ProductCategories.Where(w => w.ParentID == x.ID).Count() == 0).FirstOrDefault();

            if (categ != null)
            {
                product.CategoryID = categ.ID;
            }

            base.New();

            this.Text = "اضافه صنف جديد";

            var data = gridView1.DataSource as BindingList <DAL.ProductUnit>;

            if (db.UnitNames.Count() == 0)
            {
                db.UnitNames.InsertOnSubmit(new DAL.UnitName()
                {
                    Name = "قطعة"
                });
                db.SubmitChanges();
                RefreshData();
            }
            data.Add(new DAL.ProductUnit()
            {
                factor = 1, UnitID = db.UnitNames.First().ID, Barcode = GetNewBarCode()
            });
        }
示例#8
0
        public override void Save()
        {
            gridView1.UpdateCurrentRow();
            if (ValdiateData() == false)
            {
                return;
            }
            var db = new DAL.dbDataContext();

            if (product.ID == 0)
            {
                db.Products.InsertOnSubmit(product);
            }
            else
            {
                db.Products.Attach(product);
            }

            SetData();
            db.SubmitChanges();
            var data = gridView1.DataSource as BindingList <DAL.ProductUnit>;

            foreach (var item in data)
            {
                item.ProductID = product.ID;
                if (string.IsNullOrEmpty(item.Barcode))
                {
                    item.Barcode = "";
                }
            }
            sdb.SubmitChanges();
            base.Save();
            this.Text = string.Format("بيانات صنف : {0}", product.Name);
        }
示例#9
0
        private void btnAccept_Click(object sender, EventArgs e)
        {
            int user_id = Properties.Settings.Default.user_id;

            user = db.users.Where(a => a.id == user_id).FirstOrDefault();
            if (user.type == "user")
            {
                if (dgvMovements.Rows.Count > 0)
                {
                    int id = 0;
                    if (dgvMvtHeader.CurrentRow.Cells[0].Value != null)
                    {
                        id = Convert.ToInt32(dgvMvtHeader.CurrentRow.Cells[0].Value.ToString());
                        movement_header.approved     = 1;
                        movement_header.userApproved = user.id;
                        db.SubmitChanges();
                        MessageBox.Show("تم قبول الطلب بنجاح");
                        btnAccept.Enabled = false;
                    }
                }
            }
            else
            {
                MessageBox.Show("عفوا ! لا يمتلك هذا المستخدم صلاحية قبول الطلبات");
            }
        }
示例#10
0
 void save()
 {
     if (txt_name.Text.Trim() == string.Empty)
     {
         MessageBox.Show("الرجاء عدم ترك حقل الاسم فارغ");
         return;
     }
     if (store.id == 0)
     {
         db = new DAL.dbDataContext();
         db.stores.InsertOnSubmit(store);
         SetData();
         db.SubmitChanges();
     }
     else
     {
         SetData();
         db.SubmitChanges();
     }
     MessageBox.Show("تم الحفظ بنجاح");
     DGV_stores.DataSource = db.stores;
     New();
 }
示例#11
0
 private void Lkp_Category_ProcessNewValue(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e)
 {
     if (e.DisplayValue is string st && st.Trim() != string.Empty)
     {
         var newObject = new DAL.ProductCategory()
         {
             Name = st, ParentID = 0, Number = "0"
         };
         using (var db = new DAL.dbDataContext())
         {
             db.ProductCategories.InsertOnSubmit(newObject);
             db.SubmitChanges();
         }
         ((List <DAL.ProductCategory>)lkp_Category.Properties.DataSource).Add(newObject);
         e.Handled = true;
     }
 }
示例#12
0
        private void RepoUOM_ProcessNewValue(object sender, DevExpress.XtraEditors.Controls.ProcessNewValueEventArgs e)
        {
            if (e.DisplayValue is string value && value.Trim() != string.Empty)
            {
                var NewObject = new DAL.UnitName()
                {
                    Name = value.Trim()
                };
                using (DAL.dbDataContext db = new DAL.dbDataContext())
                {
                    db.UnitNames.InsertOnSubmit(NewObject);
                    db.SubmitChanges();
                }

                ((List <DAL.UnitName>)repoUOM.DataSource).Add(NewObject);
                ((List <DAL.UnitName>)((LookUpEdit)sender).Properties.DataSource).Add(NewObject);

                e.Handled = true;
            }
        }
示例#13
0
        void Save()
        {
            if (txt_name.Text.Trim() == String.Empty)
            {
                txt_name.ErrorText = "برجاء ادخال اسم الشركة";
                return;
            }


            DAL.dbDataContext db   = new DAL.dbDataContext();
            DAL.CompanyInfo   info = db.CompanyInfos.FirstOrDefault();
            if (info == null)
            {
                info = new DAL.CompanyInfo();
            }
            info.CompanyName = txt_name.Text;
            info.Mobile      = txt_mobile.Text;
            info.Phone       = txt_phone.Text;
            info.Address     = txt_address.Text;
            db.SubmitChanges();
            XtraMessageBox.Show("تم الحفظ بنجاح");
        }
示例#14
0
        public override void Save()
        {
            if (IsDataValidated() == false)
            {
                return;
            }

            var db = new DAL.dbDataContext();

            if (category.ID == 0)
            {
                db.ProductCategories.InsertOnSubmit(category);
            }
            else
            {
                db.ProductCategories.Attach(category);
            }

            SetData();
            db.SubmitChanges();

            base.Save();
        }
示例#15
0
        public override void Delete()
        {
            var db = new DAL.dbDataContext();

            if (XtraMessageBox.Show(text: "هل تريد حذف المخزن", caption: "تاكيد الحذف",
                                    buttons: MessageBoxButtons.YesNo,
                                    icon: MessageBoxIcon.Question) == DialogResult.Yes)
            {
                var log        = db.StoreLogs.Where(x => x.SourceID == store.ID).Count();
                var accountLog = db.Journals.Where(x => x.AccountID == store.CostOfSoldGoodsAccountID ||
                                                   x.AccountID == store.SalesAccountID ||
                                                   x.AccountID == store.SalesReturnAccountID ||
                                                   x.AccountID == store.InventoryAccountID
                                                   ).Count();

                if (log + accountLog > 0)
                {
                    XtraMessageBox.Show(text: "عفوا لا يمكن حذف المخزن حيث ام استخادمه في النظام "
                                        , caption: "", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error);

                    return;
                }

                db.Stores.Attach(store);
                db.Stores.DeleteOnSubmit(store);
                db.Accounts.DeleteAllOnSubmit(db.Accounts.Where(x =>
                                                                x.ID == store.CostOfSoldGoodsAccountID ||
                                                                x.ID == store.SalesAccountID ||
                                                                x.ID == store.SalesReturnAccountID ||
                                                                x.ID == store.InventoryAccountID
                                                                ));
                db.SubmitChanges();
                XtraMessageBox.Show("تم الحذف بنجاح");
                New();
            }
        }
示例#16
0
        public override void Save()
        {
            gridView1.UpdateCurrentRow();
            var db = new DAL.dbDataContext();

            if (invoice.ID == 0)
            {
                db.InvoiceHeaders.InsertOnSubmit(invoice);
            }
            else
            {
                db.InvoiceHeaders.Attach(invoice);
            }
            SetData();

            var items = (Collection <DAL.InvoiceDetail>)gridView1.DataSource;


            if (invoice.Expences > 0)
            {
                var            totalPrice  = items.Sum(x => x.TotalPrice);
                var            totalQTY    = items.Sum(x => x.ItemQty);
                var            ByPriceUnit = invoice.Expences / totalPrice; // السعر لكل جنيه واحد
                var            ByQtyUnit   = invoice.Expences / totalQTY;   //السعر لكل قطعه واحده من الوحده المختاره
                XtraDialogArgs args        = new XtraDialogArgs();
                UserControls.CostDistributionOption distributionOption = new UserControls.CostDistributionOption();
                args.Caption = "";
                args.Content = distributionOption;
                ((XtraBaseArgs)args).Buttons = new DialogResult[]
                {
                    DialogResult.OK
                };
                args.Showing += Args_Showing;

                XtraDialog.Show(args);


                foreach (var row in items)
                {
                    if (distributionOption.SelectedOption == Master.CostDistributionOptions.ByPrice)
                    {
                        row.CostValue = (row.TotalPrice / row.ItemQty) + (ByPriceUnit * row.Price); // توزيع بالسعر
                    }
                    else
                    {
                        row.CostValue = (row.TotalPrice / row.ItemQty) + (ByQtyUnit); // توزيع بالكميه
                    }
                    row.TotalCostValue = row.ItemQty * row.CostValue;
                }
            }
            else
            {
                foreach (var row in items)
                {
                    row.CostValue      = row.TotalPrice / row.ItemQty;
                    row.TotalCostValue = row.TotalPrice;
                }
            }
            var msg = $"   {invoice.ID} لعميل {glkp_PartID.Text} فاتوره مبيعات رقم ";

            #region Journals


            // فاتوره بقيمه بضاعه 1000
            // ضريبه 120
            // مصروف نقل 100
            // خصم 50

            //  1170  الصافي


            //         حساب المخزون           - مدين - 1100
            //         حساب ضريبه مضافه       - مدين -  120
            // حساب المورد            - دائن -         1220


            //          حساب المورد          - مدين - 50
            //     حساب خصم نقدي مكتسب  - دائن -      50


            //        حساب المورد         -مدين - 1000
            //   حساب الخذنه         -دائن -      1000
            db.Journals.DeleteAllOnSubmit(db.Journals.Where(x => x.SourceType == (byte)type && x.SourceID == invoice.ID));
            db.SubmitChanges();
            var partAccountID = db.CustomersAndVendors.Single(x => x.ID == invoice.PartID).AccountID;
            var store         = db.Stores.Single(x => x.ID == invoice.Branch);
            var drawer        = db.Drawers.Single(x => x.ID == invoice.Drawer);
            db.Journals.InsertOnSubmit(new DAL.Journal() // Part
            {
                AccountID  = partAccountID,
                Code       = 54545,
                Credit     = invoice.Total + invoice.TaxValue + invoice.Expences,
                Debit      = 0,
                InsertDate = invoice.Date,
                Notes      = msg,
                SourceID   = invoice.ID,
                SourceType = (byte)type,
            });
            db.Journals.InsertOnSubmit(new DAL.Journal() // Store Inventory
            {
                AccountID  = store.InventoryAccountID,
                Code       = 54545,
                Credit     = 0,
                Debit      = invoice.Total + invoice.Expences,
                InsertDate = invoice.Date,
                Notes      = msg,
                SourceID   = invoice.ID,
                SourceType = (byte)type,
            });

            if (invoice.Tax > 0)
            {
                db.Journals.InsertOnSubmit(new DAL.Journal() //
                {
                    AccountID  = Session.Defaults.PurchaseTax,
                    Code       = 54545,
                    Credit     = 0,
                    Debit      = invoice.TaxValue,
                    InsertDate = invoice.Date,
                    Notes      = msg + " - ضريبه مضافه ",
                    SourceID   = invoice.ID,
                    SourceType = (byte)type,
                });
            }
            //if (Invoice.Expences  > 0)
            //    db.Journals.InsertOnSubmit(new DAL.Journal() //
            //    {
            //        AccountID = Session.Defualts.PurchaseExpences,
            //        Code = 54545,
            //        Credit = 0,
            //        Debit = Invoice.Expences,
            //        InsertDate = Invoice.Date,
            //        Notes = msg + " -   مصروفات شراء",
            //        SourceID = Invoice.ID,
            //        SourceType = (byte)Type,
            //    });

            if (invoice.DiscountVale > 0)
            {
                db.Journals.InsertOnSubmit(new DAL.Journal() // Store Tax
                {
                    AccountID  = Session.Defaults.DiscountReceivedAccount,
                    Code       = 54545,
                    Credit     = invoice.DiscountVale,
                    Debit      = 0,
                    InsertDate = invoice.Date,
                    Notes      = msg + " -   خصم شراء",
                    SourceID   = invoice.ID,
                    SourceType = (byte)type,
                });
                db.Journals.InsertOnSubmit(new DAL.Journal() // Store Tax
                {
                    AccountID  = partAccountID,
                    Code       = 54545,
                    Credit     = 0,
                    Debit      = invoice.DiscountVale,
                    InsertDate = invoice.Date,
                    Notes      = msg + " -   خصم شراء",
                    SourceID   = invoice.ID,
                    SourceType = (byte)type,
                });
            }


            if (invoice.Paid > 0)
            {
                db.Journals.InsertOnSubmit(new DAL.Journal() //
                {
                    AccountID  = drawer.AccountID,
                    Code       = 54545,
                    Credit     = invoice.Paid,
                    Debit      = 0,
                    InsertDate = invoice.Date,
                    Notes      = msg + " - سداد",
                    SourceID   = invoice.ID,
                    SourceType = (byte)type,
                });
                db.Journals.InsertOnSubmit(new DAL.Journal() //
                {
                    AccountID  = partAccountID,
                    Code       = 54545,
                    Credit     = 0,
                    Debit      = invoice.Paid,
                    InsertDate = invoice.Date,
                    Notes      = msg + " - سداد",
                    SourceID   = invoice.ID,
                    SourceType = (byte)type,
                });
            }
            #endregion


            foreach (var row in items)
            {
                row.InvoiceID = invoice.ID;
            }
            generalDB.SubmitChanges();
            db.StoreLogs.DeleteAllOnSubmit(db.StoreLogs.Where(x => x.SourceType == (byte)type && x.SourceID == invoice.ID));
            db.SubmitChanges();
            if (invoice.PostedToStore)
            {
                foreach (var row in items)
                {
                    var unitView = Session.ProductsView.Single(x => x.ID == row.ItemID).Units.Single(x => x.UnitID == row.ItemUnitID);
                    db.StoreLogs.InsertOnSubmit(new DAL.StoreLog()
                    {
                        ProductID       = row.ItemID,
                        InsertTime      = invoice.PostDate.Value,
                        SourceID        = invoice.ID,
                        SourceType      = (byte)type,
                        Notes           = msg,
                        IsInTransaction = true,
                        StoreID         = row.StoreID,
                        Qty             = row.ItemQty * unitView.Factor,
                        CostValue       = row.CostValue / unitView.Factor
                    });
                }
            }
            db.SubmitChanges();
            base.Save();
        }