Ejemplo n.º 1
0
        protected void FileDPRUpload_Click(object sender, EventArgs e)
        {
            FileLabel.Text = string.Empty;
            prodMonth      = string.Empty;

            //check month selected or not
            if (!string.IsNullOrWhiteSpace(hdnProdMonth.Value))
            {
                prodMonth = hdnProdMonth.Value;
            }
            else
            {
                //TODO if Production Month Empty!!
                fileName       = string.Empty;
                filePath       = string.Empty;
                FileLabel.Text = "Please select Production Month.";
                return;
            }

            if (!string.IsNullOrWhiteSpace(filePath) && !string.IsNullOrWhiteSpace(fileName))
            {
                try
                {
                    var user   = HttpContext.Current.Session["user"] as User;
                    int userId = 0;
                    if (user != null)
                    {
                        userId = user.Id;
                    }
                    //uploadingfile
                    var upload = DPRUploader.UploadFile(prodMonth, fileName, filePath, userId);

                    fileName = string.Empty;
                    filePath = string.Empty;

                    if (upload)
                    {
                        FileLabel.Text = "File Uploaded Successfully";
                    }
                    else
                    {
                        FileLabel.Text = "Error processing uploaded file. Please check your file format.";
                    }
                }
                catch (Exception ex)
                {
                    FileLabel.Text = "Error upload file : " + ex.Message;
                }
            }
            else
            {
                FileLabel.Text = "File Cannot be upload, check your file format.";
                return;
            }
        }
Ejemplo n.º 2
0
        protected void popupDocUpload_WindowCallback(object source, PopupWindowCallbackArgs e)
        {
            if (e.Parameter == "upload")
            {
                string filePath = Session["pl_uploaded_file"] as string;
                string fileName = Path.GetFileName(filePath);
                //int userId = 0;

                var user   = HttpContext.Current.Session["user"] as User;
                int userId = 0;
                if (user != null)
                {
                    userId = user.Id;
                }

                DPRUploader uploader = new DPRUploader();

                //set username for column createdby and modifiedby
                uploader.Username = PermissionHelper.GetAuthenticatedUserName();

                //parameter
                DateTime value           = (DateTime)dtPM.Value;
                int      productionMonth = value.ToString("yyyyMM", System.Globalization.CultureInfo.InvariantCulture).ToInt32(0);

                //parse the file
                string message  = "";
                int    rowCount = 0; // uploader.Parse(filePath, productionMonth);

                //UploadeingFile
                var upload = DPRUploader.UploadFile(productionMonth.ToString(), fileName, filePath, userId);

                // if (rowCount > 0)
                if (upload)
                {
                    lblSuccess.Text = "Successfully upload and process data " + Path.GetFileName(filePath) + ", " + message;
                    this.masterGrid.DataBindSafe();

                    //e.CallbackData = lblSuccess.Text;
                    //e.IsValid = true;
                    //e.ErrorText = "";
                }
                else
                {
                    if (uploader.ErrorMessage.Length > 0)
                    {
                        lblSuccess.Text = uploader.ErrorMessage;
                    }
                    else
                    {
                        lblSuccess.Text = "Upload file " + Path.GetFileName(filePath) + " failed!";
                    }

                    //delete the file
                    File.Delete(filePath);

                    //e.CallbackData = lblSuccess.Text;
                    //e.IsValid = false;
                    //e.ErrorText = lblSuccess.Text;
                }
            }

            //try
            //{
            //    string[] parameters = e.Parameter.Split(';');
            //    Session["Id"] = parameters[0];
            //    CheckListInstanceStep oStep =
            //        CheckListInstanceRepository.RetrieveCurrentInstanceStep(Convert.ToInt32(parameters[0]));
            //    DotWeb.Models.CheckListInstanceInfo oInfo =
            //        CheckListInstanceRepository.RetrieveCurrentInstanceInfoById(
            //            oStep.CheckListInstanceInfoId.GetValueOrDefault());
            //    int ass = Convert.ToInt32(Session["assemblyType"]);
            //    int modelId = ModelRepository.RetrieveModelIdByName(oInfo.Model);
            //    int vpm = Convert.ToInt32(oInfo.PackingMonth);
            //    int variantId = ModelRepository.RetrieveVariantIdByModelIdAndVariantName(modelId, oInfo.Variant);
            //    if (oStep != null)
            //    {
            //        string fileTypeName = FileTypeRepository.RetrieveFileTypeNameById(
            //                                                          oStep.FileTypeId);
            //        popupDocUpload.JSProperties["cpHeaderText"] = "File Upload - " + fileTypeName;

            //        UploaderBase uploader = UploaderHelper.GetUploader(oStep.FileTypeId, ass);
            //        if (uploader.HasExistingData(vpm, modelId, variantId) != 0)
            //        {
            //            lblexist.Text = "File Already exist";
            //            lblFile.Text = uploader.FileName;
            //        }

            //        Session["FileTypeName"] = fileTypeName;
            //        Session["FileTypeId"] = oStep.FileTypeId;
            //        Session["ModelName"] = oInfo.Model;
            //        Session["VariantName"] = oInfo.Variant;
            //        Session["PackingMonth"] = oInfo.PackingMonth;
            //    }
            //}
            //catch (Exception ex)
            //{
            //    LoggerHelper.LogError(ex);
            //}
        }