Exemple #1
0
        protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
        {
            if (FormsAuthentication.CookiesSupported == true)
            {
                if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
                {
                    try
                    {
                        //let us take out the username now
                        string username = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name;

                        String userRole = "";
                        using (OracleEntitiesConnStr db = new OracleEntitiesConnStr())
                        {
                            APPUSER        appuser        = db.APPUSERs.SingleOrDefault(u => u.USERNAME.Equals(username, StringComparison.OrdinalIgnoreCase));
                            USERPERMISSION userpermission = db.USERPERMISSIONs.SingleOrDefault(u => u.USERID == appuser.ID);
                            string         role           = userpermission.ROLENAME;
                            userRole = role;
                            System.Web.HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(
                                new System.Security.Principal.GenericIdentity(username, "Forms"), new[] { userRole });
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Exemple #2
0
        public ActionResult DeleteRequest(string rejectMessage, int id = 0)
        {
            UPREQUEST request    = db.UPREQUESTs.Find(id);
            UPREQUEST newRequest = new UPREQUEST();

            newRequest.ID            = request.ID;
            newRequest.STATUS        = 10;
            newRequest.BONDERID      = request.BONDERID;
            newRequest.CREATEDBY     = request.CREATEDBY;
            newRequest.CREATEDDATE   = request.CREATEDDATE;
            newRequest.MODIFIEDBY    = request.MODIFIEDBY;
            newRequest.MODIFIEDDATE  = request.MODIFIEDDATE;
            newRequest.REJECTCOMMENT = rejectMessage;

            if (newRequest != null)
            {
                using (var db2 = new OracleEntitiesConnStr())
                {
                    db2.Entry(newRequest).State = EntityState.Modified;
                    db2.SaveChanges();
                }
            }


            return(Redirect(ControllerContext.HttpContext.Request.UrlReferrer.ToString()));
        }
Exemple #3
0
 public static string getBonderName(short id = 0)
 {
     using (OracleEntitiesConnStr db = new OracleEntitiesConnStr()){
         BONDER bonder = db.BONDERs.Find(id);
         if (bonder == null)
         {
             return(String.Empty);
         }
         return(bonder.BONDERNAME);
     }
 }
Exemple #4
0
        public void AddBonderAnnualEntitlementCoE(int?BonderSlno, int id, int[] ProductCoE, string[] ProductWeightCoE, string[] ProductDescriptionCoE, string[] ProductSizeCoE,
                                                  string[] ProductMeasurementCoE, string[] ProductRawmaterialsCoE, int[] ProductMachineCoE, int[] hscodesCoE, int[] RawmaterialProductID,
                                                  int[] measuementoCoE, int[] grossCoEs, int[] wastageCoEs, int[] shrinkageCoEs, int[] netCoEs)
        {
            if (ProductCoE != null)
            {
                int lenth = ProductCoE.Length;

                for (int i = 0; i < lenth; i++)
                {
                    BONDERANNUALENTITLEMENTCOM bonderannualentitlementcom = new BONDERANNUALENTITLEMENTCOM();

                    bonderannualentitlementcom.AESLNO      = (Int16)id;
                    bonderannualentitlementcom.BONDERSLNO  = (Int16)BonderSlno;
                    bonderannualentitlementcom.MSLNO       = (Int16)ProductCoE[i];
                    bonderannualentitlementcom.WEIGHT      = ProductWeightCoE[i];
                    bonderannualentitlementcom.MSIZE       = ProductSizeCoE[i];
                    bonderannualentitlementcom.MEASUREMENT = ProductMeasurementCoE[i];
                    //bonderannualentitlementcom.MDESC = ProductDescriptionCoE[i];
                    bonderannualentitlementcom.MACHINESLNO = (Int16)ProductMachineCoE[i];

                    for (int j = 0; j < hscodesCoE.Length; j++)
                    {
                        BONDERANNUALENTITLEMENTCOEDET bonderannualentitlementcoedet = new BONDERANNUALENTITLEMENTCOEDET();

                        OracleEntitiesConnStr db2 = new OracleEntitiesConnStr();

                        if (ProductCoE[i] == RawmaterialProductID[j])
                        {
                            bonderannualentitlementcoedet.AESLNO      = (Int16)id;
                            bonderannualentitlementcoedet.BONDERSLNO  = (Int16)BonderSlno;
                            bonderannualentitlementcoedet.MSLNO       = (Int16)ProductCoE[i];
                            bonderannualentitlementcoedet.RMSLNO      = (Int16)hscodesCoE[j];
                            bonderannualentitlementcoedet.GROSSQT     = (Int16)grossCoEs[j];
                            bonderannualentitlementcoedet.WASTAGEQT   = (Int16)wastageCoEs[j];
                            bonderannualentitlementcoedet.SHRINKAGEQT = (Int16)shrinkageCoEs[j];
                            bonderannualentitlementcoedet.NETQT       = (Int16)netCoEs[j];

                            db2.BONDERANNUALENTITLEMENTCOEDETs.Add(bonderannualentitlementcoedet);
                        }

                        db2.SaveChanges();
                    }


                    db.BONDERANNUALENTITLEMENTCOMs.Add(bonderannualentitlementcom);
                }

                db.SaveChanges();


                //db.SaveChanges();
            }
        }
Exemple #5
0
        public ActionResult AddRawMaterial(BACKTOBACKPRODUCT backtobackProduct)
        {
            USERPERMISSION userpermission = sessionAttributeRetreival.getStoredUserPermission();

            foreach (var item in backtobackProduct.RAWMATERIALs)
            {
                item.PRODUCTID = backtobackProduct.ID;
            }

            DateTime thisDay = DateTime.Now;
            var      user    = "******";

            System.Diagnostics.Debug.WriteLine("Time: " + thisDay + " ModelState.IsValid: " + ModelState.IsValid);

            // if (ModelState.IsValid)
            if (true)
            {
                try
                {
                    foreach (var rawMaterial in backtobackProduct.RAWMATERIALs)
                    {
                        var productId = rawMaterial.PRODUCTID;
                        System.Diagnostics.Debug.WriteLine("Time: " + thisDay + " productId: " + productId);
                        System.Diagnostics.Debug.WriteLine("Time: " + thisDay + " backtobackProduct.BACKTOBACKLCID: " + backtobackProduct.BACKTOBACKLCID);
                        using (var dbRawMaterial = new OracleEntitiesConnStr())
                        {
                            RAWMATERIAL newRawMaterial = new RAWMATERIAL();
                            newRawMaterial.RAWMATERIALCODE = rawMaterial.RAWMATERIALCODE;
                            newRawMaterial.QUANTITY        = rawMaterial.QUANTITY;
                            newRawMaterial.UNIT            = rawMaterial.UNIT;
                            newRawMaterial.PERMITTEDWASTE  = rawMaterial.PERMITTEDWASTE;
                            newRawMaterial.PRODUCTID       = productId;
                            if (userpermission != null)
                            {
                                newRawMaterial.CREATEDBY = userpermission.APPUSER.USERNAME;
                            }
                            newRawMaterial.CREATEDDATE = thisDay;

                            dbRawMaterial.RAWMATERIALs.Add(newRawMaterial);
                            dbRawMaterial.SaveChanges();
                        }
                    }

                    return(RedirectToAction("Details/" + backtobackProduct.BACKTOBACKLCID));
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Create(BACKTOBACKPRODUCTs): Time-" + thisDay + " Exception = " + e.StackTrace);
                }
            }

            return(View());
        }
Exemple #6
0
        public ActionResult DeleteConfirmed(short id)
        {
            APPUSER appuser = db.APPUSERs.Find(id);
            OracleEntitiesConnStr userDb          = new OracleEntitiesConnStr();
            List <USERPERMISSION> userPermissions = userDb.USERPERMISSIONs.Where(u => u.USERID == appuser.ID).ToList();

            foreach (USERPERMISSION userpermission in userPermissions)
            {
                userDb.USERPERMISSIONs.Remove(userpermission);
                userDb.SaveChanges();
            }

            db.APPUSERs.Remove(appuser);
            db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Exemple #7
0
        public ActionResult CreateOREditUP(IList <UPREQUEST> requests, string UPNO, short ID = 0)
        {
            USERPERMISSION    loggedinUser = sessionAttributeRetreival.getStoredUserPermission();
            IList <UPREQUEST> requestList  = new List <UPREQUEST>();
            UP   up            = new UP();
            bool flag          = true;
            bool isanyselected = false;

            if (UPNO == null || UPNO.Equals(""))
            {
                return(RedirectToAction("Create", new { error = "Please Provide UP NO" }));
            }
            else
            {
                UP duplicateUp = db.UPs.SingleOrDefault(u => u.UPNO.Equals(UPNO));
                if (duplicateUp != null)
                {
                    return(RedirectToAction("Create", new { error = "UP No Already Exists" }));
                }
            }
            for (int i = 0; i < requests.Count(); i++)
            {
                int id = requests[i].ID;
                if (requests[i].IsSelected)
                {
                    isanyselected = true;
                    UPREQUEST request      = db.UPREQUESTs.Find(id);
                    int       productCount = request.UPEXBONDLISTs.Count();
                    if (productCount < 1)
                    {
                        flag = false;
                    }
                    else
                    {
                        requestList.Add(request);
                        up.BONDERID = request.BONDERID;
                    }
                }
            }
            if (!isanyselected && ID <= 0)
            {
                return(RedirectToAction("Create", new { error = "Please select at least one exbond" }));
            }
            if (!flag && ID <= 0)
            {
                return(RedirectToAction("Create", new { error = "Sorry! please check all selected Requests has at least one exbond" }));
            }
            else
            {
                short lastInserted = 0;

                if (ID <= 0)//add new UP
                {
                    DateTime thisDay = DateTime.Today;
                    up.CREATEDDATE = thisDay;
                    if (loggedinUser != null)
                    {
                        up.CREATEDBY = loggedinUser.APPUSER.USERNAME;
                    }
                    up.UPNO = UPNO;
                    db.UPs.Add(up);
                    db.SaveChanges();
                    lastInserted = db.UPs.Max(item => item.ID);
                }
                else//Edit existing UP
                {
                    if (loggedinUser != null)
                    {
                        up.MODIFIEDBY = loggedinUser.APPUSER.USERNAME;
                    }
                    up = db.UPs.Find(ID);
                    UP newUp = new UP();
                    newUp.ID           = ID;
                    newUp.BONDERID     = up.BONDERID;
                    newUp.UPNO         = up.UPNO;
                    newUp.MODIFIEDDATE = DateTime.Today;
                    newUp.CREATEDDATE  = up.CREATEDDATE;
                    newUp.CREATEDBY    = up.CREATEDBY;
                    using (var db2 = new OracleEntitiesConnStr())
                    {
                        db2.Entry(newUp).State = EntityState.Modified;
                        db2.SaveChanges();
                    }
                    lastInserted = ID;
                }
                for (int x = 0; x < requestList.Count(); x++)
                {
                    using (var db1 = new OracleEntitiesConnStr())//save value to relational table
                    {
                        UPREQUESTLIST uprequestList = new UPREQUESTLIST();
                        uprequestList.UPREQUESTID = requestList[x].ID;
                        uprequestList.UPID        = lastInserted;
                        db1.UPREQUESTLISTs.Add(uprequestList);
                        db1.SaveChanges();
                    }
                    using (var db2 = new OracleEntitiesConnStr()) //change status of up request as approved
                    {
                        UPREQUEST request = new UPREQUEST();      // db.UPREQUESTs.Find(requestList[x].ID);
                        request.ID               = requestList[x].ID;
                        request.BONDERID         = requestList[x].BONDERID;
                        request.STATUS           = 20; //approved
                        db2.Entry(request).State = EntityState.Modified;
                        db2.SaveChanges();
                    }
                }

                return(RedirectToAction("Index"));
            }
        }
        public ActionResult createOrEditRequest(IList <EXBOND> exbonds, IList <ATTACHMENT> attachments, short ID = 0)
        {
            USERPERMISSION loggedinUser = new SessionAttributeRetreival().getStoredUserPermission();

            if (TempData["isAnyAttachment"] != null)
            {
                bool isAnyAttachment = (bool)TempData["isAnyAttachment"];
                if (!isAnyAttachment)
                {
                    attachments = null;
                }
            }
            var files = Request.Files;

            //for (int i = 0; i < Request.Files.Count; i++)
            //{
            //    HttpPostedFileBase file = files[i];
            //    var fileName = Path.GetFileName(file.FileName);
            //}
            if (attachments != null)
            {
                foreach (ATTACHMENT attachment in attachments)
                {
                    if (attachment != null && attachment.CONTENT == null && attachment.ID == 0 && attachment.NAME == null)
                    {
                        if (ID <= 0)
                        {
                            return(RedirectToAction("Create", new { error = "Please provide a valid file" }));
                        }
                        else
                        {
                            return(RedirectToAction("AddMoreAttachment", new { ID, errorMessage = "Please provide a valid file" }));
                        }
                    }
                }
            }
            bool attachmentValid = false;

            foreach (string extensions in GlobalConstants.extensions)
            {
                try
                {
                    if (attachments.Any(item => item.CONTENT.EndsWith(extensions)))
                    {
                        attachmentValid = true;
                        break;
                    }
                }
                catch (Exception e) {
                    attachmentValid = true;
                }
            }
            if (!attachmentValid)
            {
                if (ID <= 0)
                {
                    return(RedirectToAction("Create", new { error = "Please provide a valid file" }));
                }
                else
                {
                    return(RedirectToAction("Edit", new { ID, error = "Please provide a valid file" }));
                }
            }
            List <ATTACHMENT> newAttachmentList = new List <ATTACHMENT>();

            if (attachments != null)
            {
                for (int i = 0; i < attachments.Count(); i++)
                {
                    if (attachments[i].CONTENT != null)
                    {
                        newAttachmentList.Add(attachments[i]);
                    }
                }
            }
            UPREQUEST      uprequest     = new UPREQUEST();
            IList <EXBOND> exbondList    = new List <EXBOND>();
            bool           flag          = true;
            bool           isanyselected = false;

            if (exbonds != null)
            {
                for (int i = 0; i < exbonds.Count(); i++)
                {
                    int id = exbonds[i].ID;
                    if (exbonds[i].IsSelected)
                    {
                        isanyselected = true;
                        EXBOND exbond   = db.EXBONDs.Find(id);
                        int    b2bCount = exbond.EXBONDBACKTOBACKs.Count();
                        if (exbond != null && b2bCount < 1)
                        {
                            flag = false;
                        }
                        else
                        {
                            uprequest.BONDERID = exbond.BONDERID;
                            exbondList.Add(exbond);
                        }
                    }
                }
            }
            if (!isanyselected && ID <= 0)
            {
                return(RedirectToAction("Create", new { error = "Please select at least one exbond" }));
            }
            if (!flag && ID <= 0)
            {
                return(RedirectToAction("Create", new { error = "Sorry! please check all selected Exbond has at least one backtoback" }));
            }
            else
            {
                short lastInserted = 0;
                //if (ModelState.IsValid)
                //{
                if (ID <= 0)
                {
                    DateTime thisDay = DateTime.Today;
                    uprequest.CREATEDDATE = thisDay;
                    if (loggedinUser != null)
                    {
                        uprequest.CREATEDBY = loggedinUser.APPUSER.USERNAME;
                    }
                    uprequest.STATUS = 2;
                    db.UPREQUESTs.Add(uprequest);
                    db.SaveChanges();
                    lastInserted = db.UPREQUESTs.Max(item => item.ID);
                }
                else
                {
                    uprequest = db.UPREQUESTs.Find(ID);
                    UPREQUEST newRequest = new UPREQUEST();
                    newRequest.ID           = ID;
                    newRequest.BONDERID     = uprequest.BONDERID;
                    newRequest.STATUS       = uprequest.STATUS;
                    newRequest.MODIFIEDDATE = DateTime.Today;
                    uprequest.CREATEDDATE   = uprequest.CREATEDDATE;
                    uprequest.CREATEDBY     = uprequest.CREATEDBY;
                    if (loggedinUser != null)
                    {
                        uprequest.MODIFIEDBY = loggedinUser.APPUSER.USERNAME;
                    }
                    using (var newdb2 = new OracleEntitiesConnStr())
                    {
                        newdb2.Entry(newRequest).State = EntityState.Modified;
                        newdb2.SaveChanges();
                    }
                    lastInserted = ID;
                }
                for (int x = 0; x < exbondList.Count(); x++)
                {
                    using (var db1 = new OracleEntitiesConnStr())
                    {
                        UPEXBONDLIST upexbond = new UPEXBONDLIST();
                        upexbond.EXBONDID    = exbondList[x].ID;
                        upexbond.UPREQUESTID = lastInserted;
                        db1.UPEXBONDLISTs.Add(upexbond);
                        db1.SaveChanges();
                    }
                }
                for (int k = 0; k < newAttachmentList.Count(); k++)
                {
                    string path = UploadedPath(files[k], newAttachmentList[k].CONTENT);
                    attachments[k].CONTENT = path;
                    using (var db2 = new OracleEntitiesConnStr())
                    {
                        attachments[k].UPREQUESTID = lastInserted;
                        db2.ATTACHMENTs.Add(attachments[k]);
                        db2.SaveChanges();
                    }
                }
                // }
                if (ID <= 0)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Edit/" + ID));
                }
            }
        }
        public ActionResult AddEntitlementCoefficient(int?aeslno, int?bonderslno, int[] ProductCoE, string[] ProductWeightCoE, string[] ProductDescriptionCoE,
                                                      string[] ProductSizeCoE, string[] ProductMeasurementCoE, string[] ProductRawmaterialsCoE, int[] ProductMachineCoE, int[] hscodesCoE
                                                      , int[] measuementoCoE, int[] grossCoEs, int[] wastageCoEs, int[] shrinkageCoEs, int[] netCoEs, int[] RawmaterialProductID)
        {
            try
            {
                if (ProductCoE != null)
                {
                    int lenth = ProductCoE.Length;

                    for (int i = 0; i < lenth; i++)
                    {
                        BONDERANNUALENTITLEMENTCOM bonderannualentitlementcom = new BONDERANNUALENTITLEMENTCOM();

                        bonderannualentitlementcom.AESLNO      = (Int16)aeslno;
                        bonderannualentitlementcom.BONDERSLNO  = (Int16)bonderslno;
                        bonderannualentitlementcom.MSLNO       = (Int16)ProductCoE[i];
                        bonderannualentitlementcom.WEIGHT      = ProductWeightCoE[i];
                        bonderannualentitlementcom.MSIZE       = ProductSizeCoE[i];
                        bonderannualentitlementcom.MEASUREMENT = ProductMeasurementCoE[i];
                        //bonderannualentitlementcom.MDESC = ProductDescriptionCoE[i];
                        bonderannualentitlementcom.MACHINESLNO = (Int16)ProductMachineCoE[i];

                        for (int j = 0; j < hscodesCoE.Length; j++)
                        {
                            BONDERANNUALENTITLEMENTCOEDET bonderannualentitlementcoedet = new BONDERANNUALENTITLEMENTCOEDET();

                            OracleEntitiesConnStr db2 = new OracleEntitiesConnStr();

                            if (ProductCoE[i] == RawmaterialProductID[j])
                            {
                                bonderannualentitlementcoedet.AESLNO      = (Int16)aeslno;
                                bonderannualentitlementcoedet.BONDERSLNO  = (Int16)bonderslno;
                                bonderannualentitlementcoedet.MSLNO       = (Int16)ProductCoE[i];
                                bonderannualentitlementcoedet.RMSLNO      = (Int16)hscodesCoE[j];
                                bonderannualentitlementcoedet.GROSSQT     = (Int16)grossCoEs[j];
                                bonderannualentitlementcoedet.WASTAGEQT   = (Int16)wastageCoEs[j];
                                bonderannualentitlementcoedet.SHRINKAGEQT = (Int16)shrinkageCoEs[j];
                                bonderannualentitlementcoedet.NETQT       = (Int16)netCoEs[j];

                                db2.BONDERANNUALENTITLEMENTCOEDETs.Add(bonderannualentitlementcoedet);
                            }

                            db2.SaveChanges();
                        }


                        db.BONDERANNUALENTITLEMENTCOMs.Add(bonderannualentitlementcom);
                    }

                    db.SaveChanges();
                }


                return(RedirectToAction("EntitlementDetails", new { ID = aeslno }));
            }


            catch
            {
                ViewBag.MachineList  = new SelectList(db.MACHINEINFORMATIONs, "MACHINESLNO", "MODELNM");
                ViewBag.Products     = new SelectList(db.MATERIALS.Where(p => p.MTYPE == "F"), "MSLNO", "MHSCODE");
                ViewBag.Rawmaterilas = new SelectList(db.MATERIALS.Where(r => r.MTYPE == "r"), "MSLNO", "MHSCODE");
                ViewBag.AeSlno       = aeslno;
                ViewBag.BonderSlno   = bonderslno;

                return(View());
            }
        }
Exemple #10
0
        public ActionResult Edit(BACKTOBACKLC backtobacklc)
        {
            USERPERMISSION loggedinUser = sessionAttributeRetreival.getStoredUserPermission();

            if (loggedinUser != null)
            {
                backtobacklc.MODIFIEDBY = loggedinUser.APPUSER.USERNAME;
            }
            if (loggedinUser != null && loggedinUser.BONDERID != null)
            {
                ViewBag.BONDERID = new SelectList(db.BONDERs.Where(b => b.BONDERSLNO == loggedinUser.BONDERID), "BONDERSLNO", "BONDERNAME", backtobacklc.BONDERID);
            }
            else
            {
                ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME", backtobacklc.BONDERID);
            }
            foreach (var item in backtobacklc.BACKTOBACKPRODUCTs)
            {
                item.BACKTOBACKLCID = backtobacklc.ID;
            }

            DateTime thisDay = DateTime.Now;


            bool isAddMore = false;

            if (true)
            {
                try
                {
                    if (backtobacklc.BACKTOBACKPRODUCTs != null && backtobacklc.BACKTOBACKPRODUCTs.Count > 0)
                    {
                        if (backtobacklc.BONDERID != null)
                        {
                            USERPERMISSION userpermission = sessionAttributeRetreival.getStoredUserPermission();
                            int            bonderId       = backtobacklc.BONDERID;
                            if (userpermission != null)
                            {
                                List <INBONDRAWMATERIAL> inbondRawMaterials = db.INBONDRAWMATERIALs.Where(inb => inb.INBOND.BONDERID == bonderId).ToList();
                                if (inbondRawMaterials != null)
                                {
                                    decimal bonderUsedQuantity     = inbondRawMaterials.Sum(item => item.PRODUCTQUANTITY);
                                    decimal?bonderProvidedQuantity = backtobacklc.BACKTOBACKPRODUCTs.Sum(item => item.QUANTITY);
                                    if (bonderUsedQuantity < bonderProvidedQuantity)
                                    {
                                        ModelState.AddModelError("", "Your Remaining Inbond Raw Material Quantity " + bonderUsedQuantity);
                                        ViewBag.BUYERSBANKBRANCHID = new SelectList(db.BANKBRANCHes, "BBRANCHSLNO", "BRANCHNAME", backtobacklc.BUYERSBANKBRANCHID);
                                        ViewBag.BUYERSBANKID       = new SelectList(db.BANKs, "BANKSLNO", "BANKNAME", backtobacklc.BUYERSBANKID);

                                        if (userpermission != null && userpermission.BONDERID != null)
                                        {
                                            ViewBag.BONDERID = new SelectList(db.BONDERs.Where(b => b.BONDERSLNO == userpermission.BONDERID), "BONDERSLNO", "BONDERNAME", userpermission.BONDERID);
                                        }
                                        else
                                        {
                                            ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME", backtobacklc.BONDERID);
                                        }
                                        ViewData["QUANTITYUNIT"] = new SelectList(model.QUANTITYUNITLIST, "Value", "Text", backtobacklc.QUANTITYUNIT);

                                        ViewData["PRICEUNIT"] = new SelectList(model.COSTUNITLIST, "Value", "Text", backtobacklc.PRICEUNIT);
                                        for (int i = 0; i < backtobacklc.BACKTOBACKPRODUCTs.Count(); i++)
                                        {
                                            ViewData["BACKTOBACKPRODUCTs[" + i + "].QUANTITYUNIT"] = new SelectList(model.QUANTITYUNITLIST, "Value", "Text", backtobacklc.BACKTOBACKPRODUCTs[i].QUANTITYUNIT);
                                        }
                                        for (int i = 0; i < backtobacklc.BACKTOBACKPRODUCTs.Count(); i++)
                                        {
                                            return(RedirectToAction("Addmore", new { errorMessage = "Your Remaining Inbond Raw Material Quantity " + bonderUsedQuantity, id = backtobacklc.ID }));
                                        }
                                        return(View(backtobacklc));
                                    }
                                }
                            }
                        }

                        System.Diagnostics.Debug.WriteLine("Edit(BACKTOBACKPRODUCTs): Time-" + thisDay + " BACKTOBACKPRODUCTs count = " + backtobacklc.BACKTOBACKPRODUCTs.Count);

                        foreach (var item in backtobacklc.BACKTOBACKPRODUCTs)
                        {
                            if (item.NAME != null)
                            {
                                System.Diagnostics.Debug.WriteLine("Edit(BACKTOBACKPRODUCTs): Time-" + thisDay + " item.ID = " + item.ID);
                                if (item.ID == 0)
                                {
                                    using (var db1 = new OracleEntitiesConnStr())
                                    {
                                        BACKTOBACKPRODUCT newItem = new BACKTOBACKPRODUCT();
                                        newItem.ID             = item.ID;
                                        newItem.BACKTOBACKLCID = item.BACKTOBACKLCID;
                                        newItem.NAME           = item.NAME;
                                        newItem.QUANTITY       = item.QUANTITY;
                                        newItem.QUANTITYUNIT   = item.QUANTITYUNIT;
                                        newItem.CREATEDDATE    = thisDay;
                                        newItem.SIZEANDDETAIL  = item.SIZEANDDETAIL;
                                        newItem.ID             = item.ID;
                                        db1.BACKTOBACKPRODUCTs.Add(newItem);
                                        db1.SaveChanges();
                                    }
                                    short lastProductId = db.BACKTOBACKPRODUCTs.Max(itemBack2Back => itemBack2Back.ID);
                                    foreach (var rawMaterial in item.RAWMATERIALs)
                                    {
                                        using (var dbRawMaterial = new OracleEntitiesConnStr())
                                        {
                                            RAWMATERIAL newRawMaterial = new RAWMATERIAL();
                                            newRawMaterial.RAWMATERIALCODE = rawMaterial.RAWMATERIALCODE;
                                            newRawMaterial.QUANTITY        = rawMaterial.QUANTITY;
                                            newRawMaterial.UNIT            = rawMaterial.UNIT;
                                            newRawMaterial.PERMITTEDWASTE  = rawMaterial.PERMITTEDWASTE;
                                            newRawMaterial.PRODUCTID       = lastProductId;
                                            newRawMaterial.CREATEDDATE     = thisDay;
                                            dbRawMaterial.RAWMATERIALs.Add(newRawMaterial);
                                            dbRawMaterial.SaveChanges();
                                        }
                                    }
                                }
                                if (item.ID > 0)
                                {
                                    using (var db1 = new OracleEntitiesConnStr())
                                    {
                                        BACKTOBACKPRODUCT newItem = new BACKTOBACKPRODUCT();
                                        newItem.ID               = item.ID;
                                        newItem.BACKTOBACKLCID   = item.BACKTOBACKLCID;
                                        newItem.NAME             = item.NAME;
                                        newItem.QUANTITY         = item.QUANTITY;
                                        newItem.QUANTITYUNIT     = item.QUANTITYUNIT;
                                        newItem.CREATEDDATE      = thisDay;
                                        newItem.SIZEANDDETAIL    = item.SIZEANDDETAIL;
                                        newItem.ID               = item.ID;
                                        db1.Entry(newItem).State = EntityState.Modified;
                                        db1.SaveChanges();
                                    }
                                    foreach (var rawMaterial in item.RAWMATERIALs)
                                    {
                                        using (var dbRawMaterial = new OracleEntitiesConnStr())
                                        {
                                            RAWMATERIAL newRawMaterial = new RAWMATERIAL();
                                            newRawMaterial.ID = rawMaterial.ID;
                                            newRawMaterial.RAWMATERIALCODE            = rawMaterial.RAWMATERIALCODE;
                                            newRawMaterial.QUANTITY                   = rawMaterial.QUANTITY;
                                            newRawMaterial.UNIT                       = rawMaterial.UNIT;
                                            newRawMaterial.PERMITTEDWASTE             = rawMaterial.PERMITTEDWASTE;
                                            newRawMaterial.PRODUCTID                  = item.ID;
                                            newRawMaterial.CREATEDDATE                = thisDay;
                                            dbRawMaterial.Entry(newRawMaterial).State = EntityState.Modified;
                                            dbRawMaterial.SaveChanges();
                                        }
                                    }
                                }
                            }
                        }


                        BACKTOBACKLC newBacktobacklc = new BACKTOBACKLC();
                        newBacktobacklc.BUYERSNAME             = backtobacklc.BUYERSNAME;
                        newBacktobacklc.BUYERSADDRESS          = backtobacklc.BUYERSADDRESS;
                        newBacktobacklc.LCNUMBER               = backtobacklc.LCNUMBER;
                        newBacktobacklc.LCDATE                 = backtobacklc.LCDATE;
                        newBacktobacklc.BUYERSBANKID           = backtobacklc.BUYERSBANKID;
                        newBacktobacklc.BUYERSBANKBRANCHID     = backtobacklc.BUYERSBANKBRANCHID;
                        newBacktobacklc.SHIPPINGDATE           = backtobacklc.SHIPPINGDATE;
                        newBacktobacklc.CORRECTIONDATE         = backtobacklc.CORRECTIONDATE;
                        newBacktobacklc.PRODUCTQUANTITY        = backtobacklc.PRODUCTQUANTITY;
                        newBacktobacklc.QUANTITYUNIT           = backtobacklc.QUANTITYUNIT;
                        newBacktobacklc.LCUSEDPRICE            = backtobacklc.LCUSEDPRICE;
                        newBacktobacklc.PRICEUNIT              = backtobacklc.PRICEUNIT;
                        newBacktobacklc.MASTERLCNUMBER         = backtobacklc.MASTERLCNUMBER;
                        newBacktobacklc.MASTERLCCORRECTIONDATE = backtobacklc.MASTERLCCORRECTIONDATE;
                        newBacktobacklc.UDNUMBER               = backtobacklc.UDNUMBER;
                        newBacktobacklc.UDDATE                 = backtobacklc.UDDATE;
                        newBacktobacklc.UDCORRECTIONDATE       = backtobacklc.UDCORRECTIONDATE;
                        newBacktobacklc.UDPRODUCTDETAIL        = backtobacklc.UDPRODUCTDETAIL;
                        newBacktobacklc.BONDERID               = backtobacklc.BONDERID;

                        newBacktobacklc.CREATEDBY   = backtobacklc.CREATEDBY;
                        newBacktobacklc.CREATEDDATE = backtobacklc.CREATEDDATE;
                        if (loggedinUser != null)
                        {
                            newBacktobacklc.MODIFIEDBY = loggedinUser.APPUSER.USERNAME;
                        }
                        newBacktobacklc.MODIFIEDDATE    = thisDay;
                        newBacktobacklc.ID              = backtobacklc.ID;
                        db.Entry(newBacktobacklc).State = EntityState.Modified;
                        db.SaveChanges();
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception e)
                {
                    ViewBag.BUYERSBANKBRANCHID = new SelectList(db.BANKBRANCHes, "BBRANCHSLNO", "BRANCHNAME", backtobacklc.BUYERSBANKBRANCHID);
                    ViewBag.BUYERSBANKID       = new SelectList(db.BANKs, "BANKSLNO", "BANKNAME", backtobacklc.BUYERSBANKID);

                    ViewData["QUANTITYUNIT"] = new SelectList(model.QUANTITYUNITLIST, "Value", "Text", backtobacklc.QUANTITYUNIT);

                    ViewData["PRICEUNIT"] = new SelectList(model.COSTUNITLIST, "Value", "Text", backtobacklc.PRICEUNIT);
                    for (int i = 0; i < backtobacklc.BACKTOBACKPRODUCTs.Count(); i++)
                    {
                        if (backtobacklc.BACKTOBACKPRODUCTs[i].ID <= 0)
                        {
                            isAddMore = true;
                        }
                        ViewData["BACKTOBACKPRODUCTs[" + i + "].QUANTITYUNIT"] = new SelectList(model.QUANTITYUNITLIST, "Value", "Text", backtobacklc.BACKTOBACKPRODUCTs[i].QUANTITYUNIT);
                    }
                    var message = string.Join(" | ", ModelState.Values
                                              .SelectMany(v => v.Errors)
                                              .Select(c => c.ErrorMessage));
                    ViewBag.error = "all field values are required for product!";

                    if (isAddMore)
                    {
                        return(RedirectToAction("Addmore", new { errorMessage = message, id = backtobacklc.ID }));
                    }

                    return(Redirect(ControllerContext.HttpContext.Request.UrlReferrer.ToString()));
                }
            }
            return(View(backtobacklc));
        }
Exemple #11
0
        public ActionResult Create(BACKTOBACKLC backToBackLC)
        {
            USERPERMISSION loggedinUser = sessionAttributeRetreival.getStoredUserPermission();

            if (loggedinUser != null)
            {
                backToBackLC.CREATEDBY = loggedinUser.APPUSER.USERNAME;
            }
            if (loggedinUser != null && loggedinUser.BONDERID != null)
            {
                ViewBag.BONDERID = new SelectList(db.BONDERs.Where(b => b.BONDERSLNO == loggedinUser.BONDERID), "BONDERSLNO", "BONDERNAME", loggedinUser.BONDERID);
            }
            else
            {
                ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME");
            }
            foreach (var item in backToBackLC.BACKTOBACKPRODUCTs)
            {
                item.BACKTOBACKLCID = backToBackLC.ID;
            }

            DateTime thisDay = DateTime.Now;


            System.Diagnostics.Debug.WriteLine("Time: " + thisDay + " ModelState.IsValid: " + ModelState.IsValid);

            var errors = ModelState.Values.SelectMany(v => v.Errors);

            System.Diagnostics.Debug.WriteLine("Time: " + thisDay + " errors: " + errors);
            //if (ModelState.IsValid)
            if (true)
            {
                try
                {
                    if (backToBackLC.BACKTOBACKPRODUCTs != null && backToBackLC.BACKTOBACKPRODUCTs.Count > 0)
                    {
                        if (backToBackLC.BONDERID != null)
                        {
                            USERPERMISSION userpermission = sessionAttributeRetreival.getStoredUserPermission();
                            int            bonderId       = backToBackLC.BONDERID;
                            if (userpermission != null)
                            {
                                List <INBONDRAWMATERIAL> inbondRawMaterials = db.INBONDRAWMATERIALs.Where(inb => inb.INBOND.BONDERID == bonderId).ToList();
                                if (inbondRawMaterials != null)
                                {
                                    decimal bonderUsedQuantity     = inbondRawMaterials.Sum(item => item.PRODUCTQUANTITY);
                                    decimal?bonderProvidedQuantity = backToBackLC.BACKTOBACKPRODUCTs.Sum(item => item.QUANTITY);
                                    if (bonderUsedQuantity < bonderProvidedQuantity)
                                    {
                                        ModelState.AddModelError("", "Your Remaining Inbond Raw Material Quantity " + bonderUsedQuantity);
                                        ViewBag.BUYERSBANKBRANCHID = new SelectList(db.BANKBRANCHes, "BBRANCHSLNO", "BRANCHNAME", backToBackLC.BUYERSBANKBRANCHID);
                                        ViewBag.BUYERSBANKID       = new SelectList(db.BANKs, "BANKSLNO", "BANKNAME", backToBackLC.BUYERSBANKID);

                                        if (userpermission != null && userpermission.BONDERID != null)
                                        {
                                            ViewBag.BONDERID = new SelectList(db.BONDERs.Where(b => b.BONDERSLNO == userpermission.BONDERID), "BONDERSLNO", "BONDERNAME", userpermission.BONDERID);
                                        }
                                        else
                                        {
                                            ViewBag.BONDERID = new SelectList(db.BONDERs, "BONDERSLNO", "BONDERNAME", backToBackLC.BONDERID);
                                        }
                                        ViewData["QUANTITYUNIT"] = new SelectList(model.QUANTITYUNITLIST, "Value", "Text", backToBackLC.QUANTITYUNIT);

                                        ViewData["PRICEUNIT"] = new SelectList(model.COSTUNITLIST, "Value", "Text", backToBackLC.PRICEUNIT);
                                        for (int i = 0; i < backToBackLC.BACKTOBACKPRODUCTs.Count(); i++)
                                        {
                                            ViewData["BACKTOBACKPRODUCTs[" + i + "].QUANTITYUNIT"] = new SelectList(model.QUANTITYUNITLIST, "Value", "Text", backToBackLC.BACKTOBACKPRODUCTs[i].QUANTITYUNIT);
                                        }
                                        return(View(backToBackLC));
                                    }
                                }
                            }
                        }
                        BACKTOBACKLC newBacktobacklc = new BACKTOBACKLC();
                        newBacktobacklc.BUYERSNAME             = backToBackLC.BUYERSNAME;
                        newBacktobacklc.BUYERSADDRESS          = backToBackLC.BUYERSADDRESS;
                        newBacktobacklc.LCNUMBER               = backToBackLC.LCNUMBER;
                        newBacktobacklc.LCDATE                 = backToBackLC.LCDATE;
                        newBacktobacklc.BUYERSBANKID           = backToBackLC.BUYERSBANKID;
                        newBacktobacklc.BUYERSBANKBRANCHID     = backToBackLC.BUYERSBANKBRANCHID;
                        newBacktobacklc.SHIPPINGDATE           = backToBackLC.SHIPPINGDATE;
                        newBacktobacklc.CORRECTIONDATE         = backToBackLC.CORRECTIONDATE;
                        newBacktobacklc.PRODUCTQUANTITY        = backToBackLC.PRODUCTQUANTITY;
                        newBacktobacklc.QUANTITYUNIT           = backToBackLC.QUANTITYUNIT;
                        newBacktobacklc.LCUSEDPRICE            = backToBackLC.LCUSEDPRICE;
                        newBacktobacklc.PRICEUNIT              = backToBackLC.PRICEUNIT;
                        newBacktobacklc.MASTERLCNUMBER         = backToBackLC.MASTERLCNUMBER;
                        newBacktobacklc.MASTERLCCORRECTIONDATE = backToBackLC.MASTERLCCORRECTIONDATE;
                        newBacktobacklc.UDNUMBER               = backToBackLC.UDNUMBER;
                        newBacktobacklc.UDDATE                 = backToBackLC.UDDATE;
                        newBacktobacklc.UDCORRECTIONDATE       = backToBackLC.UDCORRECTIONDATE;
                        newBacktobacklc.UDPRODUCTDETAIL        = backToBackLC.UDPRODUCTDETAIL;
                        newBacktobacklc.BONDERID               = backToBackLC.BONDERID;

                        if (loggedinUser != null)
                        {
                            newBacktobacklc.CREATEDBY = loggedinUser.APPUSER.USERNAME;
                        }
                        newBacktobacklc.CREATEDDATE = thisDay;

                        db.BACKTOBACKLCs.Add(newBacktobacklc);
                        db.SaveChanges();

                        short lastBackToBackId = db.BACKTOBACKLCs.Max(item => item.ID);

                        foreach (var product in backToBackLC.BACKTOBACKPRODUCTs)
                        {
                            using (var dbBackToBackProduct = new OracleEntitiesConnStr())
                            {
                                BACKTOBACKPRODUCT newProduct = new BACKTOBACKPRODUCT();
                                newProduct.NAME           = product.NAME;
                                newProduct.SIZEANDDETAIL  = product.SIZEANDDETAIL;
                                newProduct.QUANTITY       = product.QUANTITY;
                                newProduct.QUANTITYUNIT   = product.QUANTITYUNIT;
                                newProduct.BACKTOBACKLCID = lastBackToBackId;
                                newProduct.CREATEDBY      = backToBackLC.CREATEDBY;
                                newProduct.CREATEDDATE    = thisDay;

                                System.Diagnostics.Debug.WriteLine("Time: " + thisDay + " BACKTOBACKPRODUCTs " + backToBackLC.BACKTOBACKPRODUCTs.Count());

                                dbBackToBackProduct.BACKTOBACKPRODUCTs.Add(newProduct);
                                dbBackToBackProduct.SaveChanges();

                                short lastProductId = db.BACKTOBACKPRODUCTs.Max(itemBack2Back => itemBack2Back.ID);

                                //System.Diagnostics.Debug.WriteLine("Time: " + thisDay + " lastProductId =  " + lastProductId);

                                foreach (var rawMaterial in product.RAWMATERIALs)
                                {
                                    using (var dbRawMaterial = new OracleEntitiesConnStr())
                                    {
                                        RAWMATERIAL newRawMaterial = new RAWMATERIAL();
                                        newRawMaterial.RAWMATERIALCODE = rawMaterial.RAWMATERIALCODE;
                                        newRawMaterial.QUANTITY        = rawMaterial.QUANTITY;
                                        newRawMaterial.UNIT            = rawMaterial.UNIT;
                                        newRawMaterial.PERMITTEDWASTE  = rawMaterial.PERMITTEDWASTE;
                                        newRawMaterial.PRODUCTID       = lastProductId;
                                        newRawMaterial.CREATEDDATE     = thisDay;
                                        dbRawMaterial.RAWMATERIALs.Add(newRawMaterial);
                                        dbRawMaterial.SaveChanges();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        backToBackLC.CREATEDDATE = thisDay;

                        db.BACKTOBACKLCs.Add(backToBackLC);
                        db.SaveChanges();
                    }
                    return(RedirectToAction("Index"));
                }
                catch (DbEntityValidationException ex)
                {
                    foreach (DbEntityValidationResult item in ex.EntityValidationErrors)
                    {
                        // Get entry

                        DbEntityEntry entry          = item.Entry;
                        string        entityTypeName = entry.Entity.GetType().Name;

                        // Display or log error messages

                        foreach (DbValidationError subItem in item.ValidationErrors)
                        {
                            string message = string.Format("Error '{0}' occurred in {1} at {2}", subItem.ErrorMessage, entityTypeName, subItem.PropertyName);
                            System.Diagnostics.Debug.WriteLine("Create(BACKTOBACKPRODUCTs): Time-" + thisDay + " Exception = " + message);
                            ViewBag.error = message;
                        }
                    }
                }
                catch (Exception e)
                {
                    System.Diagnostics.Debug.WriteLine("Create(BACKTOBACKPRODUCTs): Time-" + thisDay + " Exception = " + e.StackTrace);
                }
            }

            ViewBag.BUYERSBANKBRANCHID = new SelectList(db.BANKBRANCHes, "BBRANCHSLNO", "BRANCHNAME", backToBackLC.BUYERSBANKBRANCHID);
            ViewBag.BUYERSBANKID       = new SelectList(db.BANKs, "BANKSLNO", "BANKNAME", backToBackLC.BUYERSBANKID);


            ViewData["QUANTITYUNIT"] = new SelectList(model.QUANTITYUNITLIST, "Value", "Text", backToBackLC.QUANTITYUNIT);

            ViewData["PRICEUNIT"] = new SelectList(model.COSTUNITLIST, "Value", "Text", backToBackLC.PRICEUNIT);
            for (int i = 0; i < backToBackLC.BACKTOBACKPRODUCTs.Count(); i++)
            {
                ViewData["BACKTOBACKPRODUCTs[" + i + "].QUANTITYUNIT"] = new SelectList(model.QUANTITYUNITLIST, "Value", "Text", backToBackLC.BACKTOBACKPRODUCTs[i].QUANTITYUNIT);
            }
            return(View(backToBackLC));
        }
Exemple #12
0
        public ActionResult CreateorEditExbond(IList <BACKTOBACKLC> backtobacklcs, short ID = 0)
        {
            USERPERMISSION       loggedinUser = sessionAttributeRetreival.getStoredUserPermission();
            IList <BACKTOBACKLC> b2bList      = new List <BACKTOBACKLC>();
            EXBOND exbond = new EXBOND();

            if (backtobacklcs == null)
            {
                return(RedirectToAction("Create", new { error = "Please select at least one back to back lc" }));
            }
            bool flag          = true;
            bool isanyselected = false;

            for (int i = 0; i < backtobacklcs.Count(); i++)
            {
                int id = backtobacklcs[i].ID;
                if (backtobacklcs[i].IsSelected)
                {
                    isanyselected = true;
                    BACKTOBACKLC back2backlc  = db.BACKTOBACKLCs.Find(id);
                    int          productCount = back2backlc.BACKTOBACKPRODUCTs.Count();
                    if (productCount < 1)
                    {
                        flag = false;
                    }
                    else
                    {
                        exbond.BONDERID = backtobacklcs[i].BONDER.BONDERSLNO;
                        b2bList.Add(back2backlc);
                    }
                }
            }
            if (!isanyselected && ID <= 0)
            {
                return(RedirectToAction("Create", new { error = "Please select at least one back to back lc" }));
            }
            if (!flag && ID <= 0)
            {
                return(RedirectToAction("Create", new { error = "Sorry! please check all selected LC has at least one product" }));
            }
            else
            {
                short lastInserted = 0;
                //if (ModelState.IsValid)
                //{
                if (ID <= 0)        //add new exbond
                {
                    if (loggedinUser != null)
                    {
                        exbond.CREATEDBY = loggedinUser.APPUSER.USERNAME;
                    }
                    //else
                    //{
                    //    exbond.CREATEDBY = "" + loggedinUser.USERID;
                    //}
                    exbond.CREATEDDATE = DateTime.Today;
                    db.EXBONDs.Add(exbond);
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e) {
                        Console.WriteLine(e.ToString());
                    }
                    lastInserted = db.EXBONDs.Max(item => item.ID);
                }
                else        //edit new exbond
                {
                    using (var db2 = new OracleEntitiesConnStr())
                    {
                        exbond = db.EXBONDs.Find(ID);
                        EXBOND newExbond = new EXBOND();
                        newExbond.ID          = ID;
                        newExbond.BONDERID    = exbond.BONDERID;
                        newExbond.DESCRIPTION = exbond.DESCRIPTION;
                        if (loggedinUser != null)
                        {
                            newExbond.MODIFIEDBY = loggedinUser.APPUSER.USERNAME;
                        }

                        newExbond.MODIFIEDDATE     = DateTime.Today;
                        newExbond.CREATEDDATE      = exbond.CREATEDDATE;
                        newExbond.CREATEDBY        = exbond.CREATEDBY;
                        db2.Entry(newExbond).State = EntityState.Modified;
                        db2.SaveChanges();
                    }
                    lastInserted = ID;
                }
                for (int x = 0; x < b2bList.Count(); x++)
                {
                    using (var db1 = new OracleEntitiesConnStr())
                    {
                        EXBONDBACKTOBACK exbondb2b = new EXBONDBACKTOBACK();
                        exbondb2b.BACKTOBACKID = b2bList[x].ID;
                        exbondb2b.EXBONDID     = lastInserted;
                        db1.EXBONDBACKTOBACKs.Add(exbondb2b);
                        db1.SaveChanges();
                    }
                }
                // }

                if (ID <= 0)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("Edit/" + ID));
                }
            }
        }