Beispiel #1
0
        public static List <Comission> GetComissions()
        {
            ComissionList = new List <Comission>();
            SqlConnection conn = new SqlConnection();

            try
            {
                DatabaseControl dbc = new DatabaseControl();
                SqlDataReader   rd  = dbc.GetDataFromDB("select * from dbo.Comissions", out conn);
                if (rd != null)
                {
                    while (rd.Read())
                    {
                        Comission comission = new Comission();
                        comission.Index = int.Parse(rd["index_value"].ToString());
                        comission.From  = decimal.Parse(rd["from_value"].ToString().Replace(",", "."));
                        comission.To    = decimal.Parse(rd["to_value"].ToString().Replace(",", "."));
                        comission.Value = decimal.Parse(rd["value"].ToString().Replace(",", "."));
                        comission.Type  = int.Parse(rd["type_value"].ToString());
                        ComissionList.Add(comission);
                    }
                }
            }
            catch (Exception ex)
            {
                Singleton <Logger> .Instance.WriteMainLine("AdminModel:GetUserModels: " + ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(ComissionList);
        }
Beispiel #2
0
        public static Database LoadFiles(DatabaseControl db)
        {
            string s = File.ReadAllText(db.ViewModel.PathDatabase);

            string[] split      = s.Split(':');
            int      iterations = int.Parse(split[0]);
            int      numberOfEncryptionProcedures = int.Parse(split[1]);
            string   encryptString = split[2];

            if (split.Length > 3)
            {
                bool useArchiving = bool.Parse(split[3]);

                if (useArchiving)
                {
                    s = Compressing.Decompress(Encryptor.DecryptString(encryptString, db, iterations, numberOfEncryptionProcedures));
                }


                db.ViewModel.UseCompression = useArchiving;
            }
            else
            {
                s = Encryptor.DecryptString(encryptString, db, iterations, numberOfEncryptionProcedures);
                db.ViewModel.UseCompression = false;
            }

            if (split.Length > 4)
            {
                db.ViewModel.UseTrash = bool.Parse(split[4]);
            }

            return((Database) new XmlSerializer(typeof(Database)).Deserialize(new StringReader(s)));
        }
Beispiel #3
0
        public static List <Comission> GetCatalogs()
        {
            CatalogList = new List <BrandModel>();
            SqlConnection conn = new SqlConnection();

            try
            {
                DatabaseControl dbc = new DatabaseControl();
                SqlDataReader   rd  = dbc.GetDataFromDB("select * from dbo.Catalogs", out conn);
                if (rd != null)
                {
                    while (rd.Read())
                    {
                        BrandModel bm = new BrandModel();
                        bm.Name = rd["Name_of_Catalog"].ToString();
                        bm.Link = rd["IFrameLink"].ToString();
                        CatalogList.Add(bm);
                    }
                }
            }
            catch (Exception ex)
            {
                Singleton <Logger> .Instance.WriteMainLine("AdminModel:GetUserModels: " + ex.Message);
            }
            finally
            {
                conn.Close();
            }
            return(ComissionList);
        }
        public void Persist(int agentId)
        {
            this.AgentId = agentId;
            String SqlInsert = ClassControl.SqlInsertFromObject(this, typeof(Office));

            DatabaseControl.SendInsert(SqlInsert);
        }
Beispiel #5
0
        public Aototo()
        {
            SqlConnection conn = new SqlConnection();

            try
            {
                DatabaseControl dbc = new DatabaseControl();
                SqlDataReader   rd  = dbc.GetDataFromDB("select * from dbo.providers where id_provider=" + ID, out conn);
                if (rd != null)
                {
                    while (rd.Read())
                    {
                        UsrId        = rd["provider_user_id"].ToString().Trim();
                        Password     = rd["provider_password"].ToString().Trim();
                        Login        = rd["provider_user"].ToString().Trim();
                        ProviderName = rd["provider_name"].ToString().Trim();
                    }
                }
            }
            catch (Exception ex)
            {
                Singleton <Logger> .Instance.WriteMainLine("Aototo: Ошибка при получении данных провайдера: " + ex.Message);
            }
            finally
            {
                conn.Close();
            }
            _logPath = _logPath + "/" + ProviderName;
        }
        public static Boolean HasOnDatabase(Int32 Id)
        {
            String          connectionString = DatabaseControl.GetConnectionString();
            MySqlConnection conn             = new MySqlConnection(connectionString);

            try
            {
                var command = conn.CreateCommand();

                MySqlDataReader rdr = null;
                conn.Open();

                string       stm = String.Format("SELECT * FROM md_propertydetails WHERE ID={0}", Id);
                MySqlCommand cmd = new MySqlCommand(stm, conn);
                rdr = cmd.ExecuteReader();

                Int32 count = 0;

                while (rdr.Read())
                {
                    count++;
                    break;
                }

                return(count > 0);
            }catch (Exception ex)
            {
            }
            finally
            {
                conn.Clone();
            }

            return(false);
        }
Beispiel #7
0
        public static string EncryptString(string text, DatabaseControl db)
        {
            string encryptString = text;

            byte[] baPwd     = Encoding.UTF8.GetBytes(db.ViewModel.MasterPassword);
            byte[] baPwdHash = SHA256.Create().ComputeHash(baPwd);

            for (int d = 0; d < db.ViewModel.NumberOfEncryptionProcedures; d++)
            {
                byte[] baText      = Encoding.UTF8.GetBytes(encryptString);
                byte[] baSalt      = GetRandomBytes();
                byte[] baEncrypted = new byte[baSalt.Length + baText.Length];
                for (int i = 0; i < baSalt.Length; i++)
                {
                    baEncrypted[i] = baSalt[i];
                }
                for (int i = 0; i < baText.Length; i++)
                {
                    baEncrypted[i + baSalt.Length] = baText[i];
                }
                baEncrypted = AES_Encrypt(baEncrypted, baPwdHash, db.ViewModel.Iterations);

                encryptString = Convert.ToBase64String(baEncrypted);
            }

            return(encryptString);
        }
Beispiel #8
0
        public void GetShippingReturns_CorrectAddress()
        {
            using (var _context = new P1Context())
            {
                int    num    = 8301;
                string street = "Melrose St";
                string city   = "Houston";
                string state  = "TX";
                string zip    = "77022";

                Shipping address = DatabaseControl.GetAddress(1, _context);

                int    numA    = address.AddressNum;
                string streetA = address.AddressStreet;
                string cityA   = address.AddressCity;
                string stateA  = address.AddressState;
                string zipA    = address.AddressZipCode;

                Assert.Equal(num, numA);
                Assert.Equal(street, streetA);
                Assert.Equal(city, cityA);
                Assert.Equal(state, stateA);
                Assert.Equal(zip, zipA);
            }
        }
Beispiel #9
0
 public IActionResult TryRegister(UserAccount account, string password2)
 {
     if (account.Username == null || account.Password == null)
     {
         return(RedirectToAction("FieldEmpty"));
     }
     else
     {
         if (DatabaseControl.AccountExists(account, _context))
         {
             return(RedirectToAction("UsernameTaken"));
         }
         else if (account.Username.Length < 5)
         {
             return(RedirectToAction("UsernameTooShort"));
         }
         else if (account.Password != password2)
         {
             return(RedirectToAction("PasswordsDifferent"));
         }
         else if (account.Password.Length < 5)
         {
             return(RedirectToAction("PasswordTooShort"));
         }
         else
         {
             _account = account;
             SaveChanges();
             return(RedirectToAction("CustomerInput"));
         }
     }
 }
Beispiel #10
0
        public static bool RemoveDetailFromUserBasket(string userName, string [] hashes)
        {
            try
            {
                List <string> commands = new List <string>();
                foreach (var hash in hashes)
                {
                    if (String.IsNullOrEmpty(hash))
                    {
                        continue;
                    }
                    commands.Add(String.Format("DELETE FROM dbo.Baskets WHERE hash='{0}' and user_name='{1}'", hash,
                                               userName));
                }
                DatabaseControl dbc = new DatabaseControl();
                string          ex;
                return(dbc.SetTransactionDb(commands, out ex));
            }
            catch (Exception ex)
            {
                Singleton <Logger> .Instance.WriteMainLine("UserModels:SetDetailToUserBasket:" + ex.Message);

                return(false);
            }
        }
Beispiel #11
0
        public static bool AddDetailToUserBasket(string userName, Parameters.DetailInfo detail)
        {
            SqlConnection conn = new SqlConnection();
            string        request;

            try
            {
                request = String.Format("INSERT INTO dbo.Baskets (detai_price, " +
                                        "user_name, detail_name, detail_manuf, " +
                                        "detail_searchId, detail_Storage, " +
                                        "detail_Delivery, detail_PartId, " +
                                        "detail_baseCount, detail_Code, date_of_Upload_detail, hash) VALUES" +
                                        "({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')",
                                        detail.Price.ToString(CultureInfo.InvariantCulture).Replace(",", "."), userName, detail.Name, detail.Manuf, detail.SearchID, detail.Storage, detail.Delivery,
                                        detail.PartId, detail.BaseCount,
                                        detail.Code, detail.DateofPlacetoBasket, Manage.CalculateBasketDetailHash(detail));
                DatabaseControl dbctrl = new DatabaseControl();
                SqlDataReader   rd     = dbctrl.GetDataFromDB(request, out conn);
                if (rd.Read())
                {
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Singleton <Logger> .Instance.WriteMainLine("UserModels:SetDetailToUserBasket:" + ex.Message);

                return(false);
            }
            finally
            {
                conn.Close();
            }
            return(true);
        }
Beispiel #12
0
        public void Persist(int propertyId)
        {
            this.PropertyId = propertyId;
            String SqlInsert = ClassControl.SqlInsertFromObject(this, typeof(Address));

            DatabaseControl.SendInsert(SqlInsert);
        }
 public IActionResult ConfirmOrder()
 {
     DatabaseControl.PlaceOrder(Storage.GetShoppingCart(), Storage.GetCardUsing(), Storage.WhatsTheAddy(), Storage.GetCustomer(), Storage.GetLocation(), _context);
     ViewData["orderPlaced"] = "Your order has been placed! Click View Order to view your past orders.";
     Storage.CleanAfterOrder();
     return(View("../Locations/GetLocation", Storage.GetLocation()));
 }
 public IActionResult VerifyUsername(string username)
 {
     if (!DatabaseControl.AccountExists(username, _context))
     {
         return(Json($"Username {username} is already in use."));
     }
     return(Json(true));
 }
Beispiel #15
0
        public IActionResult ChooseAddress(int ID)
        {
            Storage.SetAddy(DatabaseControl.GetAddress(ID, _context));
            Storage.SetOrderDetails();
            Order orderDetails = Storage.GetOrder();

            return(View("../Orders/OrderDetails", orderDetails));
        }
Beispiel #16
0
        public static void AutoCheckUpdate()
        {
            //获取数据库执行类库
            IDatabaseControl inter = new DatabaseControl();

            //获取字典,写入文本
            inter.AutoCallDatabaseInfo();
        }
        public IActionResult GetMicsFrom()
        {
            _currentLocation = Storage.GetLocation();
            List <Product>        mics        = DatabaseControl.FindProductsOfTypeFromStore("MIC", _currentLocation, _context);
            List <ProductInStock> micsInStock = DatabaseControl.GetProductsInStockAtLocation(mics, _currentLocation, _context);

            return(View(micsInStock));
        }
        public IActionResult GetAccessoriesFrom()
        {
            _currentLocation = Storage.GetLocation();
            List <Product>        accs        = DatabaseControl.FindProductsOfTypeFromStore("ACC", _currentLocation, _context);
            List <ProductInStock> accsInStock = DatabaseControl.GetProductsInStockAtLocation(accs, _currentLocation, _context);

            return(View(accsInStock));
        }
        public IActionResult GetDrumsFrom()
        {
            _currentLocation = Storage.GetLocation();
            List <Product>        drums        = DatabaseControl.FindProductsOfTypeFromStore("DRUMS", _currentLocation, _context);
            List <ProductInStock> drumsInStock = DatabaseControl.GetProductsInStockAtLocation(drums, _currentLocation, _context);

            return(View(drumsInStock));
        }
        public IActionResult GetPianosFrom()
        {
            _currentLocation = Storage.GetLocation();
            List <Product>        pianos        = DatabaseControl.FindProductsOfTypeFromStore("PIANO", _currentLocation, _context);
            List <ProductInStock> pianosInStock = DatabaseControl.GetProductsInStockAtLocation(pianos, _currentLocation, _context);

            return(View(pianosInStock));
        }
        public IActionResult GetBassFrom()
        {
            _currentLocation = Storage.GetLocation();
            List <Product>        bass        = DatabaseControl.FindProductsOfTypeFromStore("BASS", _currentLocation, _context);
            List <ProductInStock> bassInStock = DatabaseControl.GetProductsInStockAtLocation(bass, _currentLocation, _context);

            return(View(bassInStock));
        }
        public IActionResult GetGuitarsFrom()
        {
            _currentLocation = Storage.GetLocation();
            List <Product>        guitars        = DatabaseControl.FindProductsOfTypeFromStore("GUITAR", _currentLocation, _context);
            List <ProductInStock> guitarsInStock = DatabaseControl.GetProductsInStockAtLocation(guitars, _currentLocation, _context);

            return(View(guitarsInStock));
        }
        public IActionResult FindLocationsWithProduct(int id)
        {
            List <Location> storeOptions = DatabaseControl.FindLocationsWithProduct(id, _context);
            Product         ProductToBuy = DatabaseControl.GetProduct(id, _context);

            Storage.SetProduct(ProductToBuy);
            ViewData["productName"] = ProductToBuy.Name;
            return(View("StoreOptions", storeOptions));
        }
Beispiel #24
0
        public void Persist(int propertyId)
        {
            this.PropertyId = propertyId;
            String SqlInsert = ClassControl.SqlInsertFromObject(this, typeof(AgentDetails));

            DatabaseControl.SendInsert(SqlInsert);

            this.Office.Persist(Int32.Parse(this.ID));
        }
        public void Persist(int propertyId)
        {
            this.PhotoLocation = String.Concat(propertyId, "_", (Int32.Parse(SequenceId) - 1), ".png");
            this.PropertyId    = propertyId.ToString();

            String SqlInsert = ClassControl.SqlInsertFromObject(this, typeof(PropertyPhoto));

            DatabaseControl.SendInsert(SqlInsert);
        }
        public IActionResult UseCard(int ID)
        {
            Billing card = DatabaseControl.GetCard(ID, _context);

            Storage.SetCardUsing(card);
            List <Shipping> addresses = DatabaseControl.GetShippingAddresssesOnFileForCustomer(Storage.GetCustomer(), _context);

            return(View("../Shipping/ShippingOptions", addresses));
        }
Beispiel #27
0
        public Boolean Persist(int PropertyId)
        {
            this.PropertyId = PropertyId;
            this.Dimension  = this.Dimension.Replace("'", String.Empty);
            this.Level      = this.Level.Replace("'", String.Empty);

            String SqlInsert = ClassControl.SqlInsertFromObject(this, typeof(Room));

            return(DatabaseControl.SendInsert(SqlInsert));
        }
Beispiel #28
0
 public void GetLocationReturns_CorrectLocation()
 {
     using (var _context = new P1Context())
     {
         string   storeName = "Wavey Davey's";
         Location store     = DatabaseControl.GetLocation(3, _context);
         string   name      = store.Name;
         Assert.Equal(storeName, name);
     }
 }
Beispiel #29
0
 public void GetCardReturns_CorrectCard()
 {
     using (var _context = new P1Context())
     {
         string  CardNumber = "4634653646346466";
         Billing card       = DatabaseControl.GetCard(1, _context);
         string  cardNum    = card.CardNumber;
         Assert.Equal(cardNum, CardNumber);
     }
 }
        public IActionResult GetAddToCart(int ID)
        {
            Location _currentLocation = DatabaseControl.GetLocation(ID, _context);

            Storage.SetLocation(_currentLocation);
            ProductInStock productInStock = DatabaseControl.GetProductInStock(Storage.GetProduct().ProductID, _currentLocation, _context);

            Storage.SetProductToBuy(productInStock);
            return(View("AddToCart", productInStock));
        }
Beispiel #31
0
    public void OnClick()
    {
        InputField login = GameObject.Find("Login").GetComponent<InputField>();
        InputField pass = GameObject.Find("Password").GetComponent<InputField>();

        if ((login.text != "") && (pass.text != ""))
        {
            DatabaseControl db = new DatabaseControl();
            Debug.Log("RESULTADO: " + db.Login(login.text, pass.text));
        }
    }
Beispiel #32
0
 public bool CreateFolder(Element element)
 {
     bool isFolderCreated = false;
     if (element.ParentElement.Path != root.Path)
     {
         DatabaseControl temp_dbControl = new DatabaseControl(element.ParentElement.Path);
         temp_dbControl.OpenConnection();
         isFolderCreated = temp_dbControl.CreateFolder(element);
         temp_dbControl.CloseConnection();
     }
     else
     {
         isFolderCreated = dbControl.CreateFolder(element);
     }
     return isFolderCreated;
 }
Beispiel #33
0
        private void xmlReader_DoWork(object sender, DoWorkEventArgs e)
        {
            while (pendingHeadingHighP.Count > 0)
            {
                try
                {
                    Element element = pendingHeadingHighP.Pop() as Element;
                    DatabaseControl temp_dbControl;
                    if (element.IsRemoteHeading)
                    {
                        string path = String.Empty;
                        IWshRuntimeLibrary.IWshShortcut shortcut = GetShortcut(element);
                        if (shortcut != null)
                        {
                            path = shortcut.TargetPath + System.IO.Path.DirectorySeparatorChar;
                        }
                        temp_dbControl = new DatabaseControl(path);
                    }
                    else
                    {
                        temp_dbControl = new DatabaseControl(element.Path);
                    }
                    temp_dbControl.newXooMLCreate += new NewXooMLCreateDelegate(dbControl_newXooMLCreate);
                    temp_dbControl.OpenConnection();
                    temp_dbControl.newDBControlHighP += new NewDatabaseControlHandler(dbControl_newDBControlHighP);
                    temp_dbControl.newDBControlLowP += new NewDatabaseControlHandler(dbControl_newDBControlLowP);

                    temp_dbControl.elementStatusChangedDelegate += new ElementStatusChangedDelegate(dbControl_elementStatusChanged);
                    temp_dbControl.elementDelete += new ElementDeleteDelegate(dbControl_elementDelete);

                    List<Element> eleList = temp_dbControl.GetAllElementFromXML();

                    int hiddenElements = 0;
                    foreach (Element ele in eleList)
                    {
                        Dispatcher.FromThread(mainThread).Invoke((AddElementMethodInvoker)delegate
                        {
                            if (tobeDeletedElements.Contains(ele))
                            {

                            }
                            else
                            {
                                Element temp_ele = temp_dbControl.GetFragmentElementFromXML();
                                element.ShowAssociationMarkedDefer = temp_ele.ShowAssociationMarkedDefer;
                                element.ShowAssociationMarkedDone = temp_ele.ShowAssociationMarkedDone;
                                element.StartDate = temp_ele.StartDate;
                                element.DueDate = temp_ele.DueDate;

                                if (ele.IsVisible == Visibility.Visible)
                                {
                                    if (ele.IsHeading)
                                    {
                                        ele.ParentElement = element;
                                        if (IsCircularHeading(ele))
                                        {
                                            if (ele.IsExpanded)
                                            {
                                                Stack<Element> s = new Stack<Element>();
                                                while (pendingHeadingHighP.Count != 0)
                                                {
                                                    Element _ele = pendingHeadingHighP.Pop() as Element;
                                                    if (_ele != ele)
                                                    {
                                                        s.Push(_ele);
                                                    }
                                                    else
                                                    {
                                                        while (s.Count != 0)
                                                        {
                                                            pendingHeadingHighP.Push(s.Pop());
                                                        }
                                                        break;
                                                    }
                                                }

                                                ele.IsExpanded = false;
                                            }
                                        }
                                    }
                                    AddElement(ele, element);
                                }
                                else
                                {
                                    hiddenElements++;
                                }
                            }

                        });
                    }

                    if (eleList.Count != 0 && hiddenElements == eleList.Count)
                    {
                        Dispatcher.FromThread(mainThread).Invoke((AddElementMethodInvoker)delegate
                        {
                            InsertCommandNote("Click the icon on the right to show hidden associations", ElementCommand.ShowHiddenAssociations, element);
                        });
                    }

                    if (element.CanImportCalendar)
                    {
                        Dispatcher.FromThread(mainThread).Invoke((AddElementMethodInvoker)delegate
                        {
                            InsertCommandNote("Click the icon on the right to import Meetings and Appointments from Outlook", ElementCommand.ImportMeetingsAndAppointmentsFromOutlook, element);
                        });
                    }

                    while (tobeDeletedElements.Count > 0)
                    {
                        Element tobedeleted = tobeDeletedElements.Pop();
                        tobedeleted.ParentElement = element;
                        DeleteElement(tobedeleted);
                    }
                }
                catch (Exception ex)
                {
                    continue;
                }
            }
        }
Beispiel #34
0
        // Includes UI change and XML IO
        public void InsertElement(Element newElement, Element parentElement, int index)
        {
            newElement.ParentElement = parentElement;
            parentElement.Elements.Insert(index, newElement);

            if (newElement.IsCommandNote)
            {
                return;
            }

            if (newElement.ParentElement.Path != root.Path)
            {
                DatabaseControl temp_dbControl = new DatabaseControl(newElement.ParentElement.Path);
                temp_dbControl.OpenConnection();
                temp_dbControl.InsertElementIntoXML(newElement);
                temp_dbControl.CloseConnection();
            }
            else
            {
                dbControl.InsertElementIntoXML(newElement);
            }
        }
Beispiel #35
0
        // Includes UI change and XML IO
        public void RemoveElement(Element element, Element parentElement)
        {
            string previousText = element.NoteText;
            parentElement.Elements.Remove(element);
            element.NoteText = previousText;

            if (element.ParentElement.Path != root.Path)
            {
                DatabaseControl temp_dbControl = new DatabaseControl(element.ParentElement.Path);
                temp_dbControl.OpenConnection();
                temp_dbControl.RemoveElementFromXML(element);
                temp_dbControl.CloseConnection();
            }
            else
            {
                dbControl.RemoveElementFromXML(element);
            }
        }
Beispiel #36
0
        public void PowerDDone(Element element, DateTime dt)
        {
            if (element == null)
            {
                return;
            }

            string dateFolderPath = JournalControl.GetJournalPath(dt) + System.IO.Path.DirectorySeparatorChar;

            Guid lastID = element.ID;
            Guid newID = Guid.NewGuid();
            element.ID = newID;
            element.PowerDStatus = PowerDStatus.Done;
            element.PowerDTimeStamp = dt;
            element.FontColor = ElementColor.SeaGreen.ToString();

            DatabaseControl temp_dbControl = new DatabaseControl(dateFolderPath);
            temp_dbControl.OpenConnection();
            bool isLocalFile = false;
            bool isLocalFolder = false;
            string targetFileName = element.AssociationURI;
            if (element.AssociationType == ElementAssociationType.File)
            {
                isLocalFile = true;
            }
            if (element.AssociationType == ElementAssociationType.Folder)
            {
                isLocalFolder = true;
            }
            if (isLocalFile || isLocalFolder)
            {
                string shortcutName = ShortcutNameConverter.GenerateShortcutNameFromFileName(element.AssociationURI, dateFolderPath);
                string shortcutPath = dateFolderPath + shortcutName;

                if (isLocalFile)
                {
                    element.AssociationType = ElementAssociationType.FileShortcut;
                }
                else
                {
                    element.AssociationType = ElementAssociationType.FolderShortcut;
                }
                element.AssociationURI = shortcutName;

                CreateShortcut(element, element.ParentElement.Path + targetFileName, shortcutPath);
            }
            Element parent = element.ParentElement;
            element.ParentElement = null;
            element.Position = -1;
            temp_dbControl.InsertElementIntoXML(element);
            element.ParentElement = parent;
            temp_dbControl.CloseConnection();
            if (isLocalFile)
            {
                element.AssociationType = ElementAssociationType.File;
                element.AssociationURI = targetFileName;
            }
            if (isLocalFolder)
            {
                element.AssociationType = ElementAssociationType.Folder;
                element.AssociationURI = targetFileName;
            }
            if (element.AssociationType != ElementAssociationType.None && !isLocalFile && !isLocalFolder)
            {
                System.IO.File.Copy(element.AssociationURIFullPath, dateFolderPath + element.AssociationURI);
            }

            element.ID = lastID;
            element.IsVisible = Visibility.Visible;
            element.TempData = dateFolderPath + "|" + newID.ToString();
            element.PowerDStatus = PowerDStatus.Done;
            element.PowerDTimeStamp = dt;
            element.FontColor = ElementColor.SpringGreen.ToString();

            UpdateElement(element);

            if (element.FlagStatus == FlagStatus.Flag)
            {
                Check(element);
            }
        }
Beispiel #37
0
        public void PowerDDelete(Element element, PowerDDeleteType pddt)
        {
            switch (pddt)
            {
                case PowerDDeleteType.Delete:
                    DeleteMessageType dmt = DeleteMessageType.Default;
                    switch (element.Type)
                    {
                        case ElementType.Heading:
                            if (element.IsRemoteHeading)
                            {
                                dmt = DeleteMessageType.InplaceExpansionHeading;
                            }
                            else
                            {
                                if (HasChildOrContent(element))
                                {
                                    dmt = DeleteMessageType.HeadingWithChildren;
                                }
                                else
                                {
                                    dmt = DeleteMessageType.HeadingWithoutChildren;
                                }
                            }
                            break;
                        case ElementType.Note:
                            if (element.HasAssociation)
                            {
                                switch (element.AssociationType)
                                {
                                    case ElementAssociationType.File:
                                        dmt = DeleteMessageType.NoteWithFileAssociation;
                                        break;
                                    case ElementAssociationType.FileShortcut:
                                    case ElementAssociationType.Web:
                                    case ElementAssociationType.Email:
                                        dmt = DeleteMessageType.NoteWithShortcutAssociation;
                                        break;
                                };
                            }
                            else
                            {
                                dmt = DeleteMessageType.NoteWithoutAssociation;
                            }
                            break;
                    };

                    if (dmt == DeleteMessageType.HeadingWithoutChildren ||
                        dmt == DeleteMessageType.NoteWithoutAssociation)
                    {

                    }
                    else
                    {
                        DeleteWindow dw = new DeleteWindow(dmt);
                        if (dw.ShowDialog().Value == true)
                        {

                        }
                        else
                        {
                            return;
                        }
                    }

                    DeleteElement(element);

                    break;
                case PowerDDeleteType.Undo:

                    string folderPath = String.Empty;
                    string oldGuid = String.Empty;
                    Element oldElement = null;
                    if (element.PowerDStatus == PowerDStatus.Done && element.TempData != String.Empty)
                    {
                        folderPath = element.TempData.Split('|')[0];
                        oldGuid = element.TempData.Split('|')[1];

                        DatabaseControl temp_dbControl = new DatabaseControl(folderPath);
                        temp_dbControl.OpenConnection();
                        foreach (Element ele in temp_dbControl.GetAllElementFromXML())
                        {
                            if (ele.ID.ToString() == oldGuid)
                            {
                                oldElement = ele;
                                break;
                            }
                        }

                        temp_dbControl.RemoveElementFromXML(oldElement);
                        temp_dbControl.CloseConnection();

                        if (oldElement != null && oldElement.AssociationURI != String.Empty)
                        {
                            if (oldElement.AssociationType == ElementAssociationType.File)
                            {
                                System.IO.File.Delete(element.AssociationURIFullPath);
                                System.IO.File.Move(folderPath + oldElement.AssociationURI, element.Path + oldElement.AssociationURI);

                                element.AssociationType = ElementAssociationType.File;
                                AssignICCInfo(element, element.Path + oldElement.AssociationURI);
                            }
                            else
                            {
                                System.IO.File.Delete(folderPath + oldElement.AssociationURI);
                            }
                        }
                    }

                    element.FontColor = ElementColor.Black.ToString();
                    element.TempData = String.Empty;
                    element.PowerDStatus = PowerDStatus.None;
                    element.IsVisible = Visibility.Visible;

                    break;
            };

            UpdateElement(element);
        }
Beispiel #38
0
        public void AddAppointments(Element element, DateTime dt)
        {
            Outlook.Application outlookApp = new Outlook.Application();

            // Get the NameSpace and Logon information.
            Outlook.NameSpace outlookNS = outlookApp.GetNamespace("mapi");

            //Log on by using a dialog box to choose the profile.
            outlookNS.Logon(Missing.Value, Missing.Value, true, true);

            // Lets Get The Calendar folder.
            Outlook.MAPIFolder outlookCal = outlookNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

            // Get the Items (Appointments) collection from the Calendar folder.
            Outlook.Items appointItems = outlookCal.Items;

            // Set start value
            DateTime startDt =
                new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);
            // Set end value
            DateTime endDt =
                new DateTime(dt.Year, dt.Month, dt.Day, 23, 59, 59);
            // Initial restriction is Jet query for date range
            string sCriteria = "[Start] >= '" +
                startDt.ToString("g")
                + "' AND [End] <= '" +
                endDt.ToString("g") + "'";

            //Use the Restrict method to reduce the number of items to process.
            Outlook.Items restrictedItems = appointItems.Restrict(sCriteria);

            restrictedItems.Sort("[Start]", Type.Missing);
            restrictedItems.IncludeRecurrences = true;

            //Get each item until item null.
            Outlook.AppointmentItem appointItem;
            //Preferably the first Item
            appointItem = (Outlook.AppointmentItem) restrictedItems.GetFirst();

            if (appointItem == null)
            {
                MessageBox.Show("There are no meetings or appointments in the Outlook calendar to import for this date.");
            }

            int count =0;
            foreach (Element ele in element.Elements)
            {
                if (ele.IsCommandNote == false)
                    break;
                count++;
            }

            while (appointItem != null)
            {
                //create heading for each appoints
                string newNoteText = appointItem.Start.ToShortTimeString() + " " + appointItem.Subject.ToString();

                if(newNoteText.Length > StartProcess.MAX_EXTRACTNAME_LENGTH)
                    newNoteText = newNoteText.Substring(0, StartProcess.MAX_EXTRACTNAME_LENGTH);

                bool bDuplicate = false;

                Element dupEle = element.FirstChild;

                bool bOverwrite = false;
                int index = 2;

                //Check whether there is duplicate appointments with same heading
                foreach (Element ele in FindAllHeadingElements(element))
                {
                    if (newNoteText == ele.NoteText)
                    {
                        //System.Windows.MessageBox.Show("Duplicate appointments found!\n");
                        dupEle = ele;
                        bDuplicate = true;
                        break;
                    }
                }
                System.Windows.MessageBoxButton buttons = System.Windows.MessageBoxButton.YesNo;
                string message = "The appointment has already existed,do you want to overwrite it?";
                string caption = newNoteText;

                //if duplicate appointment exists and user don't want to merge them, skip it
                if ((bDuplicate == true) && (System.Windows.MessageBox.Show(message, caption, buttons, System.Windows.MessageBoxImage.Warning, System.Windows.MessageBoxResult.Yes) == System.Windows.MessageBoxResult.No))
                {
                    appointItem = (Outlook.AppointmentItem)restrictedItems.GetNext();
                    continue;
                }
                Element appointEle = dupEle;
                if( bDuplicate== true)
                {
                    if (dupEle.IsExpanded)
                    {
                        //overwrite the current appointments
                        int remain = 0;
                        while (dupEle.Elements.Count > remain)
                        {
                            if (dupEle.FirstChild.AssociationType == ElementAssociationType.File)
                            {
                                remain++;
                                dupEle.Elements.Move(0, dupEle.Elements.Count - 1);
                                continue;
                            }
                            DeleteElement(dupEle.FirstChild);
                        }
                    }
                    else
                    {
                        DatabaseControl temp_dbControl = new DatabaseControl(dupEle.Path);
                        temp_dbControl.OpenConnection();
                        List<Element> eleList = temp_dbControl.GetAllElementFromXML();
                        foreach (Element ele in eleList)
                        {

                            if (ele.AssociationType != ElementAssociationType.File)
                            {
                                ele.ParentElement = dupEle;
                                dupEle.Elements.Add(ele);
                                DeleteElement(ele);
                            }
                        }
                        temp_dbControl.CloseConnection();
                    }

                    UpdateElement(dupEle);

                    appointEle = dupEle;
                    appointEle.Status = ElementStatus.New;
                    appointEle.FontColor = ElementColor.Blue.ToString();
                    appointEle.Position = count++;
                    UpdateElement(appointEle);
                }else
                {
                    //create new appointment
                    appointEle = CreateNewElement(ElementType.Heading, newNoteText);
                    appointEle.Status = ElementStatus.New;
                    appointEle.FontColor = ElementColor.Blue.ToString();
                    InsertElement(appointEle, element, count++);
                    UpdateElement(element);
                }

                //add subject
                Element subEle = CreateNewElement(ElementType.Note, string.Empty);
                subEle.FontColor = ElementColor.Blue.ToString();
                subEle.Status = ElementStatus.New;
                subEle.NoteText = "<no subject>";
                if (appointItem.Subject != null)
                    subEle.NoteText = "Subject: " + appointItem.Subject.ToString();

                if (subEle.NoteText.Length > StartProcess.MAX_EXTRACTTEXT_LENGTH)
                    subEle.NoteText = subEle.NoteText.Substring(0, StartProcess.MAX_EXTRACTTEXT_LENGTH) + "...";

                InsertElement(subEle, appointEle, appointEle.Elements.Count);

                //add location
                Element locEle = CreateNewElement(ElementType.Note, string.Empty);
                locEle.Status = ElementStatus.New;
                locEle.FontColor = ElementColor.Blue.ToString();

                locEle.NoteText = "<no location>";
                if (appointItem.Location != null)
                    locEle.NoteText = "Location: " + appointItem.Location.Trim().ToString();
                InsertElement(locEle, appointEle, appointEle.Elements.Count);

                //add start time
                Element startEle = CreateNewElement(ElementType.Note, string.Empty);
                startEle.FontColor = ElementColor.Blue.ToString();
                startEle.Status = ElementStatus.New;
                startEle.NoteText = "<no start time>";
                if (appointItem.Start != null)
                    startEle.NoteText = "Start time: " + appointItem.Start.ToShortTimeString();
                InsertElement(startEle, appointEle, appointEle.Elements.Count);

                //add end time
                Element endEle = CreateNewElement(ElementType.Note, string.Empty);
                endEle.Status = ElementStatus.New;
                endEle.FontColor = ElementColor.Blue.ToString();
                endEle.NoteText = "<no end time>";
                if (appointItem.End != null)
                    endEle.NoteText = "End Time: " + appointItem.End.ToShortTimeString();
                InsertElement(endEle, appointEle, appointEle.Elements.Count);

                //add attachments
                foreach (Outlook.Attachment attachment in appointItem.Attachments)
                {
                    string attachmentFileName = attachment.FileName;

                    Regex byproduct = new Regex("att[0-9]+[.txt|.c]");

                    if (!byproduct.IsMatch(attachmentFileName.ToLower()))
                    {
                        string fileNameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(attachmentFileName);
                        string fileNameExt = System.IO.Path.GetExtension(attachmentFileName);
                        string copyPath = appointEle.Path + attachmentFileName;

                        message = "The attachment has already existed,do you want to overwriet it?";

                        bOverwrite = true;
                        index = 2;
                        while (FileNameChecker.Exist(copyPath))
                        {
                            caption = attachmentFileName;
                            if (System.Windows.MessageBox.Show(message, caption, buttons, System.Windows.MessageBoxImage.Warning, System.Windows.MessageBoxResult.Yes) == System.Windows.MessageBoxResult.Yes)
                            {
                                bOverwrite = true;
                                break;
                            }
                            copyPath = appointEle.Path + fileNameWithoutExt + " (" + index.ToString() + ")" + fileNameExt;
                            attachmentFileName = fileNameWithoutExt + " (" + index.ToString() + ")" + fileNameExt;
                            index++;
                        }

                        attachment.SaveAsFile(copyPath);

                        if (bOverwrite == false)
                        {
                            Element attachmentElement = CreateNewElement(ElementType.Note, " --- " + fileNameWithoutExt);
                            attachmentElement.FontColor = ElementColor.Blue.ToString();
                            attachmentElement.Status = ElementStatus.New;
                            attachmentElement.AssociationType = ElementAssociationType.File;
                            attachmentElement.AssociationURI = System.IO.Path.GetFileName(copyPath);
                            attachmentElement.TailImageSource = FileTypeHandler.GetIcon((ElementAssociationType)attachmentElement.AssociationType, copyPath);
                            InsertElement(attachmentElement, appointEle, appointEle.Elements.Count);
                        }
                        else
                            appointEle.Elements.Move(0, appointEle.Elements.Count - 1);
                    }
                }

                //add body text

                Element bodyEle = CreateNewElement(ElementType.Note, string.Empty);
                bodyEle.Status = ElementStatus.New;
                bodyEle.FontColor = ElementColor.Blue.ToString();

                bodyEle.NoteText = "<no message>";
                if ((appointItem.Body != null) && (appointItem.Body.Trim() != string.Empty))
                {
                    bodyEle.NoteText = appointItem.Body.Replace("\r\n", " ").Replace("\t"," ").Trim();
                    if(bodyEle.NoteText.Length>StartProcess.MAX_EXTRACTTEXT_LENGTH)
                        bodyEle.NoteText = bodyEle.NoteText.Substring(0, StartProcess.MAX_EXTRACTTEXT_LENGTH) + "...";
                }
                //add the uri to appoint item in outlook
                InsertElement(bodyEle, appointEle, appointEle.Elements.Count);

                string fileFullName = appointItem.EntryID;

                ElementAssociationType type = ElementAssociationType.Appointment;
                string folderPath = appointEle.Path;

                string fileName = "<no subject>";
                if (appointItem.Subject != null)
                {
                    fileName = appointItem.Subject.ToString();
                    if (appointItem.Subject.Length > StartProcess.MAX_EXTRACTNAME_LENGTH)
                        fileName = appointItem.Subject.Substring(0, StartProcess.MAX_EXTRACTNAME_LENGTH);
                }

                string shortcutName = ShortcutNameConverter.GenerateShortcutNameFromAppointmentSubject(fileName, folderPath);
                AssignAssociationInfo(bodyEle, fileFullName, shortcutName, type);

                //appointEle.IsExpanded = true;
                UpdateElement(appointEle);

                appointItem = (Outlook.AppointmentItem)restrictedItems.GetNext();
            }

            // Log off
            outlookNS.Logoff();

            // Clean up
            appointItem = null;
            restrictedItems = null;
            appointItems = null;
            outlookCal = null;
            outlookNS = null;
            outlookApp = null;
        }
Beispiel #39
0
        public void PowerDDelegate(Element element, string folderPath)
        {
            if (Directory.Exists(folderPath) == false)
            {
                return;
            }

            if (MessageBox.Show("This association and its file or shortcut (if any) will be moved to \r\n" + folderPath, "Delegate", MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
            {
                return;
            }

            if (CheckOpenFiles(element) == true)
            {
                return;
            }

            element.PowerDStatus = PowerDStatus.Delegated;
            element.PowerDTimeStamp = DateTime.Now;

            Element parent = element.ParentElement;
            Guid id = element.ID;
            element.ID = Guid.NewGuid();
            element.Status = ElementStatus.New;
            element.FontColor = ElementColor.Blue.ToString();
            DatabaseControl temp_dbControl = new DatabaseControl(folderPath);
            temp_dbControl.OpenConnection();
            element.ParentElement = null;
            element.Position = -1;
            temp_dbControl.InsertElementIntoXML(element);
            temp_dbControl.CloseConnection();
            element.ParentElement = parent;
            element.ID = id;

            if (element.HasAssociation)
            {
                if (element.AssociationType == ElementAssociationType.Folder)
                {
                    System.IO.Directory.Move(element.AssociationURIFullPath, folderPath + element.AssociationURI);
                }
                else
                {
                    System.IO.File.Move(element.AssociationURIFullPath, folderPath + element.AssociationURI);
                }
            }

            string folderName = System.IO.Directory.GetParent(folderPath).Name;

            element.NoteText = "\"" + element.NoteText + "\" has been moved to: " + folderName;
            element.Status = ElementStatus.Normal;
            element.PowerDStatus = PowerDStatus.Done;
            element.PowerDTimeStamp = DateTime.Now;
            element.FontColor = ElementColor.SpringGreen.ToString();

            element.AssociationType = ElementAssociationType.FolderShortcut;
            string shortcutName = ShortcutNameConverter.GenerateShortcutNameFromFileName(folderName, parent.Path);
            string shortcutPath = parent.Path + shortcutName;
            element.AssociationURI = shortcutName;
            CreateShortcut(element, folderPath, shortcutPath);

            element.TailImageSource = FileTypeHandler.GetIcon(ElementAssociationType.FolderShortcut, element.AssociationURIFullPath);

            UpdateElement(element);
        }
Beispiel #40
0
        public void LabelWith(Element element, string path)
        {
            ElementControl temp_eleControl = new ElementControl(path);

            Element ele = new Element
            {
                ID = Guid.NewGuid(),
                ParentElement = temp_eleControl.Root,
                HeadImageSource = String.Empty,
                TailImageSource = String.Empty,
                NoteText = element.NoteText,
                Path = path,
                Type = ElementType.Note,
                Status = ElementStatus.New,
                FontColor = ElementColor.Blue.ToString(),
                Position = 0,
            };

            string shortcutName = ShortcutNameConverter.GenerateShortcutNameFromFileName(element.AssociationURI, path);
            string shortcutPath = path + shortcutName;

            ele.AssociationType = ElementAssociationType.FolderShortcut;
            ele.AssociationURI = shortcutName;
            CreateShortcut(ele, element.Path, shortcutPath);

            temp_eleControl.Root.Elements.Insert(0, ele);

            DatabaseControl temp_dbControl = new DatabaseControl(path);
            temp_dbControl.OpenConnection();
            temp_dbControl.InsertElementIntoXML(ele);
            temp_dbControl.CloseConnection();

            temp_eleControl.UpdateElement(ele);

            string folderName, parentName, tempPath;
            int pos;
            char[] ds = { '\\' };

            tempPath = path.TrimEnd(ds);

            pos = tempPath.LastIndexOfAny(ds);
            folderName = tempPath.Substring(pos + 1);
            tempPath = tempPath.Remove(pos);

            pos = tempPath.LastIndexOfAny(ds);
            parentName = tempPath.Substring(pos + 1);

            //string notifyText = "Labeled with \"" + System.IO.Path.GetFileName(targetPath) + "\" under \"" + System.IO.Path.Path.GetFileName(parent) + "\"";
            string notifyText = "Labeled with \"" + folderName + "\" under \"" + parentName + "\"";

            //add an note for notification
            Element notifyEle = new Element
            {
                ID = Guid.NewGuid(),
                ParentElement = element,
                NoteText = notifyText,
                Path = element.Path,
                Type = ElementType.Note,
                Status = ElementStatus.New,
                FontColor = ElementColor.SpringGreen.ToString(),
                Position = 0,
            };

            /*
            shortcutName = ShortcutNameConverter.GenerateShortcutNameFromFileName(folderName, element.Path);
            shortcutPath = element.Path + shortcutName;

            notifyEle.AssociationType = ElementAssociationType.FolderShortcut;
            notifyEle.AssociationURI = shortcutName;
            CreateShortcut(notifyEle, path, shortcutPath);
            notifyEle.TailImageSource = FileTypeHandler.GetIcon(ElementAssociationType.FolderShortcut, notifyEle.AssociationURIFullPath);
            */
            notifyEle.PowerDStatus = PowerDStatus.Done;
            notifyEle.PowerDTimeStamp = DateTime.Now;
            InsertElement(notifyEle, element, 0);

            UpdateElement(element);
        }
Beispiel #41
0
        public void DisplayMoreAssociations(Element element)
        {
            try
            {
                Queue<Element> displayElements = new Queue<Element>();

                DatabaseControl temp_dbControl = new DatabaseControl(element.ParentElement.Path);
                temp_dbControl.OpenConnection();
                temp_dbControl.SHOW_ME_ALL = true;
                List<Element> eleList = temp_dbControl.GetAllElementFromXML();
                temp_dbControl.CloseConnection();

                Element eleAbove = element.ElementAboveUnderSameParent;
                int pos = 0;
                int j = 0;
                bool more = false;
                if (eleAbove != null)
                {
                    pos = eleAbove.Position;
                    for (j = 0; j < eleList.Count; j++)
                    {
                        if (eleList[j].ID == eleAbove.ID)
                        {
                            j++;
                            break;
                        }
                    }
                }
                for (; j < eleList.Count; j++)
                {
                    if (eleList[j].IsVisible == Visibility.Collapsed)
                    {
                        displayElements.Enqueue(eleList[j]);
                        if (displayElements.Count == MAX_NEWASSOCIATION_VISIBLE)
                        {
                            more = true;
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }

                while (displayElements.Count > 0)
                {
                    Element ele = displayElements.Dequeue();
                    ele.ParentElement = element.ParentElement;
                    ele.IsVisible = Visibility.Visible;
                    element.ParentElement.Elements.Insert(++pos, ele);
                    UpdateElement(ele);
                }

                if (!more)
                {
                    element.ParentElement.Elements.Remove(element);
                }
            }
            catch (Exception ex)
            {

            }
        }
Beispiel #42
0
        // Note: param "rootElementPath" should be ending with System.IO.Path.DirectorySeparatorChar
        public ElementControl(string rootElementPath)
        {
            root = new Element
            {
                ParentElement = null,
                HeadImageSource = String.Empty,
                TailImageSource = String.Empty,
                NoteText = String.Empty,
                IsExpanded = true,
                Path = rootElementPath,
                Type = ElementType.Heading,
            };

            ni_root = new NavigationItem
            {
                Name = String.Empty,
                Path = rootElementPath,
                Parent = null,
            };

            dbControl = new DatabaseControl(rootElementPath);
            dbControl.newXooMLCreate += new NewXooMLCreateDelegate(dbControl_newXooMLCreate);
            dbControl.OpenConnection();
            dbControl.newDBControlHighP += new NewDatabaseControlHandler(dbControl_newDBControlHighP);
            dbControl.newDBControlLowP += new NewDatabaseControlHandler(dbControl_newDBControlLowP);
            dbControl.elementUpdate += new ElementUpdateDelegate(dbControl_elementUpdate);
            dbControl.elementStatusChangedDelegate += new ElementStatusChangedDelegate(dbControl_elementStatusChanged);
            dbControl.elementDelete += new ElementDeleteDelegate(dbControl_elementDelete);

            root.ShowAssociationMarkedDone = dbControl.GetFragmentElementFromXML().ShowAssociationMarkedDone;
            root.ShowAssociationMarkedDefer = dbControl.GetFragmentElementFromXML().ShowAssociationMarkedDefer;

            foreach (Element element in dbControl.GetAllElementFromXML())
            {
                if (element.IsVisible == Visibility.Collapsed)
                {
                    continue;
                }

                AddElement(element, root);

                if (element.IsHeading)
                {
                    NavigationItem ni = new NavigationItem
                    {
                        Name = element.NoteText,
                        Path = element.Path,
                        Parent = ni_root,
                    };
                    ni.Items.Add(new NavigationItem());
                    ni_root.Items.Add(ni);
                }
            }

            currentElement = root;

            RunXMLBackgroundWorker();
        }
Beispiel #43
0
        public void ShowOrHidePowerDElement(Element parent, PowerDStatus status, bool show)
        {
            try
            {
                DatabaseControl temp_dbControl;
                List<Element> allElements = new List<Element>();

                if (parent.Path != root.Path)
                {
                    temp_dbControl = new DatabaseControl(parent.Path);
                    temp_dbControl.OpenConnection();
                    temp_dbControl.DO_NOT_UPDATE_POWERDREGION = true;
                    allElements = temp_dbControl.GetAllElementFromXML();

                }
                else
                {
                    temp_dbControl = dbControl;
                    temp_dbControl.DO_NOT_UPDATE_POWERDREGION = true;
                    allElements = temp_dbControl.GetAllElementFromXML();
                    temp_dbControl.DO_NOT_UPDATE_POWERDREGION = false;
                }

                for (int i = allElements.Count - 1; i >= 0; i--)
                {
                    if (allElements[i].PowerDStatus == status)
                    {
                        //allElements[i].ParentElement = parent;
                        if (show)
                        {
                            allElements[i].IsVisible = Visibility.Visible;
                        }
                        else
                        {
                            allElements[i].IsVisible = Visibility.Collapsed;
                            for (int j = parent.Elements.Count - 1; j >= 0 ; j--)
                            {
                                if (parent.Elements[j].ID == allElements[i].ID)
                                {
                                    parent.Elements.RemoveAt(j);
                                    break;
                                }
                            }
                        }
                        UpdateElement(allElements[i]);
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }
        private void button_OK_Click(object sender, RoutedEventArgs e)
        {
            // return;
            // Click to save the note
            //none of URI or note is available, there is nothing to save

            if (newNoteText.Length == 0 && newInfoItem == null)
                return;

            bNoteModified = false;
            bSkipModifyConfirmation = false;

            //use the title as note, if only URI is available
            if (newInfoItem!=null && newNoteText.Length == 0 )
                newNoteText = newInfoItem.Title;

            ComboBoxItem cbi_sel = (ComboBoxItem) comboBox_SaveLoc.SelectedItem;

            string xmlFileFullPath = cbi_sel.Tag.ToString();

            Element parentElement = new Element
            {
                ParentElement = null,
                HeadImageSource = String.Empty,
                TailImageSource = String.Empty,
                NoteText = String.Empty,
                IsExpanded = true,
                Path = xmlFileFullPath,
                Type = ElementType.Heading,
            };

            Element newElement = new Element
            {
                ParentElement = parentElement,
                HeadImageSource = String.Empty,
                TailImageSource = String.Empty,
                NoteText = newNoteText,
                IsExpanded = false,
                Path = xmlFileFullPath,
                Type = ElementType.Note,
                FontColor = ElementColor.Blue.ToString(),
                Status = ElementStatus.New,
            };

            newElement.ParentElement = parentElement;
            newElement.Position = 0;

            if ((newInfoItem != null) && (bool)checkBox_URI.IsChecked)
            {
                ElementAssociationType newType;
                switch (newInfoItem.Type)
                {
                    case InfoItemType.Email:
                        newType = ElementAssociationType.Email;
                        break;
                    case InfoItemType.File:
                        newType = ElementAssociationType.FileShortcut;
                        break;
                    case InfoItemType.Web:
                        newType = ElementAssociationType.Web;
                        break;
                    default:
                        newType = ElementAssociationType.None;
                        break;
                }
                newElement.AssociationType = newType;
            }

            try
            {
                newElement.ParentElement.Elements.Insert(0, newElement);

                DatabaseControl temp_dbControl = new DatabaseControl(newElement.ParentElement.Path);
                temp_dbControl.OpenConnection();
                temp_dbControl.InsertElementIntoXML(newElement);
                temp_dbControl.CloseConnection();

                ElementControl elementControl = new ElementControl(newElement.ParentElement.Path);
                elementControl.CurrentElement = newElement;

                //if URI is available and selected, association will be added together with the note
                if ((newInfoItem!= null) && (bool)checkBox_URI.IsChecked)
                {
                    elementControl.AddAssociation(newElement, newInfoItem.Uri, newElement.AssociationType, newNoteText);
                }

                string eventInfo = LogEventInfo.NoteText + LogControl.COMMA + newElement.NoteText;

                if ((bool)checkBox_URI.IsChecked)
                    eventInfo += LogControl.DELIMITER + LogEventInfo.LinkStatus + LogControl.COMMA + "check";
                else
                    eventInfo += LogControl.DELIMITER + LogEventInfo.LinkStatus + LogControl.COMMA + "unCheck";

                if(newInfoItem!=null && newInfoItem.Uri!=null)
                    eventInfo += LogControl.DELIMITER + LogEventInfo.LinkedFile + LogControl.COMMA + newInfoItem.Uri;

                eventInfo += LogControl.DELIMITER + LogEventInfo.PutUnder + LogControl.COMMA + newElement.Path;

                LogControl.Write(
                elementControl.CurrentElement,
                LogEventAccess.QuickCapture,
                LogEventType.CreateNewNote,
                LogEventStatus.NULL,
                eventInfo);

                newInfoItem = null;

            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("QuickCapture_button_OK_Click\n" + ex.Message);

                LogControl.Write(
                   newElement,
                   LogEventAccess.QuickCapture,
                   LogEventType.CreateNewNote,
                   LogEventStatus.Error,
                   LogEventInfo.ErrorMessage + LogControl.COMMA + ex.Message);
            }

            ReInitilize();

            this.Visibility = Visibility.Hidden;
            this.ShowInTaskbar = true;
        }
Beispiel #45
0
        public void SyncNavigationItem(NavigationItem ni_root)
        {
            List<NavigationItem> ni_list;

            if (ni_root.Path != root.Path)
            {
                DatabaseControl temp_dbControl = new DatabaseControl(ni_root.Path);
                temp_dbControl.OpenConnection();
                ni_list = temp_dbControl.GetAllHeadingElementFromXML();
                temp_dbControl.CloseConnection();
            }
            else
            {
                ni_list = dbControl.GetAllHeadingElementFromXML();
            }

            ni_root.Items.Clear();
            foreach (NavigationItem ni in ni_list)
            {
                ni.Parent = ni_root;
                ni.Items.Add(new NavigationItem());
                ni_root.Items.Add(ni);
            }
        }
Beispiel #46
0
        public void UpdateDaysAhead()
        {
            Element today = GetTodayElement();
            if (today != null)
            {
                Element daysahead = null;
                DatabaseControl tmp_dbControl = new DatabaseControl(today.Path);
                List<Element> eleList = new List<Element>();

                if (today.IsExpanded == true)
                {
                    foreach (Element ele in today.Elements)
                    {
                        if (ele.NoteText == StartProcess.DAYS_AHEAD)
                        {
                            daysahead = ele;
                            break;
                        }
                    }
                }
                else
                {
                    tmp_dbControl.OpenConnection();
                    eleList = tmp_dbControl.GetAllElementFromXML();
                    tmp_dbControl.CloseConnection();

                    foreach (Element ele in eleList)
                    {
                        if (ele.NoteText == StartProcess.DAYS_AHEAD)
                        {
                            daysahead = ele;
                            break;
                        }
                    }
                }

                if (daysahead != null)
                {
                    daysahead.Elements.Clear();
                    GC.Collect();
                    System.IO.DirectoryInfo di = new DirectoryInfo(daysahead.Path);
                    try
                    {
                        FileInfo[] fi = di.GetFiles();
                        for (int i = 0; i < fi.Length; i++)
                        {
                            Regex regex = new Regex(@"\d{4}-\d{2}-\d{2},\w*");
                            string filename = fi[i].Name;
                            if (filename == "XooML.xml" || regex.Match(filename).Success)
                            {
                                fi[i].Delete();
                            }
                        }

                        DatabaseControl temp_dbControl = new DatabaseControl(daysahead.Path);
                        temp_dbControl.OpenConnection();
                        temp_dbControl.CloseConnection();
                    }
                    catch (Exception)
                    {
                        return;
                    }
                }
                else
                {
                    daysahead = CreateNewElement(ElementType.Heading, String.Empty);
                    daysahead.Status = ElementStatus.Special;
                    InsertElement(daysahead, today, today.Elements.Count);
                    daysahead.NoteText = StartProcess.DAYS_AHEAD;
                    UpdateElement(daysahead);
                }

                const int num_daysahead = 7;
                List<string> journalPath = JournalControl.GetJournalPathDaysAhead(DateTime.Now, num_daysahead);
                for (int i = 0; i < num_daysahead; i++)
                {
                    string dayPath = journalPath[i];
                    string dayName = System.IO.Path.GetFileName(dayPath);
                    int period = dayName.IndexOf(',');
                    string part1 = dayName.Substring(0, period);
                    string part2 = dayName.Substring(period + 2);
                    Element dayElement = CreateNewElement(ElementType.Note, System.IO.Path.GetFileName(dayPath));
                    if (i == 0)
                    {
                        part2 = "Today";
                    }
                    else if (i == 1)
                    {
                        part2 = "Tomorrow";
                    }
                    dayElement.NoteText = part2 + ", " + part1;
                    InsertElement(dayElement, daysahead, daysahead.Elements.Count);
                    AddAssociation(dayElement, dayPath, ElementAssociationType.FolderShortcut, null);
                    Promote(dayElement);
                }
            }
        }
Beispiel #47
0
        // Includes XML IO
        public void UpdateElement(Element element)
        {
            if (element == root)
            {
                dbControl.UpdateFragmentElementIntoXML(element);
                return;
            }

            if (element.IsCommandNote)
            {
                return;
            }

            if (element.ParentElement == null)
            {
                return;
            }

            if (element.IsLocalHeading)
            {
                string previousName = System.IO.Directory.GetParent(element.Path).Name;
                string currentName = HeadingNameConverter.ConvertFromHeadingNameToFolderName(element);
                if (previousName != currentName)
                {
                    if (CheckOpenFiles(element) == true)
                    {
                        return;
                    }
                }
            }

            if (element.ParentElement.Path != root.Path)
            {
                DatabaseControl temp_dbControl = new DatabaseControl(element.ParentElement.Path);
                temp_dbControl.newXooMLCreate += new NewXooMLCreateDelegate(dbControl_newXooMLCreate);
                temp_dbControl.OpenConnection();
                temp_dbControl.elementStatusChangedDelegate += new ElementStatusChangedDelegate(dbControl_elementStatusChanged);
                temp_dbControl.UpdateElementIntoXML(element);
                temp_dbControl.CloseConnection();
            }
            else
            {
                dbControl.UpdateElementIntoXML(element);
            }

            switch (element.Type)
            {
                case ElementType.Heading:
                    if (element.IsLocalHeading)
                    {
                        string previousPath = element.Path;
                        element.Path = element.ParentElement.Path + HeadingNameConverter.ConvertFromHeadingNameToFolderName(element) + System.IO.Path.DirectorySeparatorChar;
                        try
                        {
                            RenameFolder(element, previousPath);
                        }
                        catch (Exception)
                        {
                            element.Path = previousPath;
                            element.NoteText = System.IO.Directory.GetParent(element.Path).Name;
                            MessageBox.Show("The heading name is too long, please shorten the name and try again.");
                            return;
                        }
                    }
                    DatabaseControl temp_dbControl = new DatabaseControl(element.Path);
                    temp_dbControl.newXooMLCreate +=new NewXooMLCreateDelegate(dbControl_newXooMLCreate);
                    temp_dbControl.OpenConnection();
                    temp_dbControl.UpdateFragmentElementIntoXML(element);
                    temp_dbControl.CloseConnection();
                    break;
                case ElementType.Note:
                    break;
            };
        }
Beispiel #48
0
 // Use this for initialization
 void Start()
 {
     db = new DatabaseControl();
 }
Beispiel #49
0
        public void UpdateRootPath(string newRootPath)
        {
            root.Path = newRootPath;
            root.Elements.Clear();

            ni_root.Path = newRootPath;
            ni_root.Items.Clear();
            ni_root.Items.Clear();
            selectedElements.Clear();
            updateStatusList.Clear();
            tobeDeletedElements.Clear();

            GC.Collect();

            dbControl = new DatabaseControl(newRootPath);
            dbControl.newXooMLCreate += new NewXooMLCreateDelegate(dbControl_newXooMLCreate);
            dbControl.OpenConnection();
            dbControl.newDBControlHighP += new NewDatabaseControlHandler(dbControl_newDBControlHighP);
            dbControl.newDBControlLowP += new NewDatabaseControlHandler(dbControl_newDBControlLowP);
            dbControl.elementUpdate += new ElementUpdateDelegate(dbControl_elementUpdate);
            dbControl.elementStatusChangedDelegate += new ElementStatusChangedDelegate(dbControl_elementStatusChanged);
            dbControl.elementDelete += new ElementDeleteDelegate(dbControl_elementDelete);

            foreach (Element element in dbControl.GetAllElementFromXML())
            {
                AddElement(element, root);

                if (element.IsHeading)
                {
                    NavigationItem ni = new NavigationItem
                    {
                        Name = element.NoteText,
                        Path = element.Path,
                        Parent = ni_root,
                    };
                    ni.Items.Add(new NavigationItem());
                    ni_root.Items.Add(ni);
                }
            }

            currentElement = root;

            RunXMLBackgroundWorker();
        }
Beispiel #50
0
        public bool HasChildOrContent(Element element)
        {
            if (element.IsNote)
            {
                return false;
            }
            else if (element.HasChildren)
            {
                return true;
            }
            else
            {
                System.IO.DirectoryInfo di = new DirectoryInfo(element.Path);

                DatabaseControl temp_dbControl = new DatabaseControl(element.Path);
                temp_dbControl.OpenConnection();
                bool noContent = false;
                if (temp_dbControl.GetAllElementFromXML().Count == 0)
                {
                    if (di.GetFiles().Length == 1 && di.GetFiles()[0].Name == StartProcess.XOOML_XML_FILENAME)
                    {
                        noContent = true;
                    }
                }
                temp_dbControl.CloseConnection();

                return !noContent;
            }
        }
Beispiel #51
0
        public void HideElement(Element element)
        {
            if (element.IsCommandNote)
            {
                return;
            }

            if (element.ElementAboveUnderSameParent != null &&
                element.ElementAboveUnderSameParent.IsCommandNote &&
                element.ElementAboveUnderSameParent.Command == ElementCommand.DisplayMoreAssociations)
            {
                int hiddenAssociationCount = Int32.Parse(element.ElementAboveUnderSameParent.NoteText.Split(' ')[10]);
                element.ElementAboveUnderSameParent.NoteText = String.Format("Click the icon on the right to show the next {0} association(s)", ++hiddenAssociationCount);
            }
            else if (element.ElementBelowUnderSameParent != null &&
                element.ElementBelowUnderSameParent.IsCommandNote &&
                element.ElementBelowUnderSameParent.Command == ElementCommand.DisplayMoreAssociations)
            {
                int hiddenAssociationCount = Int32.Parse(element.ElementBelowUnderSameParent.NoteText.Split(' ')[10]);
                element.ElementBelowUnderSameParent.NoteText = String.Format("Click the icon on the right to show the next {0} association(s)", ++hiddenAssociationCount);
            }
            else
            {
                int hiddenAssociationCount = 0;
                Element commandNote = new Element();
                commandNote.Type = ElementType.Note;
                commandNote.Command = ElementCommand.DisplayMoreAssociations;
                commandNote.Status = ElementStatus.Special;
                commandNote.TailImageSource = String.Format("pack://application:,,,/{0};component/{1}", "Planz", "Images/command.png");
                commandNote.HasAssociation = true;
                commandNote.CanOpen = false;
                commandNote.CanExplore = false;
                commandNote.CanRename = false;
                commandNote.CanDelete = false;
                commandNote.NoteText = String.Format("Click the icon on the right to show the next {0} association(s)", ++hiddenAssociationCount);

                InsertElement(commandNote, element.ParentElement, element.Position);
            }

            element.IsVisible = Visibility.Collapsed;

            DatabaseControl temp_dbControl = new DatabaseControl(element.ParentElement.Path);
            temp_dbControl.OpenConnection();
            temp_dbControl.UpdateElementIntoXML(element);
            temp_dbControl.CloseConnection();
        }