Exemplo n.º 1
0
        protected void btnSave_Click(object sender, ImageClickEventArgs e)
        {
            try
            {
                ADAM.DataBase.ADAMConnectionString mdb = new DataBase.ADAMConnectionString();
                for (int Row = 0; Row < gvItemContent.Rows.Count; Row++)
                {
                    CheckBox chkChoose = gvItemContent.Rows[Row].FindControl("chkChoose") as CheckBox;
                    if (chkChoose.Checked)
                    {
                        decimal Qty        = decimal.Parse(gvItemContent.Rows[Row].Cells[8].Text);
                        long    ItemMoveId = long.Parse(gvItemContent.DataKeys[Row][0].ToString());
                        long    ProductionDetailsOrderId = long.Parse(gvItemContent.DataKeys[Row][1].ToString());
                        hfProductionDetailsOrderId.Value = ProductionDetailsOrderId.ToString();

                        ADAM.DataBase.ItemMovement itmMovementdr = mdb.ItemMovements.Single(a => a.Id == ItemMoveId);
                        itmMovementdr.MainQtyOut = itmMovementdr.MainQtyOut + Qty;

                        var Rows = from a in mdb.ItemMovements
                                   where a.MovmentnameId == 21 && a.ItemColorId == itmMovementdr.ItemColorId &&
                                   a.ItemId == itmMovementdr.ItemId && a.DocmentId == ProductionDetailsOrderId
                                   select a;

                        if (Rows.Count() > 0)
                        {
                            continue;
                        }

                        ADAM.DataBase.ItemMovement Nmovedr = new DataBase.ItemMovement();
                        Nmovedr.AdditionalQty        = 0;
                        Nmovedr.AdditionalQtyOut     = 0;
                        Nmovedr.AuditDetailsId       = 0;
                        Nmovedr.DocmentId            = ProductionDetailsOrderId;
                        Nmovedr.IncommingOrderNo     = itmMovementdr.IncommingOrderNo;
                        Nmovedr.ItemColorId          = itmMovementdr.ItemColorId;
                        Nmovedr.ItemId               = itmMovementdr.ItemId;
                        Nmovedr.ItemUnitId           = itmMovementdr.ItemUnitId;
                        Nmovedr.LocatioId            = itmMovementdr.LocatioId;
                        Nmovedr.MainQty              = Qty * -1;
                        Nmovedr.MainQtyOut           = 0;
                        Nmovedr.MovementDate         = DateTime.Now;
                        Nmovedr.MovmentnameId        = 21;
                        Nmovedr.RecDate              = DateTime.Now;
                        Nmovedr.StoreId              = itmMovementdr.StoreId;
                        Nmovedr.SupplyOrderDetailsId = 0;
                        Nmovedr.ParentItemMoveMentId = itmMovementdr.Id;

                        mdb.ItemMovements.Add(Nmovedr);
                        mdb.SaveChanges();
                    }
                }
                ADAM.DataBase.ProductionDetailsOrder Proddr = mdb.ProductionDetailsOrders.Single(a => a.Id == long.Parse(hfProductionDetailsOrderId.Value));
                Proddr.Status = 1;
                mdb.SaveChanges();
            }
            catch { }
        }
Exemplo n.º 2
0
        protected void gvPurchaseDetailsData_SelectedIndexChanged(object sender, EventArgs e)
        {
            ADAM.DataBase.ADAMConnectionString Mdb = new DataBase.ADAMConnectionString();
            ADAM.DataBase.DeliveryDataDetail   PurchaseDetailsdr = Mdb.DeliveryDataDetails.Single(a => a.Id == long.Parse(gvDeliveryData.SelectedDataKey.Value.ToString()));
            hfPurchaseDetailsId.Value = PurchaseDetailsdr.Id.ToString();
            PurchaseDetailsdr.Status  = 1;

            DropDownList ddlLoction = gvDeliveryData.SelectedRow.FindControl("ddlLocation") as DropDownList;

            if (ddlLoction.SelectedValue == "0")
            {
                Response.Write("<script>alert('من فضلك أدخل الـ Location')</script>");
                return;
            }

            TextBox txtQty        = gvDeliveryData.SelectedRow.FindControl("txtRealQty") as TextBox;
            TextBox txtRealTester = gvDeliveryData.SelectedRow.FindControl("txtRealTester") as TextBox;

            if (string.IsNullOrEmpty(txtQty.Text) || (decimal.Parse(txtQty.Text) == 0 && PurchaseDetailsdr.Qty > 0))
            {
                Response.Write("<script>alert('من فضلك أدخل الكمية بشكل صحيح')</script>");
                return;
            }

            #region Insert Into Movement

            ADAM.DataBase.ItemMovement itmmovdr = new DataBase.ItemMovement();
            itmmovdr.AdditionalQty    = decimal.Parse(txtRealTester.Text);
            itmmovdr.AdditionalQtyOut = 0;
            itmmovdr.AuditDetailsId   = 0;
            itmmovdr.DocmentId        = PurchaseDetailsdr.Id;
            itmmovdr.IncommingOrderNo = 0;
            itmmovdr.ItemColorId      = PurchaseDetailsdr.ItemColorId;
            itmmovdr.ItemId           = PurchaseDetailsdr.ItemId;
            ADAM.DataBase.Item itmdr = Mdb.Items.Single(a => a.Id == PurchaseDetailsdr.ItemId);
            itmmovdr.ItemUnitId           = itmdr.ItemunitId;
            itmmovdr.LocatioId            = long.Parse(ddlLoction.SelectedValue);
            itmmovdr.MainQty              = decimal.Parse(txtQty.Text);
            itmmovdr.MainQtyOut           = 0;
            itmmovdr.MovementDate         = DateTime.Now;
            itmmovdr.MovmentnameId        = 16;
            itmmovdr.RecDate              = DateTime.Now;
            itmmovdr.StoreId              = 2;
            itmmovdr.SupplyOrderDetailsId = 0;
            itmmovdr.ParentItemMoveMentId = 0;

            Mdb.ItemMovements.Add(itmmovdr);
            Mdb.SaveChanges();
            #endregion
            gvDeliveryData.DataBind();
        }
        protected void gvItems_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                ADAM.DataBase.ADAMConnectionString mdb = new DataBase.ADAMConnectionString();
                TextBox      txtMainQty       = gvItems.SelectedRow.FindControl("txtMainQty") as TextBox;
                TextBox      txtAdditionalQty = gvItems.SelectedRow.FindControl("txtAdditionalQty") as TextBox;
                int          ItemColorId      = int.Parse(gvItems.SelectedDataKey[1].ToString());
                DropDownList ddlLocation      = gvItems.SelectedRow.FindControl("ddlLocation") as DropDownList;

                ADAM.DataBase.Item itmdr = mdb.Items.Single(a => a.Code == long.Parse(gvItems.SelectedRow.Cells[0].Text) && a.ItemTypeId == long.Parse(ddlItemType.SelectedValue));

                var CountRows = from a in mdb.ItemMovements
                                where a.StoreId == 2 && a.ItemColorId == ItemColorId && a.ItemId == itmdr.Id &&
                                a.MovmentnameId == long.Parse(ddlItemMovementName.SelectedValue)
                                select a;

                if (CountRows.Count() > 0 && ddlItemMovementName.SelectedValue == "6")
                {
                    Response.Write("<script>alert('لقد تم ادخل رصيد مدة لهذا الصنف مع هذا اللون')</script>");
                    return;
                }

                if (string.IsNullOrEmpty(txtMainQty.Text) || string.IsNullOrEmpty(txtAdditionalQty.Text) || ddlLocation.SelectedValue == "0")
                {
                    Response.Write("<script>alert('من فضلك تأكد من ادخال الكميات بشكل صحيح وفي حالة عدم الرغبه في ادخال كمية ادخل صفر')</script>");
                    return;
                }

                ADAM.DataBase.ItemMovement dr = new DataBase.ItemMovement();
                dr.AdditionalQty        = decimal.Parse(txtAdditionalQty.Text);
                dr.DocmentId            = 0;
                dr.ItemColorId          = ItemColorId;
                dr.ItemId               = itmdr.Id;
                dr.ItemUnitId           = itmdr.ItemunitId;
                dr.LocatioId            = int.Parse(ddlLocation.SelectedValue);
                dr.MainQty              = decimal.Parse(txtMainQty.Text);
                dr.MovementDate         = DateTime.Now;
                dr.MovmentnameId        = long.Parse(ddlItemMovementName.SelectedValue);
                dr.RecDate              = DateTime.Now;
                dr.StoreId              = 2;
                dr.SupplyOrderDetailsId = 0;
                dr.ParentItemMoveMentId = 0;

                mdb.ItemMovements.Add(dr);
                mdb.SaveChanges();
            }
            catch { }
        }
