Exemple #1
0
        public static string GetOrganizationName()
        {
            PartyLibrary partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
            Party        orgParty = partyLib.GetByType("Organization").FirstOrDefault();

            return(orgParty.Party_Name);
        }
Exemple #2
0
        public static SelectList IndividualPartyList(object selectedItem)
        {
            ILibrary <Party>    lib    = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
            IEnumerable <Party> result = ((PartyLibrary)lib).GetByType("Individual");
            SelectList          sList  = new SelectList(result, "ID", "License_No", selectedItem);

            return(sList);
        }
Exemple #3
0
        public static SelectList PartyList(string PartyType, object selectedItem)
        {
            ILibrary <Party>    lib    = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
            IEnumerable <Party> result = ((PartyLibrary)lib).GetByType(PartyType);
            SelectList          sList  = new SelectList(result, "ID", "Party_Name", selectedItem);

            return(sList);
        }
Exemple #4
0
        public static Party GetPartyByID(string id)
        {
            int partyID = 0;

            int.TryParse(id, out partyID);

            ILibrary <Party> lib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());

            return(lib.GetByID(partyID.ToString()));
        }
Exemple #5
0
        public static SelectList IndividualReportPartyList(object selectedItem)
        {
            Party selectDropDown = new Party()
            {
                ID         = 0,
                Party_Name = " -- Select Value ---"
            };
            IEnumerable <Party> selectList = new Party[] { selectDropDown };

            ILibrary <Party>    lib    = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
            IEnumerable <Party> result = ((PartyLibrary)lib).GetByType("Individual");

            selectList = selectList.Concat <Party>(result);
            SelectList sList = new SelectList(selectList, "ID", "Party_Name", selectedItem);

            return(sList);
        }
        public ActionResult Validate(Scale data)
        {
            ModelState.Clear();

            data.Ticket_Type = ReceivingTicketType;
            data.QScale      = true;

            if (string.IsNullOrEmpty(data.Ticket_Status))
            {
                data.Ticket_Status = TicketStatus.Open.ToString();
            }

            if (data.Party_ID != null && data.Party_ID.ID == 0 && !string.IsNullOrEmpty(data.Party_ID.License_No))
            {
                PartyLibrary partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                Party        party    = partyLib.GetByLicenseNo(data.Party_ID.License_No);
                if (party != null)
                {
                    ModelState.AddModelError("Party", "Duplicate License#.");
                }
            }

            // Request Status is required.
            if (data.Ticket_Type != null && data.Ticket_Status.Contains("Select"))
            {
                ModelState.AddModelError("Ticket Status", "Request Status is a required field.");
            }

            // Ticket Type is required.
            if (data.Ticket_Type != null && data.Ticket_Type.Contains("Select"))
            {
                ModelState.AddModelError("Ticket Type", "Ticket type is a required field.");
            }

            //// Vehicle Plate is required.
            //if (string.IsNullOrEmpty(data.Vehicle_Plate_No))
            //  ModelState.AddModelError("Vehicle plate number ", "Vehicle plate number is a required field.");


            if (data.Ticket_Status != null && data.Ticket_Status.ToLower().Contains("close"))
            {
                // Party is required
                if (data.Party_ID.ID == 0 && string.IsNullOrEmpty(data.Party_ID.License_No))
                {
                    ModelState.AddModelError("Party", "Driving licence number is a required field.");
                }

                // Item is reuired.
                if (!IsLineItemExits(data.ID))
                {
                    ModelState.AddModelError("ScaleDetails", "There is at least one line item is required in the item details.");
                }

                // Gross Weight is required.
                if (data.Net_Weight <= 0)
                {
                    ModelState.AddModelError("Net_Weight ", "Net weight is a required field.");
                }

                // Amount is required
                if (data.Item_Amount <= 0)
                {
                    ModelState.AddModelError("Amount", "Amount is a required field.");
                }

                // State is rquire
                if (string.IsNullOrEmpty(data.State.Trim()))
                {
                    ModelState.AddModelError("State", "State is a required field.");
                }


                // Zip Code is rquire
                if (data.PrimaryAddress != null && string.IsNullOrEmpty(data.PrimaryAddress.Zip_Code))
                {
                    ModelState.AddModelError("Zip_Code", "Zip code is a required field.");
                }

                // DOB is required
                if (data.Party_ID != null && string.IsNullOrEmpty(data.Party_ID.Party_DOB))
                {
                    ModelState.AddModelError("Party_DOB", "Party DOB is a required field.");
                }

                // Vehicle Year is required
                if (string.IsNullOrEmpty(data.Vehicle_Year.Trim()))
                {
                    ModelState.AddModelError("Vehicle_Year", "Vehicle Year is a required field.");
                }

                // Vehicle Sate is required
                if (string.IsNullOrEmpty(data.Plate_State.Trim()))
                {
                    ModelState.AddModelError("Plate_State", "Plate State is a required field.");
                }

                //// Amount is required
                //if (data.Ticket_Settled)
                //    ModelState.AddModelError("Settled", "Ticket already paid.");
            }

            ValidQScaleItems(data);


            if (!ModelState.IsValid)
            {
                return(Json(new {
                    success = false,
                    errors = ModelState.Errors()
                }));
            }
            return(Json(new {
                success = true,
                errors = ""
            }));
        }
        private void SaveThumbScannerAttachment(int Id, byte[] data, string fileName, EnumAttachmentRefType refType, FileFormat fileFormat, bool updateParty = true)
        {
            Guid guid = SaveFile(data, string.Format("{0}.{1}", fileName, fileFormat.ToString()));

            ScaleAttachments attachments = new ScaleAttachments();

            attachments.Document_Name  = string.Format("{0}.{1}", fileName, fileFormat.ToString());// "Thumb-Image.jpeg";
            attachments.Document_RefId = guid;
            attachments.Document_Size  = data.LongLength;
            attachments.Document_Title = "Thumb-Image";
            attachments.Document_Type  = "jpeg";
            attachments.Ref_Type       = (int)refType;

            attachments.Updated_By        = User.Identity.Name;
            attachments.Created_By        = User.Identity.Name;
            attachments.Created_Date      = DateTime.Now;
            attachments.Last_Updated_Date = DateTime.Now;
            attachments.Parent            = new Scale {
                ID = Id
            };

            string destinationPath;
            string sourcePath;

            FilelHelper fileHelper = new FilelHelper();

            destinationPath = fileHelper.GetSourceDirByFileRefId(attachments.Document_RefId.ToString());     // Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString());
            sourcePath      = fileHelper.GetTempSourceDirByFileRefId(attachments.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString());

            attachments.Document_Path = fileHelper.GetFilePath(sourcePath);

            if (Id > 0)
            {
                fileHelper.MoveFile(attachments.Document_Name, sourcePath, destinationPath);
                ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                attachments.Document_Name = string.Format("{0}.{1}", fileName, "jpg");
                ScaleAttachments scaleAttachment = ScaleLibrary.Add(attachments);

                if (updateParty)
                {
                    Scale        scale    = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(Id.ToString(), new string[] { "Party_ID" });
                    PartyLibrary partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                    Party        party    = partyLib.GetByID(scale.Party_ID.ID.ToString());
                    if (party != null)
                    {
                        party.PhotoRefId = scaleAttachment.Document_RefId.ToString();
                        partyLib.Modify(party);
                    }
                }
            }
            else
            {
                if (Session["ScaleAttachments"] == null)
                {
                    Session["ScaleAttachments"] = new List <ScaleAttachments>();
                }

                IList <ScaleAttachments> iList = (IList <ScaleAttachments>)Session["ScaleAttachments"];
                iList.Add(attachments);
            }
        }
