예제 #1
0
        public void add_task(int synch_folder_id, int folder_id, int?search_id, string stato
                             , string title, string assegna, string priorita, string tipo, string stima)
        {
            if (string.IsNullOrEmpty(title))
            {
                throw new Exception("il titolo non è stato specificato!");
            }

            string folder_path = folder_id > 0 ? db_conn.first_row(core.parse_query("folder-local-path"
                                                                                    , new string[, ] {
                { "folder_id", folder_id.ToString() }
            }))["local_path"].ToString() :
                                 db_conn.first_row(core.parse_query("synch-folder-local-path"
                                                                    , new string[, ] {
                { "synch_folder_id", synch_folder_id.ToString() }
            }))["local_path"].ToString();

            List <free_label> fl = load_free_labels();

            // creo la cartella fisica
            string name = title + ".task", fp = Path.Combine(folder_path, name);

            Directory.CreateDirectory(fp);

            // creo l'indice
            doc_task it = doc_task.exists_index(this.core, fp) ? doc_task.open_index(this.core, fp) : doc_task.create_index(this.core, fp);

            it.dt_create = DateTime.Now;
            if (!string.IsNullOrEmpty(assegna))
            {
                it.user = assegna;
            }
            if (!string.IsNullOrEmpty(stato))
            {
                it.stato = stato;
            }
            if (!string.IsNullOrEmpty(priorita))
            {
                it.priorita = priorita;
            }
            if (!string.IsNullOrEmpty(tipo))
            {
                it.tipo = tipo;
            }
            if (!string.IsNullOrEmpty(stima))
            {
                it.stima = stima;
            }
            it.save();

            // aggiorno il db
            long new_folder_id = long.Parse(synch_folder_id > 0 ?
                                            db_conn.exec(core.parse_query("lib-notes.task-ins-into-synch", new string[, ] {
                { "synch_folder_id", synch_folder_id.ToString() }, { "name", name }
            }), true)
        : db_conn.exec(core.parse_query("lib-notes.task-ins-into-folder", new string[, ] {
                { "folder_id", folder_id.ToString() }, { "name", name }
            }), true));

            long new_task_id = long.Parse(db_conn.exec(core.parse_query("lib-notes.ins-task-from-folder", new string[, ] {
                { "folder_id", new_folder_id.ToString() }
                , { "title", title }, { "user", assegna }, { "stato", !string.IsNullOrEmpty(stato) ? stato : "da_fare" }
                , { "priorita", priorita }, { "tipo", tipo }, { "stima", stima }, { "dt_lwt_index", it.lwt.ToString("yyyy/MM/dd HH:mm:ss") }
            }), true));

            if (search_id.HasValue)
            {
                db_conn.exec(core.parse_query("lib-notes.ins-task-into-search", new string[, ] {
                    { "search_id", search_id.ToString() }, { "task_id", new_task_id.ToString() }
                }));
            }
        }
예제 #2
0
        public void update_task(int task_id, out string rel_path, List <free_label> fl, string title = null, string assegna = null
                                , string stato = null, string priorita = null, string stima = null, string tipo = null)
        {
            rel_path = "";

            // aggiorno il file/folder
            DataRow r = db_conn.first_row(core.parse_query("lib-notes.task-paths", new string[, ] {
                { "task_id", task_id.ToString() }
            }));

            if (r == null)
            {
                throw new Exception("il task " + task_id.ToString() + " non c'è in tabella!");
            }
            if (db_provider.int_val(r["file_id"]) > 0)
            {
                throw new Exception("questo tipo di task non è supportato, lanciare il comando synch!");
            }
            rel_path = db_provider.str_val(r["rel_path"]);
            string folder_path = db_provider.str_val(r["folder_path"]), name = !string.IsNullOrEmpty(title) ? title : db_provider.str_val(r["task_name"])
            , f_name = db_provider.str_val(r["folder_name"]), src = Path.Combine(folder_path, f_name);

            // leggo il doc. indice
            doc_task it = null;

            if (doc_task.exists_index(core, src))
            {
                it = doc_task.open_index(core, src);
            }
            else
            {
                it = doc_task.create_index(core, src);
            }

            // rinomino il folder
            string folder_name = Path.GetFileName(src);

            if (folder_name.ToLower() != (name + ".task").ToLower())
            {
                string new_name = name + ".task", new_path = Path.Combine(Path.GetDirectoryName(src), new_name);
                if (Directory.Exists(new_path))
                {
                    throw new Exception("cè già la cartella " + new_path);
                }
                Directory.Move(src, new_path);
                src = new_path;
                db_conn.exec(core.parse_query("lib-notes.update-folder-name"
                                              , new Dictionary <string, object>()
                {
                    { "folder_id", r["folder_id"].ToString() }, { "folder_name", new_name }
                }));

                // title
                if (!string.IsNullOrEmpty(title))
                {
                    db_conn.exec(core.parse_query("lib-notes.set-task-title"
                                                  , new string[, ] {
                        { "title", title }, { "task_id", task_id.ToString() }
                    }));
                }
            }

            // stato
            if (stato != null)
            {
                it.stato = stato;
                db_conn.exec(core.parse_query("lib-notes.set-task-state"
                                              , new string[, ] {
                    { "stato", stato }, { "task_id", task_id.ToString() }
                }));
            }

            // assegna
            if (assegna != null)
            {
                it.user = assegna;
                db_conn.exec(core.parse_query("lib-notes.set-task-user"
                                              , new string[, ] {
                    { "user", assegna }, { "task_id", task_id.ToString() }
                }));
            }

            // priorita
            if (priorita != null)
            {
                it.priorita = priorita;
                db_conn.exec(core.parse_query("lib-notes.set-task-priorita"
                                              , new string[, ] {
                    { "priorita", priorita }, { "task_id", task_id.ToString() }
                }));
            }

            // stima
            if (stima != null)
            {
                it.stima = stima;
                db_conn.exec(core.parse_query("lib-notes.set-task-stima"
                                              , new string[, ] {
                    { "stima", stima }, { "task_id", task_id.ToString() }
                }));
            }

            // tipo
            if (tipo != null)
            {
                it.tipo = tipo;
                db_conn.exec(core.parse_query("lib-notes.set-task-tipo"
                                              , new string[, ] {
                    { "tipo", tipo }, { "task_id", task_id.ToString() }
                }));
            }

            // aggiorno l'indice
            if (it.changed)
            {
                it.dt_upd = dn_lib.tools.sys.without_ms(DateTime.Now);
                it.save_into_folder(core, src);
                db_conn.exec(core.parse_query("lib-notes.set-task-upd"
                                              , new string[, ] {
                    { "i_lwt", it.lwt.ToString("yyyy-MM-dd HH:mm:ss") }, { "dt_upd", it.dt_upd.Value.ToString("yyyy-MM-dd HH:mm:ss") }, { "task_id", task_id.ToString() }
                }));
            }
        }