Exemplo n.º 4
0
        protected void gvItemMovement_SelectedIndexChanged(object sender, EventArgs e)
        {
            ADAM.DataBase.ADAMConnectionString Mdb   = new DataBase.ADAMConnectionString();
            ADAM.DataBase.ItemMovement         movdr = Mdb.ItemMovements.Single(a => a.Id == long.Parse(gvItemMovement.SelectedDataKey.Value.ToString()));
            TextBox txtQtyOut     = gvItemMovement.SelectedRow.FindControl("txtQtyOut") as TextBox;
            TextBox txtfreeQtyOut = gvItemMovement.SelectedRow.FindControl("txtfreeQtyOut") as TextBox;


            if ((movdr.MainQtyOut + decimal.Parse(txtQtyOut.Text) <= movdr.MainQty) && (movdr.AdditionalQtyOut + decimal.Parse(txtfreeQtyOut.Text) <= movdr.AdditionalQty))
            {
                movdr.MainQtyOut       = movdr.MainQtyOut + decimal.Parse(txtQtyOut.Text);
                movdr.AdditionalQtyOut = movdr.AdditionalQtyOut + decimal.Parse(txtfreeQtyOut.Text);

                var ExchangeRequestOrderRows = from a in Mdb.ExchangeRequestDetailsDatas
                                               where a.ExchangeRequestHeaderData.OrderType == long.Parse(ddlExchangeRequestType.SelectedValue) &&
                                               a.Status == 1
                                               orderby a.ExchangeRequestOrder descending
                                               select a;

                if (ExchangeRequestOrderRows.Count() <= 0)
                {
                    hfExchangeRequestOrder.Value = "1";
                }
                else
                {
                    if (hfExchangeRequestOrder.Value == "0")
                    {
                        hfExchangeRequestOrder.Value = (ExchangeRequestOrderRows.First().ExchangeRequestOrder + 1).ToString();
                    }
                }

                ADAM.DataBase.ExchangeRequestDetailsData Exdr = Mdb.ExchangeRequestDetailsDatas.Single(a => a.Id == long.Parse(hfDetailsId.Value));
                if ((decimal.Parse(txtQtyOut.Text)) > (Exdr.Qty + Exdr.Bounce))
                {
                    Response.Write("<script>alert('لا يمكن ان يكون الكمية المنصرفة اكبر من كمية طلب الصرف')</script>");
                    return;
                }
                if ((decimal.Parse(txtfreeQtyOut.Text)) > (Exdr.FreeQty))
                {
                    Response.Write("<script>alert('لا يمكن ان يكون الكمية Tester المنصرفة اكبر من كمية طلب الصرف')</script>");
                    return;
                }
                Exdr.ExchangeRequestOrder = long.Parse(hfExchangeRequestOrder.Value);
                Exdr.Status = 1;

                if (movdr.IncommingOrderNo != 0)
                {
                    ADAM.DataBase.IncommingOrderData incdr = Mdb.IncommingOrderDatas.Single(a => a.IncommingOrderNo == movdr.IncommingOrderNo && a.AuditDetailsId == movdr.AuditDetailsId);
                    Exdr.IncommingOrderId = incdr.Id;
                    Exdr.LocationId       = movdr.LocatioId;
                }

                ADAM.DataBase.ItemMovement dr = new DataBase.ItemMovement();
                dr.AdditionalQty        = decimal.Parse(txtfreeQtyOut.Text) * -1;
                dr.AdditionalQtyOut     = 0;
                dr.AuditDetailsId       = movdr.AuditDetailsId;
                dr.DocmentId            = Exdr.Id;
                dr.IncommingOrderNo     = movdr.IncommingOrderNo;
                dr.ItemColorId          = movdr.ItemColorId;
                dr.ItemId               = movdr.ItemId;
                dr.ItemUnitId           = movdr.ItemUnitId;
                dr.LocatioId            = movdr.LocatioId;
                dr.MainQty              = decimal.Parse(txtQtyOut.Text) * -1;
                dr.MainQtyOut           = 0;
                dr.MovementDate         = DateTime.Now;
                dr.MovmentnameId        = int.Parse(ddlExchangeRequestType.Text);
                dr.RecDate              = DateTime.Now;
                dr.StoreId              = movdr.StoreId;
                dr.SupplyOrderDetailsId = movdr.SupplyOrderDetailsId;
                dr.ParentItemMoveMentId = movdr.Id;
                Mdb.ItemMovements.Add(dr);

                Exdr.IncommingOrderNo = movdr.IncommingOrderNo;

                Mdb.SaveChanges();

                Exdr.MovementId = dr.Id;

                gvExchangeRequestData.DataBind();
            }
            else
            {
                Response.Write("<script>alert('لا يمكن ان يكون الكمية المنصرفة اكبر من كمية الرصيد الحالي')</script>");
                return;
            }
        }
