Exemplo n.º 1
0
        /// <summary>
        /// Get Truck Doc Details By TruckDocId
        /// </summary>
        /// <param name="truckDocId">Int32:TruckDocId</param>
        /// <returns></returns>
        public TruckDocumentsDTO GetTruckDocDetailsByTruckDocId(int truckDocId)
        {
            TruckDocumentsDTO truckDocument = new TruckDocumentsDTO();
            AutoMapper.Mapper.Map(ESalesUnityContainer.Container.Resolve<IGenericRepository<truckdocument>>()
            .GetSingle(item => item.TruckDoc_Doc_Id == truckDocId && item.TruckDoc_IsDeleted == false), truckDocument);

            return truckDocument;
        }
    private void SaveDocumentListForTruck(string truckNo)
    {
        TruckVerificationDTO truckDetails = new TruckVerificationDTO();
        truckDetails = ESalesUnityContainer.Container.Resolve<ITruckService>().GetAllTruckDetails(truckNo);

        IList<TruckDocDetailsDTO> listTruckDocDetail = new List<TruckDocDetailsDTO>();
        IList<TruckDocumentsDTO> listTruckDocument = new List<TruckDocumentsDTO>();
        IList<StandaloneTruckDocDetails> listStandaloneTruckDocDetail = new List<StandaloneTruckDocDetails>();

        foreach (GridViewRow row in grdDocument.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                if (((TextBox)(row.Cells[2].Controls[1])).Text != string.Empty)
                {
                    if (truckDetails.type == 1)
                    {
                        TruckDocDetailsDTO truckDocDetails = new TruckDocDetailsDTO();
                        truckDocDetails.Truck_Doc_TruckId = Convert.ToInt32(ViewState[Globals.StateMgmtVariables.TRUCKID]);
                        truckDocDetails.Truck_Doc_DocId = Convert.ToInt32(grdDocument.DataKeys[row.RowIndex].Value);
                        truckDocDetails.Truck_Doc_DocNo = ((TextBox)(row.Cells[2].Controls[1])).Text;

                        DateTimeFormatInfo dateTimeFormatterProvider = DateTimeFormatInfo.CurrentInfo.Clone() as DateTimeFormatInfo;
                        dateTimeFormatterProvider.ShortDatePattern = "dd/MM/yyyy";
                        if (((TextBox)(row.Cells[3].Controls[1])).Text != string.Empty)
                        {
                            truckDocDetails.Truck_Doc_ExDate = DateTime.Parse(((TextBox)(row.Cells[3].Controls[1])).Text, dateTimeFormatterProvider);
                        }

                        TruckDocumentsDTO truckDocument = new TruckDocumentsDTO();
                        truckDocument.TruckDoc_CreatedBy = base.GetCurrentUserId();
                        truckDocument.TruckDoc_CreatedDate = DateTime.Now;
                        truckDocument.TruckDoc_LastUpdatedDate = DateTime.Now;

                        //If fileupload control has file
                        if (filAuthDoc.HasFile)
                        {
                            string uploadFilePath = Path.Combine(Server.MapPath("../CustomerAuthImages"), filAuthDoc.FileName);
                            filAuthDoc.SaveAs(uploadFilePath);

                            truckDocument.TruckDoc_File = ImageToBlob.ConvertImageToByteArray(uploadFilePath);
                            truckDocDetails.Truck_Doc_FileName = filAuthDoc.FileName;
                            //Delete the file from application folder after converting into byte array
                            File.Delete(uploadFilePath);
                        }
                        else
                        {
                            truckDocument.TruckDoc_File = null;
                        }

                        listTruckDocument.Add(truckDocument);

                        truckDocDetails.Truck_Doc_CreatedBy = GetCurrentUserId();
                        truckDocDetails.Truck_Doc_CreatedDate = DateTime.Now;
                        truckDocDetails.Truck_Doc_LastUpdatedDate = DateTime.Now;

                        listTruckDocDetail.Add(truckDocDetails);

                        ESalesUnityContainer.Container.Resolve<ITruckService>().SaveAndUpdateTruckDocumentDetails(listTruckDocDetail, listTruckDocument);
                    }
                    else if (truckDetails.type == 2)
                    {
                        StandaloneTruckDocDetails standaloneTruckDocDetails = new StandaloneTruckDocDetails();
                        standaloneTruckDocDetails.StandaloneTruck_Doc_TruckId = Convert.ToInt32(ViewState[Globals.StateMgmtVariables.TRUCKID]);
                        standaloneTruckDocDetails.StandaloneTruck_Doc_DocId = Convert.ToInt32(grdDocument.DataKeys[row.RowIndex].Value);
                        standaloneTruckDocDetails.StandaloneTruck_Doc_DocNo = ((TextBox)(row.Cells[2].Controls[1])).Text;

                        if (((TextBox)(row.Cells[3].Controls[1])).Text != string.Empty)
                        {
                            standaloneTruckDocDetails.StandaloneTruck_Doc_ExDate = DateTime.Parse(((TextBox)(row.Cells[3].Controls[1])).Text.ToString());
                        }

                        if (filAuthDoc.HasFile)
                        {
                            string uploadFilePath = Path.Combine(Server.MapPath("../CustomerAuthImages"), filAuthDoc.FileName);
                            filAuthDoc.SaveAs(uploadFilePath);

                            standaloneTruckDocDetails.StandaloneTruck_Doc_File = ImageToBlob.ConvertImageToByteArray(uploadFilePath);
                            standaloneTruckDocDetails.StandaloneTruck_Doc_FileName = filAuthDoc.FileName;
                            File.Delete(uploadFilePath);
                        }
                        else
                        {
                            standaloneTruckDocDetails.StandaloneTruck_Doc_File = null;
                        }
                        standaloneTruckDocDetails.StandaloneTruck_Doc_CreatedBy = GetCurrentUserId();
                        standaloneTruckDocDetails.StandaloneTruck_Doc_CreatedDate = DateTime.Now;
                        standaloneTruckDocDetails.StandaloneTruck_Doc_LastUpdatedDate = DateTime.Now;

                        listStandaloneTruckDocDetail.Add(standaloneTruckDocDetails);

                        ESalesUnityContainer.Container.Resolve<IStandaloneTruckService>().SaveAndUpdateStandaloneTruckDocumentDetails(listStandaloneTruckDocDetail);
                    }
                }
            }
        }
    }
	private void SaveDocumentListForTrucks(int truckId)
	{
		IList<TruckDocDetailsDTO> listTruckDetail = new List<TruckDocDetailsDTO>();
		IList<TruckDocumentsDTO> listTruckDocument = new List<TruckDocumentsDTO>();

		foreach (GridViewRow row in grdDocument.Rows)
		{
			if (row.RowType == DataControlRowType.DataRow)
			{
				if (((TextBox)(row.Cells[3].Controls[1])).Text != string.Empty)
				{
					TruckDocDetailsDTO truckDocDetail = new TruckDocDetailsDTO();
					truckDocDetail.Truck_Doc_TruckId = truckId;
					truckDocDetail.Truck_Doc_DocId = Convert.ToInt32(grdDocument.DataKeys[row.RowIndex].Value);
					truckDocDetail.Truck_Doc_DocNo = ((TextBox)(row.Cells[3].Controls[1])).Text;

					DateTimeFormatInfo dateTimeFormatterProvider = DateTimeFormatInfo.CurrentInfo.Clone() as DateTimeFormatInfo;
					dateTimeFormatterProvider.ShortDatePattern = "dd/MM/yyyy";
					truckDocDetail.Truck_Doc_ExDate = DateTime.Parse(((TextBox)(row.Cells[4].Controls[1])).Text, dateTimeFormatterProvider);

					TruckDocumentsDTO truckDocument = new TruckDocumentsDTO();
					truckDocument.TruckDoc_CreatedBy = base.GetCurrentUserId();
					truckDocument.TruckDoc_CreatedDate = DateTime.Now;

					if (((Label)(row.Cells[6].Controls[1])).Text.Trim() != string.Empty)
					{
						string filePath = Path.Combine(Convert.ToString(ViewState[Globals.StateMgmtVariables.FILEPATH]), ((Label)(row.Cells[6].Controls[1])).Text);
						truckDocument.TruckDoc_File = ImageToBlob.ConvertImageToByteArray(filePath);
					}
					else
					{
						truckDocument.TruckDoc_File = null;
					}

					listTruckDocument.Add(truckDocument);

					truckDocDetail.Truck_Doc_FileName = ((Label)(row.Cells[6].Controls[1])).Text;
					truckDocDetail.Truck_Doc_CreatedBy = GetCurrentUserId();
					truckDocDetail.Truck_Doc_CreatedDate = DateTime.Now;
					truckDocDetail.Truck_Doc_LastUpdatedDate = DateTime.Now;

					listTruckDetail.Add(truckDocDetail);
				}
			}
		}
		//Save Truck Document Details
		ESalesUnityContainer.Container.Resolve<ITruckService>().SaveAndUpdateTruckDocumentDetails(listTruckDetail, listTruckDocument);
	}