protected void btn_Upload_Click(object sender, EventArgs e)
 {
     if (Page.IsValid && File1.HasFile)
     {
         string fileName = "images/" + File1.FileName;
         string filePath = MapPath(fileName);
         File1.SaveAs(filePath);
         Image1.ImageUrl = fileName;
     }
 }
Ejemplo n.º 2
0
 public static bool operator ==(File File1, File File2)
 {
     if (ReferenceEquals(File1, File2))
     {
         return(true);
     }
     if ((object)File1 == null || (object)File2 == null)
     {
         return(false);
     }
     return(File1.Equals(File2));
 }
Ejemplo n.º 3
0
        private void watchFile_Click(object sender, EventArgs e)
        {
            File1 f = new File1();

            fs.rootDirectory   = f.OpenFile();
            this.openfile.Text = fs.rootDirectory;
            this.listBox.Items.Clear();
            //DirectoryInfo directoryInfo = new DirectoryInfo(fs.rootDirectory);
            File1 getFiles = new File1();
            //getFiles.searchFilesFolder(fs.rootDirectory);
            Thread thSearchFile = new Thread(new ParameterizedThreadStart(getFiles.searchFilesFolder));

            thSearchFile.Start(this);
        }
Ejemplo n.º 4
0
    //--------------------------------------------------------------------
    // Build the Insert command String(file)
    //--------------------------------------------------------------------
    private String BuildInsertCommand(File1 file)
    {
        String command;

        StringBuilder sb = new StringBuilder();

        // use a string builder to create the dynamic string
        sb.AppendFormat("Values({0}, '{1}' ,'{2}')", file.ProblemID.ToString(), file.Description, file.Filepath);
        String prefix = "INSERT INTO Files " + "(probID, Description1, filepath)";

        command = prefix + sb.ToString();

        return(command);
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Splits and creates a new PDF document
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSplit_Click(object sender, EventArgs e)
        {
            string dataPath1 = File1.ResolveClientUrl(File1.Value);

            if (System.IO.Path.GetExtension(dataPath1).Equals(".pdf"))
            {
                Stream stream1 = File1.PostedFile.InputStream;

                //Load a PDF document
                PdfLoadedDocument ldoc = new PdfLoadedDocument(stream1);

                //Get first page from document
                PdfLoadedPage lpage = ldoc.Pages[0] as PdfLoadedPage;

                if (x.Text != "" && y.Text != "" && width.Text != "" && height.Text != "")
                {
                    float x1      = float.Parse(x.Text);
                    float y1      = float.Parse(y.Text);
                    float width1  = float.Parse(width.Text);
                    float height1 = float.Parse(height.Text);

                    //Create PDF redaction for the page
                    PdfRedaction redaction = new PdfRedaction(new RectangleF(x1, y1, width1, height1), Color.Black);

                    //Adds the redaction to loaded page
                    lpage.Redactions.Add(redaction);

                    //Save to disk
                    if (this.CheckBox1.Checked)
                    {
                        ldoc.Save("Document1.pdf", Response, HttpReadType.Open);
                    }
                    else
                    {
                        ldoc.Save("Document1.pdf", Response, HttpReadType.Save);
                    }
                }
                else
                {
                    lb_error.Visible = true;
                    lb_error.Text    = "Note: Fill all the fields then redact";
                }
            }
            else
            {
                lb_error.Visible = true;
                lb_error.Text    = "Invalid file type. Please select a PDF file";
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Alert1 alert1 = new Alert1();
            File1 file1 = new File1();
            String1 string1 = new String1();

            Console.WriteLine("Enter path to file:");

            string line1 = file1.ToLine(Console.ReadLine());

            if (string1.IsPalindrome(line1)) { alert1.Throw("Your string is Palindrom"); }
            else { alert1.Throw("Your string is NOT Palindrom"); }

            Console.ReadKey();
        }
Ejemplo n.º 7
0
        private void watchFile_Click(object sender, EventArgs e)
        {
            File1 f = new File1();

            fs.rootDirectory   = f.OpenFile();
            this.openfile.Text = fs.rootDirectory;
            this.listBox.Items.Clear();
            File1 getFiles = new File1();

            getFiles.searchFilesFolder(fs.rootDirectory);
            foreach (string file in fs.fileName)
            {
                this.listBox.Items.Add(file);
            }
            bindText();
        }
Ejemplo n.º 8
0
    //---------------------------------------------------------------------------------
    // Read files list
    //---------------------------------------------------------------------------------
    public List <File1> getFilesList()
    {
        List <File1>  filesList = new List <File1>();
        SqlConnection con       = null;

        // classEX enter your code here

        try
        {
            con = connect("DBConnectionString"); // create a connection to the database using the connection String defined in the web config file

            String     selectSTR = "SELECT * FROM Files";
            SqlCommand cmd       = new SqlCommand(selectSTR, con);

            // get a reader
            SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); // CommandBehavior.CloseConnection: the connection will be closed after reading has reached the end

            while (dr.Read())
            {   // Read till the end of the data into a row
                File1 f = new File1();

                f.FileID      = Convert.ToInt32(dr["fileID"]);
                f.ProblemID   = Convert.ToInt32(dr["probID"]);
                f.Description = (string)dr["Description1"];
                f.Filepath    = (string)dr["filepath"];
                filesList.Add(f);
            }

            return(filesList);
        }
        catch (Exception ex)
        {
            // write to log
            throw (ex);
        }
        finally
        {
            if (con != null)
            {
                con.Close();
            }
        }
    }
Ejemplo n.º 9
0
        protected void btnupload_Click(object sender, EventArgs e)
        {
            if
            (File1.HasFile)
            {
                try
                {
                    if
                    (File1.PostedFile.ContentType ==
                     "image/jpeg")
                    {
                        if
                        (File1.PostedFile.ContentLength < 8512000)
                        {
                            string
                                filename = System.IO.Path.GetFileName(File1.FileName);
                            File1.SaveAs(Server.MapPath("~/FileUploads/" + filename));
                            Label1.Text =
                                "File uploaded successfully!";
                        }
                        else
                        {
                            Label1.Text =
                                "File maximum size is 500 Kb";
                        }
                    }
                    else
                    {
                        Label1.Text =
                            "Only JPEG files are accepted!";
                    }
                }
                catch
                (Exception
                 exc)
                {
                    Label1.Text =
                        "The file could not be uploaded. The following error occured: "

                        + exc.Message;
                }
            }
        }
Ejemplo n.º 10
0
    //--------------------------------------------------------------------------------------------------
    // This method inserts a file to the files table
    //--------------------------------------------------------------------------------------------------
    public int insert(File1 file)
    {
        SqlConnection con;
        SqlCommand    cmd;

        try
        {
            con = connect("DBConnectionString"); // create the connection
        }
        catch (Exception ex)
        {
            // write to log
            throw (ex);
        }

        String cStr = BuildInsertCommand(file);     // helper method to build the insert string

        cmd = CreateCommand(cStr, con);             // create the command

        try
        {
            int numEffected = cmd.ExecuteNonQuery(); // execute the command
            return(numEffected);
        }
        catch (Exception ex)
        {
            return(0);

            // write to log
            throw (ex);
        }

        finally
        {
            if (con != null)
            {
                // close the db connection
                con.Close();
            }
        }
    }
Ejemplo n.º 11
0
        private void SyncTLs(TLType translationType, bool ForceOverwrite = false)
        {
            string PersonalityNumber = Personality.Value.Replace("c", "");
            string FolderPath        = Paths.PluginPath;

            switch (translationType)
            {
            case TLType.Scenario:
                Logger.Log(LogLevel.Info, $"Syncing Scenario translations for personality {Personality.Value}...");
                FolderPath = Path.Combine(FolderPath, @"translation\adv\scenario");
                FolderPath = Path.Combine(FolderPath, Personality.Value);
                break;

            case TLType.Communication:
                Logger.Log(LogLevel.Info, $"Syncing Communication translations for personality {Personality.Value}...");
                if (Personality.Value.Contains("-"))
                {
                    Logger.Log(LogLevel.Info, $"Scenario characters have no Communication files, skipping.");
                    return;
                }
                FolderPath = Path.Combine(FolderPath, @"translation\communication");
                break;

            case TLType.H:
                Logger.Log(LogLevel.Info, $"Syncing H translations for personality {Personality.Value}...");
                FolderPath = Path.Combine(FolderPath, @"translation\h\list");
                break;

            default:
                return;
            }

            if (!Directory.Exists(FolderPath))
            {
                return;
            }

            var FilePaths = Directory.GetFiles(FolderPath, "*.txt", SearchOption.AllDirectories).Reverse();

            if (FilePaths.Count() == 0)
            {
                return;
            }

            foreach (string File1 in FilePaths)
            {
                string Ending   = File1.Replace(FolderPath, "").Remove(0, 1);
                bool   DidEdit1 = false;

                switch (translationType)
                {
                case TLType.Scenario:
                    if (Ending.Contains("penetration"))
                    {
                        continue;
                    }
                    Ending = Ending.Remove(0, 2);
                    break;

                case TLType.Communication:
                    if (Ending.Contains($"communication_{PersonalityNumber}"))
                    {
                        Ending = Ending.Remove(0, Ending.IndexOf("communication_"));
                    }
                    else if (Ending.Contains($"communication_off_{PersonalityNumber}"))
                    {
                        Ending = Ending.Remove(0, Ending.IndexOf("communication_off_"));
                    }
                    else if (Ending.Contains($"optiondisplayitems_{PersonalityNumber}"))
                    {
                        Ending = Ending.Remove(0, Ending.IndexOf("optiondisplayitems_"));
                    }
                    else
                    {
                        continue;
                    }
                    break;

                case TLType.H:
                    if (Ending.Contains($"personality_voice_{Personality.Value}"))
                    {
                        Ending = $"personality_voice_{Personality.Value}";
                    }
                    else
                    {
                        continue;
                    }
                    break;
                }
                //Logger.Log(LogLevel.Info, $"+{Ending}");

                string[] Lines1 = File.ReadAllLines(File1);
                Dictionary <string, string> TLLines = new Dictionary <string, string>();

                for (int i = 0; i < Lines1.Count(); i++)
                {
                    string Line1 = Lines1[i];
                    if (Line1.IsNullOrEmpty())
                    {
                        continue;
                    }

                    var Line1Split = Line1.Split('=');

                    if (CheckLineForErrors(Line1, File1, i + 1))
                    {
                        continue;
                    }

                    if (Line1.StartsWith(@"//") || Line1.EndsWith("="))
                    {
                        continue;
                    }

                    if (FormatTLText(ref Line1Split[1]))
                    {
                        DidEdit1 = true;
                    }

                    if (FormatUnTLText(ref Line1Split[0]))
                    {
                        DidEdit1 = true;
                    }

                    Lines1[i] = $"{Line1Split[0]}={Line1Split[1]}";
                    try
                    {
                        TLLines.Add(Line1Split[0], Line1Split[1]);
                    }
                    catch (ArgumentException)
                    {
                        Logger.Log(LogLevel.Warning, $"Duplicate translation line detected, only the first will be used: {Line1Split[0]}");
                    }
                }
                //foreach (var x in TLLines)
                //    Logger.Log(LogLevel.Info, x);

                if (DidEdit1)
                {
                    SaveFile(File1, Lines1);
                }

                foreach (string File2 in FilePaths.Where(x => x != File1))
                {
                    switch (translationType)
                    {
                    case TLType.Scenario:
                        if (!File2.Replace(FolderPath, "").EndsWith(Ending))
                        {
                            continue;
                        }
                        break;

                    case TLType.Communication:
                        if ((File2.Contains($"communication_{PersonalityNumber}") || File2.Contains($"communication_off_{PersonalityNumber}")) &&
                            (Ending.Contains($"communication_{PersonalityNumber}") || Ending.Contains($"communication_off_{PersonalityNumber}")))
                        {
                        }
                        else if (File2.Contains($"optiondisplayitems_{PersonalityNumber}") && Ending.Contains($"optiondisplayitems_{PersonalityNumber}"))
                        {
                        }
                        else
                        {
                            continue;
                        }
                        break;

                    case TLType.H:
                        if (!File2.Contains(Ending))
                        {
                            continue;
                        }
                        break;
                    }

                    bool     DidEdit2 = false;
                    string[] Lines2   = File.ReadAllLines(File2);

                    //Logger.Log(LogLevel.Info, $"-{File2}");

                    for (int i = 0; i < Lines2.Count(); i++)
                    {
                        string Line2 = Lines2[i];
                        if (Line2.IsNullOrEmpty())
                        {
                            continue;
                        }
                        string[] Line2Split = Line2.Split('=');

                        if (CheckLineForErrors(Line2, File2, i + 1))
                        {
                            continue;
                        }

                        if (FormatUnTLText(ref Line2Split[0]))
                        {
                            DidEdit2 = true;
                        }

                        if (FormatTLText(ref Line2Split[1]))
                        {
                            DidEdit2 = true;
                        }

                        Lines2[i] = $"{Line2Split[0]}={Line2Split[1]}";

                        string JPText = Line2Split[0];
                        if (JPText.StartsWith(@"//"))
                        {
                            JPText = JPText.Substring(2, Line2Split[0].Length - 2);
                        }
                        JPText = JPText.Trim();

                        string TLText = Line2Split[1];

                        if (TLLines.TryGetValue(JPText, out string NewTLText))
                        {
                            if (TLText.IsNullOrEmpty())
                            {
                                Lines2[i] = $"{JPText}={NewTLText}";
                                DidEdit2  = true;
                                //Logger.Log(LogLevel.Info, $"Setting:{JPText}={NewTLText}");
                            }
                            else
                            {
                                if (TLText != NewTLText)
                                {
                                    StringBuilder sb = new StringBuilder("Translations do not match!").Append(Environment.NewLine);
                                    sb.Append(File1).Append(Environment.NewLine);
                                    sb.Append($"{JPText}={NewTLText}").Append(Environment.NewLine);
                                    sb.Append($"Line:{i + 1} {File2}").Append(Environment.NewLine);
                                    sb.Append($"{JPText}={TLText}");
                                    if (ForceOverwrite)
                                    {
                                        sb.Append(Environment.NewLine).Append("Overwriting...");
                                        Lines2[i] = $"{JPText}={NewTLText}";
                                        DidEdit2  = true;
                                    }
                                    Logger.Log(LogLevel.Warning, sb.ToString());
                                    continue;
                                }
                            }
                        }
                    }
                    if (DidEdit2)
                    {
                        SaveFile(File2, Lines2);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates PDF
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            string dataPath1 = File1.ResolveClientUrl(File1.Value);

            if (System.IO.Path.GetExtension(dataPath1).Equals(".pdf"))
            {
                Stream stream1 = File1.PostedFile.InputStream;

                //Load a existing PDF document
                PdfLoadedDocument ldoc = new PdfLoadedDocument(stream1);

                //Create a new PDF compression options
                PdfCompressionOptions options = new PdfCompressionOptions();

                if (this.compressImage.Checked)
                {
                    //Compress image.
                    options.CompressImages = true;
                    options.ImageQuality   = int.Parse(this.imageQuality.SelectedValue);
                }
                else
                {
                    options.CompressImages = false;
                }
                //Compress the font data
                if (this.optFont.Checked)
                {
                    options.OptimizeFont = true;
                }
                else
                {
                    options.OptimizeFont = false;
                }
                //Compress the page contents
                if (this.optPageContents.Checked)
                {
                    options.OptimizePageContents = true;
                }
                else
                {
                    options.OptimizePageContents = false;
                }
                //Remove the metadata information.
                if (this.removeMetadata.Checked)
                {
                    options.RemoveMetadata = true;
                }
                else
                {
                    options.RemoveMetadata = false;
                }

                //Set the options to loaded PDF document
                ldoc.CompressionOptions = options;

                //Save to disk
                if (this.CheckBox1.Checked)
                {
                    ldoc.Save("Document1.pdf", Response, HttpReadType.Open);
                }
                else
                {
                    ldoc.Save("Document1.pdf", Response, HttpReadType.Save);
                }
            }
        }
Ejemplo n.º 13
0
        protected void SaveButton_Click(object sender, EventArgs e)
        {
            string strFullName = string.Empty;            //, strUrl, strContentType, strSize

            CoursewareBLL coursewareBLL = new CoursewareBLL();


            if (ViewState["AddFlag"].ToString() == "1")      //新增
            {
                strFullName = File1.FileName;                //直接取得文件名



                if (!string.IsNullOrEmpty(strFullName))
                {
                    FileInfo fi = new FileInfo(File1.FileName);

                    //判断只能上传.flv与.swf格式

                    //if (fi.Extension.ToLower() != ".flv" && fi.Extension.ToLower() != ".swf")
                    //{
                    //    SessionSet.PageMessage = "文件格式应为FLV或SWF视频! 现在格式为:" + fi.Extension.ToLower();
                    //    return;
                    //}

                    if (fi.Name.Replace(fi.Extension, "") != txtCoursewareName.Text)
                    {
                        SessionSet.PageMessage = "上传文件名与课件名不一致,请确认上传文件名!";
                        return;
                    }
                }
                RailExam.Model.Courseware courseware = new RailExam.Model.Courseware();

                courseware.CoursewareName   = txtCoursewareName.Text;
                courseware.CoursewareTypeID = int.Parse(hfCoursewareTypeID.Value);
                courseware.ProvideOrg       = SessionSet.OrganizationID;
                courseware.PublishDate      = DateTime.Parse(datePublishDate.DateValue.ToString());
                courseware.Authors          = txtAuthors.Text;
                courseware.Revisers         = txtRevisers.Text;
                courseware.KeyWord          = txtKeyWord.Text;
                courseware.Description      = txtDescription.Text;
                courseware.Memo             = txtMemo.Text;
                courseware.IsGroupLearder   = Convert.ToInt32(ddlIsGroup.SelectedValue);
                courseware.TechnicianTypeID = Convert.ToInt32(ddlTech.SelectedValue);

                ArrayList al = new ArrayList();
                courseware.OrgIDAL = GetOrg(tvOrg.Nodes, al);

                ArrayList al1 = new ArrayList();

                foreach (TreeViewNode tn in tvPost.Nodes)
                {
                    if (tn.Checked)
                    {
                        al1.Add(tn.ID);
                    }

                    if (tn.Nodes.Count > 0)
                    {
                        foreach (TreeViewNode tns in tn.Nodes)
                        {
                            if (tns.Checked)
                            {
                                al1.Add(tns.ID);
                            }

                            if (tns.Nodes.Count > 0)
                            {
                                foreach (TreeViewNode tnss in tns.Nodes)
                                {
                                    if (tnss.Checked)
                                    {
                                        al1.Add(tnss.ID);
                                    }
                                }
                            }
                        }
                    }
                }
                courseware.PostIDAL = al1;

                ArrayList trainTypeIDList = new ArrayList();
                string[]  strType         = hfTrainTypeID.Value.Split(',');
                for (int i = 0; i < strType.Length; i++)
                {
                    if (!string.IsNullOrEmpty(strType[i]))
                    {
                        trainTypeIDList.Add(strType[i]);
                    }
                }
                courseware.TrainTypeIDAL = trainTypeIDList;

                int nCoursewareID = coursewareBLL.AddCourseware(courseware);

                if (!string.IsNullOrEmpty(strFullName))
                {
                    //strUrl = File1.PostedFile.FileName;//先取得全部的上传文件路径个名字,然后再利用SubString方法来得到用户名,现在看来是没有必要了


                    //strContentType = File1.PostedFile.ContentType;//获取文件MIME内容类型
                    //strFileType = strFullName.Substring(strFullName.LastIndexOf(".") + 1);//获取文件名字 . 后面的字符作为文件类型


                    //strSize = File1.PostedFile.ContentLength.ToString();


                    Directory.CreateDirectory(Server.MapPath("../Online/Courseware/" + nCoursewareID));
                    File1.SaveAs(Server.MapPath("../Online/Courseware/" + nCoursewareID + "/") + strFullName);                    //将文件保存在跟目录的UP文件夹下

                    courseware.CoursewareID = nCoursewareID;
                    courseware.Url          = "/RailExamBao/Online/Courseware/" + nCoursewareID + "/" + strFullName;

                    coursewareBLL.UpdateCourseware(courseware);
                }
                Response.Write("<script>window.opener.form1.Refresh.value='true';window.opener.form1.submit();window.close();</script>");
            }
            else                //修改
            {
                string strCoursewareID = Request.QueryString.Get("id");

                RailExam.Model.Courseware courseware = coursewareBLL.GetCourseware(Convert.ToInt32(strCoursewareID));
                courseware.CoursewareID     = int.Parse(strCoursewareID);
                courseware.CoursewareName   = txtCoursewareName.Text;
                courseware.CoursewareTypeID = int.Parse(hfCoursewareTypeID.Value);
                courseware.ProvideOrg       = int.Parse(hfProvideOrgID.Value);
                courseware.PublishDate      = DateTime.Parse(datePublishDate.DateValue.ToString());
                courseware.Authors          = txtAuthors.Text;
                courseware.Revisers         = txtRevisers.Text;
                courseware.KeyWord          = txtKeyWord.Text;
                courseware.Description      = txtDescription.Text;
                courseware.IsGroupLearder   = Convert.ToInt32(ddlIsGroup.SelectedValue);
                courseware.TechnicianTypeID = Convert.ToInt32(ddlTech.SelectedValue);
                courseware.OrderIndex       = Convert.ToInt32(hfOrderIndex.Value);

                strFullName = File1.FileName;                //直接取得文件名



                //strUrl = File1.PostedFile.FileName;//先取得全部的上传文件路径个名字,然后再利用SubString方法来得到用户名,现在看来是没有必要了


                //strContentType = File1.PostedFile.ContentType;//获取文件MIME内容类型
                //strFileType = strFullName.Substring(strFullName.LastIndexOf(".") + 1);//获取文件名字 . 后面的字符作为文件类型


                //strSize = File1.PostedFile.ContentLength.ToString();

                if (!string.IsNullOrEmpty(strFullName))
                {
                    FileInfo fi = new FileInfo(File1.FileName);

                    //如果是武汉,就判断只能上传.flv与.swf格式

                    //if (fi.Extension.ToLower() != ".flv" && fi.Extension.ToLower() != ".swf")
                    //{
                    //    SessionSet.PageMessage = "文件格式应为FLV或SWF视频! 现在格式为:" + fi.Extension.ToLower();
                    //    return;
                    //}

                    if (fi.Name.Replace(fi.Extension, "") != txtCoursewareName.Text)
                    {
                        SessionSet.PageMessage = "上传文件名与课件名不一致,请确认上传文件名!";
                        return;
                    }

                    if (File.Exists(Server.MapPath(courseware.Url)))
                    {
                        //string[] filelist = Directory.GetFileSystemEntries(Server.MapPath("../Online/Courseware/" + courseware.CoursewareID + "/"));
                        //foreach (string file in filelist)
                        //{
                        //    if(!Directory.Exists(file))
                        //    {
                        //        File.Delete(file);
                        //    }
                        //}
                        File.Delete(Server.MapPath(courseware.Url));
                    }

                    if (!Directory.Exists(Server.MapPath("../Online/Courseware/" + strCoursewareID)))
                    {
                        Directory.CreateDirectory(Server.MapPath("../Online/Courseware/" + strCoursewareID));
                    }

                    File1.SaveAs(Server.MapPath("../Online/Courseware/" + strCoursewareID + "/") + strFullName);                    //将文件保存在跟目录的UP文件夹下

                    courseware.Url = "/RailExamBao/Online/Courseware/" + strCoursewareID + "/" + strFullName;
                }
                courseware.Memo = txtMemo.Text;

                ArrayList al = new ArrayList();
                courseware.OrgIDAL = GetOrg(tvOrg.Nodes, al);

                ArrayList al1 = new ArrayList();

                foreach (TreeViewNode tn in tvPost.Nodes)
                {
                    if (tn.Checked)
                    {
                        al1.Add(tn.ID);
                    }

                    if (tn.Nodes.Count > 0)
                    {
                        foreach (TreeViewNode tns in tn.Nodes)
                        {
                            if (tns.Checked)
                            {
                                al1.Add(tns.ID);
                            }

                            if (tns.Nodes.Count > 0)
                            {
                                foreach (TreeViewNode tnss in tns.Nodes)
                                {
                                    if (tnss.Checked)
                                    {
                                        al1.Add(tnss.ID);
                                    }
                                }
                            }
                        }
                    }
                }
                courseware.PostIDAL = al1;

                ArrayList trainTypeIDList = new ArrayList();
                string[]  strType         = hfTrainTypeID.Value.Split(',');
                for (int i = 0; i < strType.Length; i++)
                {
                    if (!string.IsNullOrEmpty(strType[i]))
                    {
                        trainTypeIDList.Add(strType[i]);
                    }
                }
                courseware.TrainTypeIDAL = trainTypeIDList;

                coursewareBLL.UpdateCourseware(courseware);

                Response.Write("<script>window.opener.form1.Refresh.value='true';window.opener.form1.submit();window.close();</script>");
            }
        }
Ejemplo n.º 14
0
    static void Main()
    {
        File1 myFile = new File1();

        File1.x = 7; //this will throw an error since the variable x is internal in File1.cs
    }
Ejemplo n.º 15
0
        /// <summary>
        /// Writes lines to the log file.
        /// </summary>
        /// <returns>The task.</returns>
        private static async Task WriteLogFileAsync()
        {
            // get the Logs folder
            Folder = ApplicationData.Current.LocalFolder;
            Folder = await Folder.CreateFolderAsync(FOLDER_NAME, CreationCollisionOption.OpenIfExists);

            // get the two log files
            File2 = await Folder.CreateFileAsync("2.log", CreationCollisionOption.OpenIfExists);

            File1 = await Folder.CreateFileAsync("1.log", CreationCollisionOption.OpenIfExists);

            // get the current log file
            BasicProperties prop1 = await File1.GetBasicPropertiesAsync();

            BasicProperties prop2 = await File2.GetBasicPropertiesAsync();

            CurrentFile = (prop1.DateModified >= prop2.DateModified) ? File1 : File2;
            var stream = await CurrentFile.OpenStreamForWriteAsync();

            stream.Seek(0, SeekOrigin.End);

            // process log file events
            List <string> myMessages = new List <string>();

            while (true)
            {
                // wait for an event
                signal.WaitOne();

                // clear the log files
                if (clear)
                {
                    CurrentFile = File1 = await Folder.CreateFileAsync("1.log", CreationCollisionOption.ReplaceExisting);

                    File2 = await Folder.CreateFileAsync("2.log", CreationCollisionOption.ReplaceExisting);

                    clear = false;
                    Cleared.Invoke(null, EventArgs.Empty);
                }

                // get the messages to be written
                lock (messages)
                {
                    myMessages.AddRange(messages);
                    messages.Clear();
                }

                // write the messages to the current log file
                foreach (string message in myMessages)
                {
                    Debug.WriteLine(message);
                    try
                    {
                        byte[] bytes = Encoding.UTF8.GetBytes(message);
                        await stream.WriteAsync(bytes);

                        stream.WriteByte(13);
                        await stream.FlushAsync();
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine("AppendTextAsync EXCEPTION: " + ex.Message);
                    }
                }
                myMessages.Clear();

                // switch log files if necessary
                BasicProperties prop = await CurrentFile.GetBasicPropertiesAsync();

                if (prop.Size >= maxFileSize)
                {
                    if (CurrentFile == File1)
                    {
                        CurrentFile = File2 = await Folder.CreateFileAsync("2.log", CreationCollisionOption.ReplaceExisting);
                    }
                    else
                    {
                        CurrentFile = File1 = await Folder.CreateFileAsync("1.log", CreationCollisionOption.ReplaceExisting);
                    }
                    stream = await CurrentFile.OpenStreamForWriteAsync();

                    stream.Seek(0, SeekOrigin.End);
                }
            }
        }
Ejemplo n.º 16
0
        // POST api/<controller>
        public void Post([FromBody] File1[] arr)
        {
            File1 f = new File1();

            f.insert(arr);
        }
Ejemplo n.º 17
0
 protected void UpdateFinally_Click(object sender, EventArgs e)
 {
     if (UpdateFinally.Text == "UPDATE COOK")
     {
         Button insert = (Button)sender;
         if (insert != null)
         {
             KuvariPozicijaUpdate updateKuvari = new KuvariPozicijaUpdate {
                 kuvarPozicija = new KuvariPozicijaItem {
                     IdKuvar = Convert.ToInt32(HiddenField1.Value), Ime = TextBox1.Text, idPozicije = Convert.ToInt32(DropDownListPozicije.SelectedValue), Slika = ""
                 }
             };
             if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0))
             {
                 Random rnd              = new Random();
                 string uid              = rnd.Next(10000000).ToString();
                 string fn               = System.IO.Path.GetFileName(File1.PostedFile.FileName);
                 string SaveLocation     = Server.MapPath("~/images/") + "" + uid + fn;
                 string SaveLocationMala = Server.MapPath("~/images/") + "" + uid + fn + "Mala";
                 updateKuvari.kuvarPozicija.Slika = "~/images/" + uid + fn;
                 string fileExtention = File1.PostedFile.ContentType;
                 int    fileLenght    = File1.PostedFile.ContentLength;
                 if (fileExtention == "image/png" || fileExtention == "image/jpeg" || fileExtention == "image/x-png")
                 {
                     File1.SaveAs(SaveLocation);
                     System.Drawing.Bitmap bmpPostedImage = new System.Drawing.Bitmap(File1.PostedFile.InputStream);
                     System.Drawing.Image  objImage       = ScaleImage(bmpPostedImage, 81);
                     // Saving image in jpeg format
                     objImage.Save(SaveLocationMala);
                     updateKuvari.kuvarPozicija.SlikaMala = "~/images/" + uid + fn + "Mala";
                 }
             }
             OperationResult result = this.menager.execute(updateKuvari);
             LabelResult.Visible = true;
             if (result.Success)
             {
                 LabelResult.Text   = "Successfully updated";
                 UpdateFinally.Text = "INSERT COOK";
                 TextBox1.Text      = "";
                 fillKuvari();
                 return;
             }
             else
             {
                 LabelResult.Text      = "Update failed";
                 LabelResult.ForeColor = System.Drawing.ColorTranslator.FromHtml("#d9534f");
                 return;
             }
         }
     }
     if (UpdateFinally.Text == "INSERT COOK")
     {
         KuvariPozicijaInsert insertKuvari = new KuvariPozicijaInsert {
             kuvarPozicija = new KuvariPozicijaItem {
                 Ime = TextBox1.Text, idPozicije = Convert.ToInt32(DropDownListPozicije.SelectedValue), Slika = ""
             }
         };
         if ((File1.PostedFile != null) && (File1.PostedFile.ContentLength > 0))
         {
             Random rnd              = new Random();
             string uid              = rnd.Next(10000000).ToString();
             string fn               = System.IO.Path.GetFileName(File1.PostedFile.FileName);
             string SaveLocation     = Server.MapPath("~/images/") + "" + uid + fn;
             string SaveLocationMala = Server.MapPath("~/images/") + "" + uid + fn + "Mala";
             insertKuvari.kuvarPozicija.Slika = "~/images/" + uid + fn;
             string fileExtention = File1.PostedFile.ContentType;
             int    fileLenght    = File1.PostedFile.ContentLength;
             if (fileExtention == "image/png" || fileExtention == "image/jpeg" || fileExtention == "image/x-png")
             {
                 File1.SaveAs(SaveLocation);
                 System.Drawing.Bitmap bmpPostedImage = new System.Drawing.Bitmap(File1.PostedFile.InputStream);
                 System.Drawing.Image  objImage       = ScaleImage(bmpPostedImage, 81);
                 objImage.Save(SaveLocationMala);
                 insertKuvari.kuvarPozicija.SlikaMala = "~/images/" + uid + fn + "Mala";
             }
         }
         OperationResult resultInsert = this.menager.execute(insertKuvari);
         if (resultInsert.Success)
         {
             LabelResult.Visible = true;
             LabelResult.Text    = "Successfully inserted";
             TextBox1.Text       = "";
             fillKuvari();
         }
     }
 }