Exemplo n.º 5
0
        //protected void btnEditOrderItem_Click(object sender, ImageClickEventArgs e)
        //{
        //    try
        //    {
        //        ADAM.DataBase.ADAMConnectionString mdb = new DataBase.ADAMConnectionString();
        //        ADAM.DataBase.RefluxDetailsData ddr = mdb.RefluxDetailsDatas.Single(a => a.Id == long.Parse(RefluxDetailsId.Value));
        //        if (ddr.RefluxHeaderData.OrderType == 1)
        //        {
        //            ADAM.DataBase.PurchaseOredrDetail purchasedr = mdb.PurchaseOredrDetails.Single(a => a.Id == ddr.ExchangeOrPurchaseDetailsId);
        //            if (decimal.Parse(txtQty.Text) > purchasedr.ConformQty)
        //            {
        //                Response.Write("<script>alert('لا يمكن ان تكون الكمية المرتجعة اكبر من الكمية الموجوده في طلب الشراء')</script>");
        //                return;
        //            }
        //        }

        //        if (ddr.RefluxHeaderData.OrderType == 2)
        //        {
        //            ADAM.DataBase.ExchangeRequestDetailsData detailsdr = mdb.ExchangeRequestDetailsDatas.Single(a => a.Id == ddr.ExchangeOrPurchaseDetailsId);
        //            if (decimal.Parse(txtQty.Text) > detailsdr.Qty)
        //            {
        //                Response.Write("<script>alert('لا يمكن ان تكون الكمية المرتجعة اكبر من الكمية الموجوده في طلب الصرف')</script>");
        //                return;
        //            }

        //            if (decimal.Parse(txtFreeQty.Text) > detailsdr.FreeQty)
        //            {
        //                Response.Write("<script>alert('لا يمكن ان تكون الكمية المجانية المرتجعة اكبر من الكمية الموجوده في طلب الصرف')</script>");
        //                return;
        //            }
        //        }

        //        ddr.RefluxQty = decimal.Parse(txtQty.Text);
        //        ddr.RefluxFreeQty = decimal.Parse(txtFreeQty.Text);

        //        mdb.SaveChanges();
        //        gvReflux.DataBind();
        //    }
        //    catch { }
        //}

        protected void btnSave_Click(object sender, ImageClickEventArgs e)
        {
            ADAM.DataBase.ADAMConnectionString mdb = new DataBase.ADAMConnectionString();
            ADAM.DataBase.RefluxDetailsData    ddr = mdb.RefluxDetailsDatas.Single(a => a.Id == long.Parse(RefluxDetailsId.Value));
            if (ddr.RefluxHeaderData.OrderType == 1)
            {
                ADAM.DataBase.PurchaseOredrDetail Pdr = mdb.PurchaseOredrDetails.Single(a => a.Id == ddr.ExchangeOrPurchaseDetailsId);
                if (Pdr.Status == 2)
                {
                    Pdr.IsClosed = 1;
                }
                else
                {
                    Response.Write("<script>alert('لا يمكن ارتجاع هذا الصنف حيث انه ليس في حالة جديد لطلب الشراء')</script>");
                    return;
                }
            }
            else if (ddr.RefluxHeaderData.OrderType == 2)
            {
                ADAM.DataBase.ExchangeRequestDetailsData Edr = mdb.ExchangeRequestDetailsDatas.Single(a => a.Id == ddr.ExchangeOrPurchaseDetailsId);
                if (Edr.Status == 0)
                {
                    Response.Write("<script>alert('لا يمكن ارتجاع هذا الصنف حيث انه لم يتم صرفه')</script>");
                    return;
                }
                else if (Edr.Status != 0)
                {
                    long incommingOrder = 0;
                    long AuditDetailsId = 0;
                    long MovementnameId = 6;

                    var incomeRows = from a in mdb.ItemMovements
                                     where (a.MovmentnameId == 3 || a.MovmentnameId == 6) && a.ItemId == ddr.ItemId && a.ItemColorId == ddr.ItemColorId && a.IncommingOrderNo == long.Parse(txtIncommingOrder.Text)
                                     select a;

                    if (incomeRows.Count() <= 0)
                    {
                        Response.Write("<script>alert('من فضلك تأكد من رقم أذن الوارد')</script>");
                        return;
                    }

                    if (!string.IsNullOrEmpty(txtIncommingOrder.Text) && long.Parse(txtIncommingOrder.Text) > 0)
                    {
                        incommingOrder = long.Parse(txtIncommingOrder.Text);
                        MovementnameId = 3;
                    }

                    ADAM.DataBase.ItemMovement itmmovdr = mdb.ItemMovements.Single(a => a.IncommingOrderNo == incommingOrder && a.AuditDetailsId == AuditDetailsId &&
                                                                                   a.MovmentnameId == MovementnameId && a.ItemColorId == ddr.ItemColorId && a.ItemId == ddr.ItemId);

                    itmmovdr.MainQtyOut       = itmmovdr.MainQtyOut - (ddr.RefluxQty + ddr.Bounce);
                    itmmovdr.AdditionalQtyOut = itmmovdr.AdditionalQtyOut - ddr.RefluxFreeQty;

                    ADAM.DataBase.ItemMovement Nmov = new DataBase.ItemMovement();
                    Nmov.AdditionalQty        = ddr.RefluxFreeQty;
                    Nmov.AuditDetailsId       = AuditDetailsId;
                    Nmov.DocmentId            = ddr.Id;
                    Nmov.IncommingOrderNo     = incommingOrder;
                    Nmov.ItemColorId          = itmmovdr.ItemColorId;
                    Nmov.ItemId               = ddr.ItemId;
                    Nmov.LocatioId            = itmmovdr.LocatioId;
                    Nmov.ItemUnitId           = itmmovdr.ItemUnitId;
                    Nmov.MainQty              = ddr.RefluxQty + ddr.Bounce;
                    Nmov.MainQtyOut           = Nmov.AdditionalQtyOut = 0;
                    Nmov.MovementDate         = DateTime.Now;
                    Nmov.MovmentnameId        = 13;
                    Nmov.RecDate              = DateTime.Now;
                    Nmov.StoreId              = itmmovdr.StoreId;
                    Nmov.SupplyOrderDetailsId = itmmovdr.SupplyOrderDetailsId;
                    Nmov.ParentItemMoveMentId = itmmovdr.Id;
                    mdb.ItemMovements.Add(Nmov);
                }
                ddr.Status = 1;
            }
            mdb.SaveChanges();
            gvReflux.DataBind();
        }
