Пример #1
0
        private void tsmiImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.DefaultExt  = "rcp";
            dlg.Filter      = "Рабочая рецептура (*.rcp)|*.rcp";
            dlg.Multiselect = false;
            DialogResult res = dlg.ShowDialog();

            if (res == DialogResult.OK && !dlg.FileName.Equals(""))
            {
                try
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(CommonFunctions.AbsolutePathFromAnyPath(Application.StartupPath, dlg.FileName));
                    XmlNode root = doc.DocumentElement;

                    DataRecept rcp = DataRecept.LoadFromXml(root, DataBook.Book, ReceptVersion.Version0);
                    if (rcp != null)
                    {
                        DataBook.Book.Components.Add(rcp);
                    }
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show("Невозможно импортировать файл:\n" + ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// создание блокировки файла пользователя
        /// </summary>
        /// <param name="fileToLock">файл пользователя</param>
        public DataLock(string fileToLock)
        {
            lockFile = CommonFunctions.AbsolutePathFromAnyPath(Application.StartupPath, fileToLock) + ".lock";
            FileStream  lf  = new FileStream(lockFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            XmlDocument doc = new XmlDocument();

            doc.Load(lf);
            XmlNode root = doc.DocumentElement;

            bool isExists = false;

            foreach (XmlNode curNode in root["users"].ChildNodes)
            {
                if (curNode.InnerText.Equals(userName))
                {
                    isExists = true;
                }
            }
            if (!isExists)
            {
                XmlNode user = root["users"].AppendChild(doc.CreateElement("user"));
                user.InnerText = userName;
            }
            doc.Save(lf);
            lf.Close();
        }
Пример #3
0
        OdbcDataAdapter adapter; // адаптер БД
        #endregion

        #region Конструктор класса
        public DPodbc()
        {
            // создаем соединение с БД
            try{
                //this.conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
                //    CommonFunctions.AbsolutePathFromAnyPath(Application.StartupPath, Config.cfg.dbFile));
                this.conn = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};DBQ=" +
                                               CommonFunctions.AbsolutePathFromAnyPath(Application.StartupPath, Config.Cfg.DBFile));
                //Extended Properties=dBase 5.0 // dbf
                this.adapter = new OdbcDataAdapter();
            } catch (OdbcException pe)
            {
                MessageBox.Show(pe.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0);
            }
        }
Пример #4
0
        /// <summary>
        /// загрузка книги из файла
        /// </summary>
        private void LoadFromFile(string file, bool isVerbose)
        {
            this.BeginUpdate();
            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(CommonFunctions.AbsolutePathFromAnyPath(Application.StartupPath, file));
                XmlNode root = doc.DocumentElement;
                if (root.Attributes.Count > 0)
                {
                    int curVer = int.Parse(root.Attributes["version"].Value, CultureInfo.CurrentCulture);
                    if (curVer == 0)
                    {
                        myVersion = ReceptVersion.Version0;
                    }
                    if (curVer == 1)
                    {
                        myVersion = ReceptVersion.Version1;
                    }
                }
                else
                {
                    myVersion = ReceptVersion.CurrentVersion; // нет версии (rcp)
                }

                foreach (XmlNode rootProps in root.ChildNodes)
                {
                    switch (rootProps.Name)
                    {
                    case "chief":
                        m_chiefName = rootProps.InnerText;
                        break;

                    case "chiefPost":
                        m_chiefPost = rootProps.InnerText;
                        break;

                    case "company":
                        _company = rootProps.InnerText;
                        break;

                    case "developer":
                        _developer = rootProps.InnerText;
                        break;

                    case "developerCompany":
                        _developerCompany = rootProps.InnerText;
                        break;

                    case "recepts":
                        foreach (XmlNode curNode in rootProps.ChildNodes)
                        {
                            Components.Add(DataRecept.LoadFromXml(curNode, this, myVersion));
                        }
                        break;

                    case "name":
                        Name = rootProps.InnerText;
                        break;
                    }
                }
            }
            catch (XmlException ex)
            {
                if (isVerbose)
                {
                    MessageBox.Show("Ошибка: " + ex.Message + "\n" + ex.StackTrace, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0);
                }
            }
            catch (FileNotFoundException ex)
            {
                if (isVerbose)
                {
                    MessageBox.Show("Ошибка: " + ex.Message + "\n" + ex.StackTrace, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0);
                }
            }

            // сортировка элементов
            Components.Sort(new DataBaseComparer());
            //Array.Sort(Components, new IfDataBaseNumSort());
            RenumberRecepts();
            EndUpdate(false);

            this.Changed  += new EventHandler <DataBaseEventArgs>(DataBook_Changed);
            this.IsChanged = false;
        }
Пример #5
0
 public FormAbout()
 {
     InitializeComponent();
     label2.Text     = "Версия " + Application.ProductVersion;
     webBrowser1.Url = new Uri(CommonFunctions.AbsolutePathFromAnyPath(Application.StartupPath, "version.txt"));
 }