private void opnFileDlgGrBtn_Click(object sender, System.EventArgs e)
        {
            /*string openFileDialogFilter = "Bitmap Files|*.bmp" +
             *  "|Enhanced Windows MetaFile|*.emf" +
             *  "|Exchangeable Image File|*.exif" +
             *  "|Gif Files|*.gif|Icons|*.ico|JPEG Files|*.jpg" +
             *  "|PNG Files|*.png|TIFF Files|*.tif|Windows MetaFile|*.wmf";
             */
            string openFileDialogFilter =
                "Image files (*.png;*.jpeg;*.jpg;*.gif;*.bmp)|*.png;*.jpeg;*.jpg;*.gif;*.bmp";

            do
            {
                using (DialogInvoker dialogInvoker = new DialogInvoker(openFileDialogFilter))
                {
                    if (dialogInvoker.Invoke() == DialogResult.OK)
                    {
                        FileInfo fileInfo = new FileInfo(dialogInvoker.InvokeDialog.FileName);
                        long     fileSize = fileInfo.Length;

                        if (fileSize < 1024000)
                        {
                            //System folder path of selected item (full source file name)
                            SourceFullFileName            = dialogInvoker.InvokeDialog.FileName;
                            this.groupImgPathTextBox.Text =
                                SourceFullFileName.Substring(SourceFullFileName.LastIndexOf("\\") + 1);
                            break;
                        }
                        else
                        {
                            MessageBox.Show("Размер изображения больше 1 мб. Выберите другой файл или измените " +
                                            "текущий файл, чтобы он соответствовал требованиям", "Внимание",
                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }while (true);
        }
Example #2
0
        private void opnFileDlgChildBtn_Click(object sender, EventArgs e)
        {
            string openFileDialogFilter =
                "Image files (*.png;*.jpeg;*.jpg;*.gif;*.bmp)|*.png;*.jpeg;*.jpg;*.gif;*.bmp";

            do
            {
                using (DialogInvoker dialogInvoker = new DialogInvoker(openFileDialogFilter))
                {
                    if (dialogInvoker.Invoke() == DialogResult.OK)
                    {
                        FileInfo fileInfo = new FileInfo(dialogInvoker.InvokeDialog.FileName);
                        long     fileSize = fileInfo.Length;

                        if (fileSize < 1024000)
                        {
                            //System folder path of selected item (full source file name)
                            SourceFullFileName            = dialogInvoker.InvokeDialog.FileName;
                            this.childImgPathTextBox.Text =
                                SourceFullFileName.Substring(SourceFullFileName.LastIndexOf("\\") + 1);
                            break;
                        }
                        else
                        {
                            MessageBox.Show("Размер изображения больше 1 мб. Выберите другой файл или измените " +
                                            "текущий файл, чтобы он соответствовал требованиям", "Внимание",
                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }while (true);
        }
Example #3
0
        private void CreateAndEditChildSaveBtn_Click(object sender, EventArgs e)
        {
            bool isValidChildCode       = ValidateChildCode();
            bool isValidChildName       = ValidateChildName();
            bool isValidChildSimpleName = ValidateChildSimpleName();
            bool isValidChildImgPath    = ValidateChildImgPath();

            bool isImgNeeded = true;

            if (isValidChildCode && isValidChildName && isValidChildSimpleName && !isValidChildImgPath)
            {
                DialogResult dialogResult = MessageBox.Show("Вы уверены, что хотите сохранить позицию без картинки?",
                                                            "Внимание", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (dialogResult == DialogResult.No || dialogResult == DialogResult.None)
                {
                    return;
                }
                else
                {
                    isImgNeeded = false;
                }
            }
            else if (!isValidChildCode || !isValidChildName || !isValidChildSimpleName || !isValidChildImgPath)
            {
                return;
            }

            //< getting values from textboxes
            ChildToEditOrCreate.Code       = Int32.Parse(this.childCodeTextBox.Text);
            ChildToEditOrCreate.Name       = this.childNameTextBox.Text;
            ChildToEditOrCreate.SimpleName = this.childSimpleNameTextBox.Text;
            ChildToEditOrCreate.GroupCode  = Int32.Parse(this.childGroupCodeTextBox.Text);
            ChildToEditOrCreate.ImgName    = this.childImgPathTextBox.Text;
            //>

            if (WorkMode.WorkType.Equals(WorkModeType.Create))
            {
                if (this.Owner != null)
                {
                    if (this.addToTheEndRadioBtn.Checked)
                    {
                        ((Form1)this.Owner).AddNewChild(ChildToEditOrCreate);
                    }
                    else
                    {
                        ((Form1)this.Owner).AddNewChild(ChildToEditOrCreate, false);
                    }
                }
            }
            else if (WorkMode.WorkType.Equals(WorkModeType.Edit))
            {
                if (this.Owner != null)
                {
                    ((Form1)this.Owner).UpdateChild(ChildToEditOrCreate);
                }
            }

            if (!isImgNeeded)
            {
                this.Close();
                return;
            }

            //Get image extension
            string imgExtension = SourceFullFileName.Substring(SourceFullFileName.LastIndexOf('.'));

            // File name for saving in .xml file
            string fileName;

            fileName = this.childCodeTextBox.Text + imgExtension;

            if (!imgExtension.Equals(".png"))
            {
                fileName = this.childCodeTextBox.Text + ".png";
            }

            // Full destination path for file(full destination file name)
            string destFolderName;

            if (((Form1)this.Owner).AppWorkMode.WorkType == WorkModeType.LoadFromFinalXml)
            {
                destFolderName = PredeterminedDestImgFolderPath +
                                 "\\" + fileName;

                string oldFileName =
                    InitImgPath.Substring(InitImgPath.LastIndexOf("\\") + 1);

                if (!SourceFullFileName.Equals(destFolderName))
                {
                    if (!imgExtension.Equals(".png"))
                    {
                        Image img;
                        using (Stream fs = new FileStream(SourceFullFileName, FileMode.Open, FileAccess.ReadWrite))
                        {
                            img = Image.FromStream(fs);

                            try
                            {
                                img.Save(destFolderName, ImageFormat.Png);
                            }
                            catch (Exception excep)
                            {
                                Logger.Error("Не удалось сохранить картинку в .png формате!", excep);
                                MessageBox.Show("Не удалось сохранить картинку в .png формате!", "Ошибка",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    else
                    {
                        File.Copy(SourceFullFileName, destFolderName);
                    }

                    if (WorkMode.WorkType.Equals(WorkModeType.Edit))
                    {
                        if (!SourceFullFileName.Contains(PredeterminedDestImgFolderPath) &&
                            !oldFileName.Equals(fileName))
                        {
                            File.Delete(InitImgPath);
                        }
                    }
                }
            }
            else //oldMode
            {
                destFolderName = Path.Combine(Path.GetDirectoryName(
                                                  Assembly.GetExecutingAssembly().Location), @"Images\") +
                                 this.childCodeTextBox.Text +
                                 imgExtension;
                File.Copy(SourceFullFileName, destFolderName, true);
            }

            //remaking final xml file
            //((Form1)this.Owner).CreateFinalXmlFile();

            this.Close();
        }
        private void CreateAndEditGrSaveBtn_Click(object sender, EventArgs e)
        {
            bool isValidGroupId      = ValidateGroupId();
            bool isValidGroupName    = ValidateGroupName();
            bool isValidGroupImgPath = ValidateGroupImgPath();

            bool isImgNeeded = true;

            if (isValidGroupId && isValidGroupName && !isValidGroupImgPath)
            {
                DialogResult dialogResult = MessageBox.Show("Вы уверены, что хотите сохранить группу без картинки?",
                                                            "Внимание", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (dialogResult == DialogResult.No || dialogResult == DialogResult.None)
                {
                    return;
                }
                else
                {
                    isImgNeeded = false;
                }
            }
            else if (!isValidGroupId || !isValidGroupName || !isValidGroupImgPath)
            {
                return;
            }

            //< getting values from textboxes
            GroupToEditOrCreate.Id      = Int32.Parse(this.groupIdTextBox.Text);
            GroupToEditOrCreate.Name    = this.groupNameTextBox.Text;
            GroupToEditOrCreate.ImgName = this.groupImgPathTextBox.Text;
            //>

            if (WorkMode.WorkType.Equals(WorkModeType.Create))
            {
                if (this.Owner != null)
                {
                    if (this.addToTheEndRadioBtn.Checked)
                    {
                        ((Form1)this.Owner).AddNewGroup(GroupToEditOrCreate);
                    }
                    else
                    {
                        ((Form1)this.Owner).AddNewGroup(GroupToEditOrCreate, false);
                    }
                }
            }
            else if (WorkMode.WorkType.Equals(WorkModeType.Edit))
            {
                if (this.Owner != null)
                {
                    ((Form1)this.Owner).UpdateGroup(GroupToEditOrCreate);
                }
            }

            if (!isImgNeeded)
            {
                this.Close();
                return;
            }

            //System folder path of selected item (full source file name)
            //string sourceFileName = this.groupImgPathTextBox.Text;
            //Get image extension
            string imgExtension = SourceFullFileName.Substring(SourceFullFileName.LastIndexOf('.'));

            // File name for saving in .xml file
            string fileName;

            fileName = SourceFullFileName
                       .Substring(SourceFullFileName.LastIndexOf("\\") + 1);

            if (!imgExtension.Equals(".png"))
            {
                fileName =
                    System.IO.Path.GetFileNameWithoutExtension(SourceFullFileName
                                                               .Substring(SourceFullFileName.LastIndexOf("\\") + 1)) + ".png";
            }

            //Full destination path for file (full destination file name)
            string destFolderName;

            if (((Form1)this.Owner).AppWorkMode.WorkType == WorkModeType.LoadFromFinalXml)
            {
                destFolderName = ((Form1)this.Owner).DestImgFolderPath +
                                 "\\" + fileName;

                if (!SourceFullFileName.Equals(destFolderName))
                {
                    if (!imgExtension.Equals(".png"))
                    {
                        Image img;
                        using (Stream fs = new FileStream(SourceFullFileName, FileMode.Open, FileAccess.ReadWrite))
                        {
                            img = Image.FromStream(fs);

                            try
                            {
                                img.Save(destFolderName, ImageFormat.Png);
                            }
                            catch
                            {
                                MessageBox.Show("Failed to save image to Png format.", "Error",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                    }
                    else
                    {
                        File.Copy(SourceFullFileName, destFolderName);
                    }
                }
            }
            else //oldMode
            {
                destFolderName = Path.Combine(Path.GetDirectoryName(
                                                  Assembly.GetExecutingAssembly().Location), @"Images\") +
                                 this.groupIdTextBox.Text +
                                 imgExtension;
                File.Copy(SourceFullFileName, destFolderName, true);
            }

            //remaking final xml file
            //((Form1)this.Owner).CreateFinalXmlFile();

            this.Close();
        }