Exemplo n.º 6
0
        private void SaveData()
        {
            try
            {
                ADAM.DataBase.ADAMConnectionString Mdb = new DataBase.ADAMConnectionString();

                var LocRows = from a in Mdb.ItemLocations where a.ItemTypeId == int.Parse(ddlItemType.SelectedValue) select a;
                if (LocRows.Count() <= 0)
                {
                    Response.Write("<script>alert('لم يتم أنشاء Location لهذا المخزن من فضلك')</script>");
                    return;
                }

                #region Create RecordReceiptHeader
                ADAM.DataBase.RecordReceiptHeader dr = new DataBase.RecordReceiptHeader();
                dr.RecordReceiptDate = DateTime.Parse(txtRecordReceiptDate.Text);
                dr.RecordReceiptNo   = long.Parse(txtRecordReceiptNo.Text);
                dr.RecDate           = DateTime.Now;
                Mdb.RecordReceiptHeaders.Add(dr);
                Mdb.SaveChanges();
                #endregion

                for (int Row = 0; Row < gvRecordReceipt.Rows.Count; Row++)
                {
                    CheckBox chkChoose = gvRecordReceipt.Rows[Row].FindControl("chkChoose") as CheckBox;
                    if (chkChoose.Checked)
                    {
                        TextBox txtQtyReceived = gvRecordReceipt.Rows[Row].FindControl("txtQtyReceived") as TextBox;
                        TextBox txtFreeQty     = gvRecordReceipt.Rows[Row].FindControl("txtFreeQty") as TextBox;

                        decimal Qty = decimal.Parse(gvRecordReceipt.Rows[Row].Cells[8].Text);

                        if (decimal.Parse(txtQtyReceived.Text) > Qty)
                        {
                            Response.Write("<script>alert('لا يمكن ان تكون الكمية المستملة اكبر من الكمية الموجودة في امر التوريد')</script>");
                            return;
                        }

                        TextBox txtIndoor = gvRecordReceipt.Rows[Row].FindControl("txtIndoor") as TextBox;
                        TextBox txtNote   = gvRecordReceipt.Rows[Row].FindControl("txtNote") as TextBox;

                        if (string.IsNullOrEmpty(txtIndoor.Text) || string.IsNullOrEmpty(txtNote.Text) || string.IsNullOrEmpty(txtQtyReceived.Text))
                        {
                            Response.Write("<script>alert('من فضلك تأكد من ادخال باقي البيانات')</script>");
                            return;
                        }

                        long ItemId = Mdb.Items.Single(a => a.Code == long.Parse(gvRecordReceipt.Rows[Row].Cells[3].Text) && a.ItemTypeId == long.Parse(ddlItemType.SelectedValue)).Id;
                        long UnitId = Mdb.Items.Single(a => a.Id == ItemId).ItemunitId;

                        #region Create RecordReceiptDetails
                        ADAM.DataBase.RecordReceiptDetail recdetails = new DataBase.RecordReceiptDetail();
                        recdetails.Indoor                = txtIndoor.Text;
                        recdetails.ItemId                = ItemId;
                        recdetails.Note                  = txtNote.Text;
                        recdetails.QtyReceived           = decimal.Parse(txtQtyReceived.Text);
                        recdetails.FreeQty               = decimal.Parse(txtFreeQty.Text);
                        recdetails.RecordReceiptHeaderId = dr.Id;
                        recdetails.SupplyOrderDetailsId  = long.Parse(gvRecordReceipt.DataKeys[Row].Value.ToString());
                        Mdb.RecordReceiptDetails.Add(recdetails);
                        #endregion

                        #region Update PurchaseOrderDetail
                        ADAM.DataBase.SupplyOrderDetail   supdr = Mdb.SupplyOrderDetails.Single(a => a.Id == long.Parse(gvRecordReceipt.DataKeys[Row].Value.ToString()));
                        ADAM.DataBase.PurchaseOredrDetail Purdr = Mdb.PurchaseOredrDetails.Single(a => a.Id == supdr.PurchaseOrderDetailsId);
                        Purdr.IsChecked = 6;
                        Mdb.SaveChanges();
                        #endregion

                        #region Create AuditHeader
                        if (hfAuditHeaderId.Value == "0")
                        {
                            ADAM.DataBase.AuditHeader auddr = new DataBase.AuditHeader();
                            auddr.AuditNo   = GetAuditNum();
                            auddr.AuditDate = DateTime.Now;
                            Mdb.AuditHeaders.Add(auddr);
                            Mdb.SaveChanges();
                            hfAuditHeaderId.Value = auddr.Id.ToString();
                        }
                        #endregion

                        #region Create AuditDetail + Create ItemMovement
                        ADAM.DataBase.AuditDetail auddetailsdr = new DataBase.AuditDetail();
                        auddetailsdr.AcceptQty              = 0;
                        auddetailsdr.AuditDetailsDate       = DateTime.Now;
                        auddetailsdr.AuditHeaderId          = long.Parse(hfAuditHeaderId.Value);
                        auddetailsdr.EmployeeId             = 0;
                        auddetailsdr.RecDate                = DateTime.Now;
                        auddetailsdr.RecordReceiptDetailsId = recdetails.Id;
                        auddetailsdr.RefusedQty             = 0;
                        auddetailsdr.Note           = "لا يوجد";
                        auddetailsdr.AcceptfreeQty  = 0;
                        auddetailsdr.RefusedFreeQty = 0;
                        Mdb.AuditDetails.Add(auddetailsdr);

                        ADAM.DataBase.ItemMovement movdr = new DataBase.ItemMovement();
                        movdr.AdditionalQty = decimal.Parse(txtFreeQty.Text);
                        movdr.DocmentId     = recdetails.Id;
                        movdr.ItemId        = ItemId;
                        movdr.MainQty       = decimal.Parse(txtQtyReceived.Text);
                        movdr.MovementDate  = DateTime.Now;
                        movdr.MovmentnameId = 1;
                        movdr.RecDate       = DateTime.Now;
                        movdr.StoreId       = 1;
                        var Rows = from a in Mdb.ItemLocations where a.ItemTypeId == int.Parse(ddlItemType.SelectedValue) select a;
                        movdr.LocatioId            = Rows.First().Id;
                        movdr.ItemUnitId           = UnitId;
                        movdr.ItemColorId          = Purdr.ItemColorId;
                        movdr.SupplyOrderDetailsId = supdr.Id;
                        movdr.ParentItemMoveMentId = 0;

                        Mdb.ItemMovements.Add(movdr);
                        Mdb.SaveChanges();
                        #endregion
                    }
                }
                Response.Write("<script>alert('تمت عملية الحفظ بنجاح')</script>");
                Response.Redirect("~/StoreData/webRecordReceiptData.aspx");
            }
            catch { Response.Write("<script>alert('خطأ أثناء الحفظ من فضلك تأكد من ادخال البيانات بشكل صحيح او الاتصال بقاعدة البيانات')</script>"); }
        }