Exemple #8
0
        public JsonResult _SaveCustomerImages(string scaleId, string partyId)
        {
            try
            {
                if (!string.IsNullOrEmpty(partyId))
                {
                    // Get party
                    PartyLibrary          partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                    smART.ViewModel.Party party    = partyLib.GetByID(partyId);
                    if (party != null)
                    {
                        FilelHelper fileHelper = new FilelHelper();
                        string      filePath;
                        // Save Customer Image
                        if (!string.IsNullOrEmpty(party.PhotoRefId))
                        {
                            filePath = fileHelper.GetFilePathByFileRefId(party.PhotoRefId);
                            if (System.IO.File.Exists(filePath))
                            {
                                Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                                SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.Customer), EnumAttachmentRefType.Customer, FileFormat.jpeg);
                            }
                        }
                        // Signature Image
                        if (!string.IsNullOrEmpty(party.SignatureImageRefId))
                        {
                            filePath = fileHelper.GetFilePathByFileRefId(party.SignatureImageRefId);
                            if (System.IO.File.Exists(filePath))
                            {
                                Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                                SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.Signature), EnumAttachmentRefType.Signature, FileFormat.bmp);
                            }
                        }
                        // Thumb Image
                        if (!string.IsNullOrEmpty(party.ThumbImage1RefId))
                        {
                            filePath = fileHelper.GetFilePathByFileRefId(party.ThumbImage1RefId);
                            if (System.IO.File.Exists(filePath))
                            {
                                Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                                SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.Thumbprint1), EnumAttachmentRefType.Thumbprint1, FileFormat.jpg);
                            }
                        }
                        // License Image
                        if (!string.IsNullOrEmpty(party.LicenseImageRefId))
                        {
                            filePath = fileHelper.GetFilePathByFileRefId(party.LicenseImageRefId);
                            if (System.IO.File.Exists(filePath))
                            {
                                Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                                SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.DriverLicense), EnumAttachmentRefType.DriverLicense, FileFormat.jpg);
                            }
                        }

                        // Vehicle Image
                        if (!string.IsNullOrEmpty(party.VehicleImageRegId))
                        {
                            filePath = fileHelper.GetFilePathByFileRefId(party.VehicleImageRegId);
                            if (System.IO.File.Exists(filePath))
                            {
                                Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                                SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.Vehicle), EnumAttachmentRefType.Vehicle, FileFormat.jpg);
                            }
                        }

                        // Cash Card Image
                        if (!string.IsNullOrEmpty(party.CashCardImageRefId))
                        {
                            filePath = fileHelper.GetFilePathByFileRefId(party.CashCardImageRefId);
                            if (System.IO.File.Exists(filePath))
                            {
                                Byte[] photoBytes = fileHelper.GetBytesFromFile(filePath);
                                SaveAttachment(Convert.ToInt32(scaleId), photoBytes, CommonHelper.GetFileNameByDocType((int)EnumAttachmentRefType.CashCard), EnumAttachmentRefType.CashCard, FileFormat.jpg);
                            }
                        }
                    }
                }
                return(Json(new { Sucess = "True" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Sucess = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public HttpResponseMessage SaveTicket([FromBody] Ticket value)
        {
            try {
                if (value.Scale == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.BadRequest));
                }

                // Start transaction.
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {
                    IsolationLevel = IsolationLevel.ReadCommitted
                })) {
                    smART.ViewModel.Scale newScale = new Scale();

                    // Add new party if already exists
                    if (!string.IsNullOrEmpty(value.Scale.License_No))
                    {
                        PartyLibrary partyLib = new PartyLibrary(ConString);
                        Party        party    = partyLib.GetByLicenseNo(value.Scale.License_No);
                        if (party != null)
                        {
                            newScale.Party_ID = party;
                        }
                        else
                        {
                            // Add new party
                            party                   = new Party();
                            party.Party_Name        = value.Scale.Customer_Name;
                            party.Party_Short_Name  = value.Scale.Customer_Name;
                            party.License_No        = value.Scale.License_No;
                            party.Party_Type        = "Individual";
                            party.Created_By        = value.Scale.Created_By;
                            party.Updated_By        = value.Scale.Created_By;
                            party.Created_Date      = value.Scale.Created_Date;
                            party.Last_Updated_Date = value.Scale.Created_Date;
                            party.Active_Ind        = true;
                            party.IsActive          = true;
                            party.State             = !string.IsNullOrEmpty(value.Scale.Customer_State) ? value.Scale.Customer_State.ToString().Trim() : "";
                            party.ACLicense_ID      = value.Scale.Customer_ACLicense_ID;
                            party.Party_DOB         = value.Scale.Customer_DOB;
                            //string dobString = value.Scale.Customer_DOB;
                            //DateTime dobDt;
                            //if (smART.Common.DateTimeHelper.IsValidDate(dobString, out dobDt))
                            //    party.Party_DOB = dobDt;

                            party             = partyLib.Add(party);
                            newScale.Party_ID = party;

                            // Add new Address
                            AddressBook address = new AddressBook();
                            address.Address1          = value.Scale.Customer_Address;
                            address.City              = value.Scale.Customer_City;
                            address.State             = value.Scale.Customer_State;
                            address.Country           = value.Scale.Customer_Country;
                            address.Party             = party;
                            address.Created_By        = value.Scale.Created_By;
                            address.Updated_By        = value.Scale.Created_By;
                            address.Created_Date      = value.Scale.Created_Date;
                            address.Last_Updated_Date = value.Scale.Created_Date;
                            address.Primary_Flag      = true;
                            address.Active_Ind        = true;
                            address.Zip_Code          = value.Scale.Customer_Zip;
                            AddressBookLibrary addressLib = new AddressBookLibrary(ConString);
                            addressLib.Add(address);
                        }
                    }

                    // Save Scale
                    ScaleLibrary lib = new ScaleLibrary(ConString);
                    newScale.Ticket_Status = "Open";
                    newScale.QScale        = true;
                    newScale.Gross_Weight  = value.ScaleDetails.Sum(s => s.GrossWeight);
                    newScale.Tare_Weight   = value.ScaleDetails.Sum(s => s.TareWeight);;
                    newScale.Net_Weight    = value.ScaleDetails.Sum(s => s.NetWeight);
                    value.Scale.MapServiceEntityToServerEntity(newScale);
                    smART.ViewModel.Scale scale = lib.Add(newScale);

                    // Save scale detail
                    if (value.ScaleDetails != null)
                    {
                        ScaleDetailsLibrary libScaleDetail = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        ItemLibrary         libItem        = new ItemLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        foreach (var item in value.ScaleDetails)
                        {
                            smART.ViewModel.ScaleDetails newScaleDetails = new smART.ViewModel.ScaleDetails();
                            newScaleDetails.Apply_To_Item = libItem.GetByID(item.Item_ID.ToString());
                            newScaleDetails.Item_Received = libItem.GetByID(item.Item_ID.ToString());
                            newScaleDetails.Scale         = scale;
                            item.MapServiceEntityToServerEntity(newScaleDetails);
                            ScaleDetails scaleDetails = libScaleDetail.Add(newScaleDetails);

                            // Set docuent related id if document is related to item
                            if (value.ScaleAttachments != null && value.ScaleAttachments.Count > 0)
                            {
                                Model.ScaleAttachments modelAttach = value.ScaleAttachments.Where(w => w.Document_RelatedID == item.ID).FirstOrDefault();
                                if (modelAttach != null && modelAttach.Document_RelatedTo == 1)
                                {
                                    modelAttach.Document_RelatedID = scaleDetails.ID;
                                }
                            }
                        }
                    }

                    // Save Max Ticket ID in Device Settings
                    DeviceSettingLibrary deviceLib      = new DeviceSettingLibrary(ConString);
                    DeviceSettings       deviceSettings = deviceLib.GetByUniueID(scale.Unique_ID.Value);
                    deviceSettings.MaxTicket_ID = value.Scale.ID;
                    deviceLib.Modify(deviceSettings);


                    // Save Attachments
                    if (value.ScaleAttachments != null)
                    {
                        ScaleAttachmentsLibrary libAttach  = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        FilelHelper             fileHelper = new FilelHelper();

                        foreach (var item in value.ScaleAttachments)
                        {
                            smART.ViewModel.ScaleAttachments newScaleAttachment = new smART.ViewModel.ScaleAttachments();

                            // Save file
                            Guid   docRefId        = Guid.NewGuid();
                            string destinationPath = fileHelper.GetSourceDirByFileRefId(docRefId.ToString());
                            fileHelper.MoveFile(item.Document_Title, fileHelper.GetTempSourceDirByFileRefId(item.Document_Path), destinationPath);

                            // Save attachment
                            newScaleAttachment.Parent         = scale;
                            newScaleAttachment.Document_RefId = docRefId;
                            newScaleAttachment.Document_Path  = Path.Combine(destinationPath, item.Document_Title);
                            item.MapServiceEntityToServerEntity(newScaleAttachment);
                            libAttach.Add(newScaleAttachment);
                        }
                    }

                    // Complete transaction.
                    scope.Complete();
                }
                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception ex) {
                ExceptionHandler.HandleException(ex, "An error occured in SaveTicket.");
                //string details = string.Format("Method: {1} {0} Message: {2} {0} Stack Trace: {3}", System.Environment.NewLine, "SaveTicket", ex.Message, ex.StackTrace.ToString());
                //smART.Common.MessageLogger.Instance.LogMessage(ex, details, Common.Priority.High, 0, System.Diagnostics.TraceEventType.Error, "Service Error", "Service");
                return(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }
        }
        public string SaveTicketImage(String scaleId, string documentType)
        {
            var docfiles = new List <string>();

            try {
                int intScaleId = Convert.ToInt32(scaleId);
                if (intScaleId <= 0)
                {
                    throw new Exception("Invalid ticket id.");
                }

                int    intDocType = Convert.ToInt32(documentType);
                string fileName   = CommonHelper.GetFileNameByDocType(intDocType);
                if (string.IsNullOrEmpty(fileName))
                {
                    throw new Exception("Invalid document type.");
                }


                var httpRequest = HttpContext.Current.Request;
                if (httpRequest.Files.Count > 0)
                {
                    // Get scale
                    Scale scale = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(scaleId, new string[] { "Party_ID" });
                    if (scale == null)
                    {
                        throw new Exception("Given scale id not found in database.");
                    }

                    FilelHelper fileHelper = new FilelHelper();
                    foreach (string file in httpRequest.Files)
                    {
                        // Save file
                        string docRefID        = Guid.NewGuid().ToString();
                        var    destinationPath = fileHelper.GetSourceDirByFileRefId(docRefID); // Path.Combine(Configuration.GetsmARTTempDocPath(), docRefID);
                        fileHelper.CreateDirectory(destinationPath);
                        var postedFile = httpRequest.Files[file];
                        postedFile.SaveAs(Path.Combine(destinationPath, fileName));
                        docfiles.Add(docRefID);

                        // Add attachment
                        ScaleAttachments attachments = new ScaleAttachments();
                        attachments.Document_Name  = fileName;
                        attachments.Document_RefId = new Guid(docRefID);
                        attachments.Document_Size  = 0;
                        attachments.Document_Title = fileName;
                        attachments.Document_Type  = "jpeg";
                        attachments.Ref_Type       = intDocType;

                        attachments.Updated_By        = User.Identity.Name;
                        attachments.Created_By        = User.Identity.Name;
                        attachments.Created_Date      = DateTime.Now;
                        attachments.Last_Updated_Date = DateTime.Now;
                        attachments.Parent            = new Scale {
                            ID = intScaleId
                        };
                        attachments.Document_Path = destinationPath;

                        ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                        attachments.Document_Name = fileName;
                        ScaleAttachments scaleAttachment = ScaleLibrary.Add(attachments);

                        // Update file ref in party master
                        if (scale.Party_ID != null && scale.Party_ID.ID > 0)
                        {
                            PartyLibrary partyLib = new PartyLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString());
                            Party        party    = partyLib.GetByID(scale.Party_ID.ID.ToString());
                            if (party != null)
                            {
                                SetPartyImageRefByDocType(intDocType, scaleAttachment.Document_RefId.ToString(), party);
                                partyLib.Modify(party);
                            }
                        }
                    }
                }
            }
            catch (Exception ex) {
                //string details = string.Format("Method: {1} {0} Message: {2} {0} Stack Trace: {3}", System.Environment.NewLine, "SaveTicketImage", ex.Message, ex.StackTrace.ToString());
                ExceptionHandler.HandleException(ex, "An error occured in SaveTicketImage utils.");
                //smART.Common.MessageLogger.Instance.LogMessage(ex, details, Common.Priority.High, 0, System.Diagnostics.TraceEventType.Error, "Service Error", "Service");
            }
            return(docfiles.FirstOrDefault());
        }