Exemplo n.º 7
0
        protected void gvBalance_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                long    MovementId = long.Parse(gvBalance.SelectedDataKey.Value.ToString());
                TextBox txtQty     = gvBalance.SelectedRow.FindControl("txtQty") as TextBox;
                TextBox txtTester  = gvBalance.SelectedRow.FindControl("txtTester") as TextBox;
                if (string.IsNullOrEmpty(txtQty.Text) && string.IsNullOrEmpty(txtTester.Text))
                {
                    return;
                }

                ADAM.DataBase.ADAMConnectionString mdb   = new DataBase.ADAMConnectionString();
                ADAM.DataBase.ItemMovement         movdr = mdb.ItemMovements.Single(a => a.Id == MovementId);

                if (!string.IsNullOrEmpty(txtQty.Text))
                {
                    ADAM.DataBase.ItemMovement newmovdr = new DataBase.ItemMovement();
                    newmovdr.AdditionalQty        = 0;
                    newmovdr.AdditionalQtyOut     = 0;
                    newmovdr.AuditDetailsId       = movdr.AuditDetailsId;
                    newmovdr.DocmentId            = 0;
                    newmovdr.IncommingOrderNo     = movdr.IncommingOrderNo;
                    newmovdr.ItemColorId          = movdr.ItemColorId;
                    newmovdr.ItemId               = movdr.ItemId;
                    newmovdr.ItemUnitId           = movdr.ItemUnitId;
                    newmovdr.LocatioId            = movdr.LocatioId;
                    newmovdr.MainQty              = -1 * decimal.Parse(txtQty.Text);
                    newmovdr.MainQtyOut           = 0;
                    newmovdr.MovementDate         = DateTime.Now;
                    newmovdr.MovmentnameId        = 18;
                    newmovdr.RecDate              = DateTime.Now;
                    newmovdr.StoreId              = movdr.StoreId;
                    newmovdr.SupplyOrderDetailsId = movdr.SupplyOrderDetailsId;
                    newmovdr.ParentItemMoveMentId = movdr.Id;
                    mdb.ItemMovements.Add(newmovdr);

                    movdr.MainQtyOut    += decimal.Parse(txtQty.Text);
                    movdr.AdditionalQty += decimal.Parse(txtQty.Text);

                    ADAM.DataBase.ItemMovement newmovddr = new DataBase.ItemMovement();
                    newmovddr.AdditionalQty        = decimal.Parse(txtQty.Text);
                    newmovddr.AdditionalQtyOut     = 0;
                    newmovddr.AuditDetailsId       = movdr.AuditDetailsId;
                    newmovddr.DocmentId            = 0;
                    newmovddr.IncommingOrderNo     = movdr.IncommingOrderNo;
                    newmovddr.ItemColorId          = movdr.ItemColorId;
                    newmovddr.ItemId               = movdr.ItemId;
                    newmovddr.ItemUnitId           = movdr.ItemUnitId;
                    newmovddr.LocatioId            = movdr.LocatioId;
                    newmovddr.MainQty              = 0;
                    newmovddr.MainQtyOut           = 0;
                    newmovddr.MovementDate         = DateTime.Now;
                    newmovddr.MovmentnameId        = 15;
                    newmovddr.RecDate              = DateTime.Now;
                    newmovddr.StoreId              = movdr.StoreId;
                    newmovddr.SupplyOrderDetailsId = movdr.SupplyOrderDetailsId;
                    newmovddr.ParentItemMoveMentId = movdr.Id;
                    mdb.ItemMovements.Add(newmovddr);
                }

                if (!string.IsNullOrEmpty(txtTester.Text))
                {
                    ADAM.DataBase.ItemMovement newmovdr = new DataBase.ItemMovement();
                    newmovdr.AdditionalQty        = -1 * decimal.Parse(txtTester.Text);
                    newmovdr.AdditionalQtyOut     = 0;
                    newmovdr.AuditDetailsId       = movdr.AuditDetailsId;
                    newmovdr.DocmentId            = 0;
                    newmovdr.IncommingOrderNo     = movdr.IncommingOrderNo;
                    newmovdr.ItemColorId          = movdr.ItemColorId;
                    newmovdr.ItemId               = movdr.ItemId;
                    newmovdr.ItemUnitId           = movdr.ItemUnitId;
                    newmovdr.LocatioId            = movdr.LocatioId;
                    newmovdr.MainQty              = 0;
                    newmovdr.MainQtyOut           = 0;
                    newmovdr.MovementDate         = DateTime.Now;
                    newmovdr.MovmentnameId        = 19;
                    newmovdr.RecDate              = DateTime.Now;
                    newmovdr.StoreId              = movdr.StoreId;
                    newmovdr.SupplyOrderDetailsId = movdr.SupplyOrderDetailsId;
                    newmovdr.ParentItemMoveMentId = movdr.Id;
                    mdb.ItemMovements.Add(newmovdr);

                    movdr.AdditionalQtyOut += decimal.Parse(txtTester.Text);
                    movdr.MainQty          += decimal.Parse(txtTester.Text);

                    ADAM.DataBase.ItemMovement newmovddr = new DataBase.ItemMovement();
                    newmovddr.AdditionalQty        = 0;
                    newmovddr.AdditionalQtyOut     = 0;
                    newmovddr.AuditDetailsId       = movdr.AuditDetailsId;
                    newmovddr.DocmentId            = 0;
                    newmovddr.IncommingOrderNo     = movdr.IncommingOrderNo;
                    newmovddr.ItemColorId          = movdr.ItemColorId;
                    newmovddr.ItemId               = movdr.ItemId;
                    newmovddr.ItemUnitId           = movdr.ItemUnitId;
                    newmovddr.LocatioId            = movdr.LocatioId;
                    newmovddr.MainQty              = decimal.Parse(txtTester.Text);
                    newmovddr.MainQtyOut           = 0;
                    newmovddr.MovementDate         = DateTime.Now;
                    newmovddr.MovmentnameId        = 14;
                    newmovddr.RecDate              = DateTime.Now;
                    newmovddr.StoreId              = movdr.StoreId;
                    newmovddr.SupplyOrderDetailsId = movdr.SupplyOrderDetailsId;
                    newmovddr.ParentItemMoveMentId = movdr.Id;
                    mdb.ItemMovements.Add(newmovddr);
                }

                mdb.SaveChanges();
                gvBalance.DataBind();
                gvItems.DataBind();
            }
            catch { }
        }
Exemplo n.º 8
0
        protected void btnConform_Click(object sender, ImageClickEventArgs e)
        {
            if (Session["UserID"] == null)
            {
                Response.Redirect("~/BasicData/webLogIn.aspx");
            }
            int userid      = int.Parse(Session["UserID"].ToString());
            int operationid = 7;

            csGetPermission Per = new csGetPermission();

            if (!Per.getPermission(userid, pageid, operationid))
            {
                Response.Redirect("~/BasicData/webHomePage.aspx");
            }

            if (string.IsNullOrEmpty(txtAuditNo.Text))
            {
                Response.Write("<script>alert('من فضلك تأكد من ادخال رقم اخطار الفحص')</script>");
                return;
            }

            ADAM.DataBase.ADAMConnectionString mdb = new DataBase.ADAMConnectionString();
            for (int Row = 0; Row < gvAuditData.Rows.Count; Row++)
            {
                CheckBox chkChoose = gvAuditData.Rows[Row].FindControl("chkChoose") as CheckBox;
                if (chkChoose.Checked)
                {
                    DropDownList ddlEmployee       = gvAuditData.Rows[Row].FindControl("ddlEmployee") as DropDownList;
                    TextBox      txtAcceptQty      = gvAuditData.Rows[Row].FindControl("txtAcceptQty") as TextBox;
                    TextBox      txtRefused        = gvAuditData.Rows[Row].FindControl("txtRefused") as TextBox;
                    TextBox      txtNote           = gvAuditData.Rows[Row].FindControl("txtNote") as TextBox;
                    DropDownList ddlLocation       = gvAuditData.Rows[Row].FindControl("ddlLocation") as DropDownList;
                    TextBox      txtFreeAcceptQty  = gvAuditData.Rows[Row].FindControl("txtFreeAcceptQty") as TextBox;
                    TextBox      txtfreeRefusedQty = gvAuditData.Rows[Row].FindControl("txtfreeRefusedQty") as TextBox;

                    if (ddlEmployee.SelectedValue == "0" || ddlLocation.SelectedValue == "0" || string.IsNullOrEmpty(txtAcceptQty.Text) ||
                        string.IsNullOrEmpty(txtRefused.Text) || string.IsNullOrEmpty(txtFreeAcceptQty.Text) || string.IsNullOrEmpty(txtfreeRefusedQty.Text))
                    {
                        Response.Write("<script>alert('من فضلك تأكد من ادخال كل البيانات بشكل صحيح')</script>");
                        return;
                    }

                    decimal Qty = decimal.Parse(gvAuditData.Rows[Row].Cells[2].Text);
                    if ((decimal.Parse(txtAcceptQty.Text) + decimal.Parse(txtRefused.Text)) != Qty)
                    {
                        Response.Write("<script>alert('يجب ان يساوي مجموع الكمية المقبولة والكمية المرفوضة الكمية المستلمة')</script>");
                        Response.Write("<script>alert(' الكمية المستلمة هي " + Qty + "')</script>");
                        return;
                    }

                    decimal AllAuditQty = 0;

                    long AuditDetailId = long.Parse(gvAuditData.DataKeys[Row].Value.ToString());
                    ADAM.DataBase.AuditDetail auddr = mdb.AuditDetails.Single(a => a.Id == AuditDetailId);

                    ADAM.DataBase.RecordReceiptDetail rrdr = mdb.RecordReceiptDetails.Single(a => a.Id == auddr.RecordReceiptDetailsId);

                    ADAM.DataBase.SupplyOrderDetail supdr = mdb.SupplyOrderDetails.Single(a => a.Id == rrdr.SupplyOrderDetailsId);
                    if (supdr.ItemPrice <= 0)
                    {
                        Response.Write("<script>alert('امر التوريد رقم " + supdr.SupplyOrderHeader.SupplyOrderNo + "والمرتبط بهذا الاجراء من فضلك قم بتسعير امر التوريد')</script>");

                        #region DelJournal

                        for (int DelRow = 0; DelRow < gvAuditData.Rows.Count; DelRow++)
                        {
                            if (DelRow > Row)
                            {
                                continue;
                            }

                            chkChoose = gvAuditData.Rows[DelRow].FindControl("chkChoose") as CheckBox;
                            if (chkChoose.Checked)
                            {
                                ADAM.DataBase.AuditDetail         Delauddr = mdb.AuditDetails.Single(a => a.Id == AuditDetailId);
                                ADAM.DataBase.RecordReceiptDetail Delrrdr  = mdb.RecordReceiptDetails.Single(a => a.Id == auddr.RecordReceiptDetailsId);
                                ADAM.DataBase.SupplyOrderDetail   Delsupdr = mdb.SupplyOrderDetails.Single(a => a.Id == rrdr.SupplyOrderDetailsId);
                                var JourHeaderRows = from a in mdb.JournalHeaders where a.DocId == Delsupdr.Id select a;
                                if (JourHeaderRows.Count() > 0)
                                {
                                    ADAM.DataBase.JournalHeader Deljournal = mdb.JournalHeaders.Single(a => a.DocId == Delsupdr.Id);
                                    var DelJournalRow = from a in mdb.JournalDetails where a.JournalId == Deljournal.Id select a;
                                    if (DelJournalRow.Count() > 0)
                                    {
                                        foreach (ADAM.DataBase.JournalDetail delJornalDetail in DelJournalRow)
                                        {
                                            mdb.JournalDetails.Remove(delJornalDetail);
                                        }
                                        mdb.SaveChanges();
                                    }
                                }
                            }
                        }

                        #endregion

                        return;
                    }

                    ADAM.DataBase.PurchaseOredrDetail Purddr = mdb.PurchaseOredrDetails.Single(a => a.Id == supdr.PurchaseOrderDetailsId);
                    int ItemColorId = Purddr.ItemColorId;

                    var RecDetails = from a in mdb.RecordReceiptDetails where a.SupplyOrderDetailsId == supdr.Id select a;
                    foreach (ADAM.DataBase.RecordReceiptDetail recdr in RecDetails)
                    {
                        ADAM.DataBase.AuditDetail auditdr = mdb.AuditDetails.Single(a => a.RecordReceiptDetailsId == recdr.Id);
                        AllAuditQty = AllAuditQty + auditdr.AcceptQty;
                    }
                    AllAuditQty = AllAuditQty + decimal.Parse(txtAcceptQty.Text);

                    if (AllAuditQty > Purddr.ConformQty)
                    {
                        Response.Write("<script>alert('لا يمكن ان تكون اجمالي الكميات المستلمة اكبر من كمية طلب الشراء المعتمدة')</script>");
                        return;
                    }

                    #region Update AuditDetails
                    auddr.EmployeeId = long.Parse(ddlEmployee.SelectedValue);
                    auddr.AcceptQty  = decimal.Parse(txtAcceptQty.Text);
                    auddr.RefusedQty = decimal.Parse(txtRefused.Text);
                    if (!string.IsNullOrEmpty(txtNote.Text))
                    {
                        auddr.Note = txtNote.Text;
                    }
                    auddr.AcceptfreeQty  = decimal.Parse(txtFreeAcceptQty.Text);
                    auddr.RefusedFreeQty = decimal.Parse(txtfreeRefusedQty.Text);
                    #endregion

                    long UnitId = mdb.Items.Single(a => a.Id == rrdr.ItemId).ItemunitId;

                    //-----------------------------------------------------------------------
                    #region Insert IntoIncommingOrderTable

                    long IncomOrderNo = GetIncoOrderData(long.Parse(ddlItemType.SelectedValue.ToString()));
                    ADAM.DataBase.IncommingOrderData Incdr = new DataBase.IncommingOrderData();
                    Incdr.AuditDetailsId         = auddr.Id;
                    Incdr.FreeItemPrice          = 0;
                    Incdr.IncommingOrderNo       = IncomOrderNo;
                    Incdr.ItemPrice              = supdr.ItemPrice;
                    Incdr.ItemTypeId             = long.Parse(ddlItemType.SelectedValue.ToString());
                    Incdr.RecordReceiptDetailsId = rrdr.Id;
                    Incdr.LocationId             = int.Parse(ddlLocation.SelectedValue);
                    mdb.IncommingOrderDatas.Add(Incdr);

                    #endregion
                    //------------------------------------------------------------------------

                    #region Insert AcceptQty
                    if (decimal.Parse(txtAcceptQty.Text) > 0)
                    {
                        ADAM.DataBase.ItemMovement itmdr = new DataBase.ItemMovement();
                        itmdr.AdditionalQty = decimal.Parse(txtFreeAcceptQty.Text) * -1;
                        itmdr.DocmentId     = auddr.Id;
                        itmdr.ItemId        = rrdr.ItemId;
                        itmdr.MainQty       = decimal.Parse(txtAcceptQty.Text) * -1;
                        itmdr.MovementDate  = DateTime.Now;
                        itmdr.MovmentnameId = 2;
                        itmdr.RecDate       = DateTime.Now;
                        itmdr.StoreId       = 1;
                        var Rows = from a in mdb.ItemLocations where a.ItemTypeId == int.Parse(ddlItemType.SelectedValue) select a;
                        itmdr.LocatioId            = Rows.First().Id;
                        itmdr.ItemUnitId           = UnitId;
                        itmdr.SupplyOrderDetailsId = rrdr.SupplyOrderDetailsId;
                        itmdr.ItemColorId          = ItemColorId;
                        itmdr.IncommingOrderNo     = 0;
                        itmdr.AuditDetailsId       = auddr.Id;
                        itmdr.AdditionalQtyOut     = 0;
                        itmdr.MainQtyOut           = 0;
                        itmdr.ParentItemMoveMentId = 0;
                        mdb.ItemMovements.Add(itmdr);

                        ADAM.DataBase.ItemMovement Nitmdr = new DataBase.ItemMovement();
                        Nitmdr.AdditionalQty        = decimal.Parse(txtFreeAcceptQty.Text);
                        Nitmdr.DocmentId            = auddr.Id;
                        Nitmdr.ItemId               = rrdr.ItemId;
                        Nitmdr.MainQty              = decimal.Parse(txtAcceptQty.Text);
                        Nitmdr.MovementDate         = DateTime.Now;
                        Nitmdr.MovmentnameId        = 3;
                        Nitmdr.RecDate              = DateTime.Now;
                        Nitmdr.StoreId              = 2;
                        Nitmdr.LocatioId            = int.Parse(ddlLocation.SelectedValue);
                        Nitmdr.ItemUnitId           = UnitId;
                        Nitmdr.SupplyOrderDetailsId = rrdr.SupplyOrderDetailsId;
                        Nitmdr.ItemColorId          = ItemColorId;
                        Nitmdr.IncommingOrderNo     = IncomOrderNo;
                        Nitmdr.AuditDetailsId       = auddr.Id;
                        Nitmdr.AdditionalQtyOut     = 0;
                        Nitmdr.MainQtyOut           = 0;
                        Nitmdr.ParentItemMoveMentId = 0;
                        mdb.ItemMovements.Add(Nitmdr);
                    }
                    #endregion

                    #region Insert RefuseQty
                    if (decimal.Parse(txtRefused.Text) > 0)
                    {
                        ADAM.DataBase.ItemMovement itmdr = new DataBase.ItemMovement();
                        itmdr.AdditionalQty = decimal.Parse(txtfreeRefusedQty.Text) * -1;
                        itmdr.DocmentId     = auddr.Id;
                        itmdr.ItemId        = rrdr.ItemId;
                        itmdr.MainQty       = decimal.Parse(txtRefused.Text) * -1;
                        itmdr.MovementDate  = DateTime.Now;
                        itmdr.MovmentnameId = 4;
                        itmdr.RecDate       = DateTime.Now;
                        itmdr.StoreId       = 1;
                        var Rows = from a in mdb.ItemLocations where a.ItemTypeId == int.Parse(ddlItemType.SelectedValue) select a;
                        itmdr.LocatioId            = Rows.First().Id;
                        itmdr.ItemUnitId           = UnitId;
                        itmdr.SupplyOrderDetailsId = rrdr.SupplyOrderDetailsId;
                        itmdr.ItemColorId          = ItemColorId;
                        itmdr.IncommingOrderNo     = 0;
                        itmdr.AuditDetailsId       = auddr.Id;
                        itmdr.AdditionalQtyOut     = 0;
                        itmdr.MainQtyOut           = 0;
                        itmdr.ParentItemMoveMentId = 0;
                        mdb.ItemMovements.Add(itmdr);

                        ADAM.DataBase.ItemMovement Nitmdr = new DataBase.ItemMovement();
                        Nitmdr.AdditionalQty        = decimal.Parse(txtfreeRefusedQty.Text);
                        Nitmdr.DocmentId            = auddr.Id;
                        Nitmdr.ItemId               = rrdr.ItemId;
                        Nitmdr.MainQty              = decimal.Parse(txtRefused.Text);
                        Nitmdr.MovementDate         = DateTime.Now;
                        Nitmdr.MovmentnameId        = 5;
                        Nitmdr.RecDate              = DateTime.Now;
                        Nitmdr.StoreId              = 3;
                        Nitmdr.LocatioId            = Rows.First().Id;
                        Nitmdr.ItemUnitId           = UnitId;
                        Nitmdr.SupplyOrderDetailsId = rrdr.SupplyOrderDetailsId;
                        Nitmdr.ItemColorId          = ItemColorId;
                        Nitmdr.IncommingOrderNo     = IncomOrderNo;
                        Nitmdr.AuditDetailsId       = auddr.Id;
                        Nitmdr.AdditionalQtyOut     = 0;
                        Nitmdr.MainQtyOut           = 0;
                        Nitmdr.ParentItemMoveMentId = 0;
                        mdb.ItemMovements.Add(Nitmdr);
                    }
                    #endregion

                    Purddr.IsChecked = 7;
                    if (AllAuditQty == Purddr.ConformQty)
                    {
                        Purddr.IsClosed = 1;
                    }

                    #region InsertJournalCode

                    //      من حـ / المخزن
                    // الي حـ / المورد

                    ADAM.DataBase.ItemType     itemTypedr = mdb.ItemTypes.Single(a => a.Id == long.Parse(ddlItemType.SelectedValue));
                    ADAM.DataBase.SupplierData Supplierdr = mdb.SupplierDatas.Single(a => a.Id == supdr.SupplyOrderHeader.SupplierId);
                    csJournal CsJornalRow = new csJournal();

                    long JournalHeaderId = CsJornalRow.InsertIntoJournalHeader(0, DateTime.Now, 9, "دخول البضاعة الي المخزن", 0, supdr.SupplyOrderHeaderId);
                    CsJornalRow.InsertIntoJournalDetails(itemTypedr.AccountId, supdr.SupplyOrderHeader.CostCenter, (decimal.Parse(txtAcceptQty.Text) * supdr.ItemPrice), 0, JournalHeaderId, "من ح/ المخزن");
                    CsJornalRow.InsertIntoJournalDetails(Supplierdr.AccountId, supdr.SupplyOrderHeader.CostCenter, 0, (decimal.Parse(txtAcceptQty.Text) * supdr.ItemPrice), JournalHeaderId, "الي حـ / المورد");

                    #endregion
                }
            }
            mdb.SaveChanges();
            Response.Redirect("~/StoreData/webConformAudit.aspx");
        }