Пример #1
0
        public bool ChangeContent(int id, string s)
        {
            bool num;

            try
            {
                work cr = db.works.Find(id);
                if (cr != null)
                {
                    if (s != null && !s.Equals(cr.context))
                    {
                        cr.context = s;
                    }
                    db.SaveChanges();
                    num = true;
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            return(num);
        }
Пример #2
0
        public void test_hooks()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                work w = new work();
                Assert.AreEqual(w.count_commits, 0);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 0);
                Assert.AreEqual(w.count_traces, 0);
                Assert.AreEqual(w.count_profiles, 0);

                db.commit_hook(my_commit_hook, w);
                db.rollback_hook(my_rollback_hook, w);
                db.update_hook(my_update_hook, w);
                db.trace(my_trace_hook, w);
                db.profile(my_profile_hook, w);

                GC.Collect();

                db.exec("CREATE TABLE foo (x int);");

                Assert.AreEqual(w.count_commits, 1);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 0);
                Assert.AreEqual(w.count_traces, 1);
                Assert.AreEqual(w.count_profiles, 1);

                db.exec("INSERT INTO foo (x) VALUES (1);");

                Assert.AreEqual(w.count_commits, 2);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 1);
                Assert.AreEqual(w.count_traces, 2);
                Assert.AreEqual(w.count_profiles, 2);

                db.exec("BEGIN TRANSACTION;");

                Assert.AreEqual(w.count_commits, 2);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 1);
                Assert.AreEqual(w.count_traces, 3);
                Assert.AreEqual(w.count_profiles, 3);

                db.exec("INSERT INTO foo (x) VALUES (2);");

                Assert.AreEqual(w.count_commits, 2);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 2);
                Assert.AreEqual(w.count_traces, 4);
                Assert.AreEqual(w.count_profiles, 4);

                db.exec("ROLLBACK TRANSACTION;");

                Assert.AreEqual(w.count_commits, 2);
                Assert.AreEqual(w.count_rollbacks, 1);
                Assert.AreEqual(w.count_updates, 2);
                Assert.AreEqual(w.count_traces, 5);
                Assert.AreEqual(w.count_profiles, 5);
            }
        }
Пример #3
0
        private void btn_sabt_Click(object sender, EventArgs e)
        {
            if (txt_subject.Text.Trim() == "" || txt_description.Text.Trim() == "" || txt_timeDone.Text.Trim() == "")
            {
                MessageBox.Show("Please fill in the required values.");
                return;
            }
            try
            {
                work W = new work();
                W.work_subject     = txt_subject.Text.Trim();
                W.work_description = txt_description.Text.Trim();
                W.userID           = PublicVariable.gUserId;
                W.timeDone         = Convert.ToInt32(txt_timeDone.Text.Trim());
                W.dateDone         = string.Format("{0:yyyy/MM/dd}", Convert.ToDateTime(persianDateTimePicker_done.Value.Year.ToString() + "/" + persianDateTimePicker_done.Value.Month.ToString() + "/" + persianDateTimePicker_done.Value.Day.ToString()));
                W.jobID            = Convert.ToInt32(cmb_request.SelectedValue);

                database.works.Add(W);
                database.SaveChanges();
                MessageBox.Show("Your information was successfully registered.");
                ClearForm();
            }
            catch
            {
                MessageBox.Show("There was a problem with the server. try again.");
            }
            ShowWorks(searchCondition());
        }
Пример #4
0
        private static void DoWork(string accs)
        {
            //await prelogin(acc);
            //Thread.Sleep(new Random().Next(0, 5000));
            //Console.WriteLine("retrieved {0}", acc);
            //Console.WriteLine(DateTime.Now.ToString("h:mm:ss tt"));
            var w = new work();

            try
            {
                //Console.WriteLine(accs);
                w.setAccount(accs);
                w.dowork(true);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
                Console.WriteLine("{0}", accs);
                //w.netClient.Disconnect();
            }
            finally
            {
                //w.netClient.Dispose();
                //w.Dispose();
            }
        }
Пример #5
0
        private static int my_commit_hook(object v)
        {
            work w = v as work;

            w.count_commits++;
            return(0);
        }
Пример #6
0
        public ActionResult DeleteConfirmed(int id)
        {
            work work = db.work.Find(id);

            db.work.Remove(work);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Пример #7
0
#pragma warning disable
        static Bool2Int()
        {
            DynamicMethod dm = new DynamicMethod("__SCLC__bool2int_il", CTypes.INT_T, new[] { CTypes.BOOL_T });

            ILGenerator il = dm.GetILGenerator();

            il.Emit(OpCodes.Ldarg_0);
            il.Emit(OpCodes.Ret);

            _func = (work)dm.CreateDelegate(typeof(work));
        }
Пример #8
0
 public ActionResult Edit([Bind(Include = "id,id_car,desc_work,value,id_protocol")] work work)
 {
     if (ModelState.IsValid)
     {
         db.Entry(work).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.id_car      = new SelectList(db.car, "id", "state_num", work.id_car);
     ViewBag.id_protocol = new SelectList(db.protocol, "id", "act_delivering", work.id_protocol);
     return(View(work));
 }
Пример #9
0
        static void Main(string[] args)
        {
            work objWork = new work("diary", "Constructor of base class", new TimeSpan(5, 20, 22));

            System.Console.WriteLine(objWork.ToString());

            ChangeRequest objChangeRequest = new ChangeRequest("story", "constuctor of the dervied class", new TimeSpan(3, 12, 45), 1);

            System.Console.WriteLine(objChangeRequest.ToString());

            objChangeRequest.Update("funnyBook", new TimeSpan(1, 3, 4));
            System.Console.WriteLine(objChangeRequest.ToString());
        }
Пример #10
0
        private static int my_cb(object v, string[] values, string[] names)
        {
            Assert.AreEqual(values.Length, 1);
            Assert.AreEqual(names.Length, 1);
            Assert.AreEqual(names[0], "x");
            Assert.AreEqual(values[0].Length, 1);

            work w = v as work;

            w.count++;

            return(0);
        }
Пример #11
0
        // GET: works/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            work work = db.work.Find(id);

            if (work == null)
            {
                return(HttpNotFound());
            }
            return(View(work));
        }
Пример #12
0
    public void User(work work, SqlDataReader reader)
    {
        ((Button)work.FindControl("name")).Text   = reader.GetString(2);
        ((Label)work.FindControl("time")).Text    = reader.GetString(3);
        ((Label)work.FindControl("where")).Text   = reader.GetString(4);
        ((Label)work.FindControl("renshu")).Text  = reader.GetInt32(6).ToString();
        ((Label)work.FindControl("gongzi1")).Text = reader.GetInt32(7).ToString();

        ((Label)work.FindControl("name1")).Text        = ((Button)work.FindControl("name")).Text;
        ((Label)work.FindControl("time1")).Text        = ((Label)work.FindControl("time")).Text;
        ((Label)work.FindControl("where1")).Text       = ((Label)work.FindControl("where")).Text;
        ((Label)work.FindControl("jieshao1")).Text     = reader.GetString(5);
        ((Label)work.FindControl("renshu1")).Text      = ((Label)work.FindControl("renshu")).Text;
        ((Label)work.FindControl("gongzidaiyu1")).Text = ((Label)work.FindControl("gongzi1")).Text;
    }
Пример #13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Label6.Text = Session["PrincipalName"].ToString();
        SqlDataReader reader = DAL.ManagerDAL.SelectJob(Session["account"].ToString());

        while (reader.Read())
        {
            if (reader.GetString(8).Trim() == "2")
            {
                work work = (work)LoadControl("work.ascx");
                work.User(work, reader);

                Panel3.Controls.Add(work);
            }
        }
    }
Пример #14
0
 public void test_exec_with_callback()
 {
     using (sqlite3 db = ugly.open(":memory:"))
     {
         db.exec("CREATE TABLE foo (x text);");
         db.exec("INSERT INTO foo (x) VALUES ('b')");
         db.exec("INSERT INTO foo (x) VALUES ('c')");
         db.exec("INSERT INTO foo (x) VALUES ('d')");
         db.exec("INSERT INTO foo (x) VALUES ('e')");
         db.exec("INSERT INTO foo (x) VALUES ('f')");
         string errmsg;
         work   w = new work();
         db.exec("SELECT x FROM foo", my_cb, w, out errmsg);
         Assert.AreEqual(w.count, 5);
     }
 }
Пример #15
0
        public bool DeleteOne(int id)
        {
            int num;

            try
            {
                work wk = db.works.Find(id);
                db.works.Remove(wk);
                num = db.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
            return(num > 0);
        }
Пример #16
0
        // GET: works/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            work work = db.work.Find(id);

            if (work == null)
            {
                return(HttpNotFound());
            }
            ViewBag.id_car      = new SelectList(db.car, "id", "state_num", work.id_car);
            ViewBag.id_protocol = new SelectList(db.protocol, "id", "act_delivering", work.id_protocol);
            return(View(work));
        }
Пример #17
0
        public ActionResult WorklistDeleteConfirm(int id)
        {
            if (Session["username"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (Session["uType"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            work work = Db.work.Find(id);

            Db.work.Remove(work);
            Db.SaveChanges();
            Session["ADMIN_WORKLIST_DELETE"] = "Admin Worklist Delete";
            return(RedirectToAction("Worklist"));
        }
Пример #18
0
 public ActionResult WorklistEdit([Bind(Include = "")] work work)
 {
     if (Session["username"] == null)
     {
         return(RedirectToAction("Index", "Home"));
     }
     if (Session["uType"] == null)
     {
         return(RedirectToAction("Index", "Home"));
     }
     if (ModelState.IsValid)
     {
         Db.Entry(work).State = EntityState.Modified;
         Db.SaveChanges();
     }
     return(RedirectToAction("Worklist"));
 }
Пример #19
0
 //tao user
 public ActionResult Create(work acc)
 {
     if (ModelState.IsValid)
     {
         var dao = new workDao();
         int id  = dao.Insert(acc);
         if (id > 0)
         {
             return(RedirectToAction("Index", "Work"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm user thành công");
         }
     }
     return(View("Index"));
 }
Пример #20
0
        //tao user
        public ActionResult Edit(work acc)
        {
            if (ModelState.IsValid)
            {
                var dao = new workDao();

                var result = dao.update(acc);
                if (result)
                {
                    return(RedirectToAction("Index", "Work"));
                }
                else
                {
                    ModelState.AddModelError("", "Cập nhập thành công");
                }
            }
            return(View("Index"));
        }
Пример #21
0
        public ActionResult WorklistCreate([Bind(Include = "")] work work)
        {
            if (Session["username"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (Session["uType"] == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            // TODO: Add insert logic here
            if (ModelState.IsValid)
            {
                Db.work.Add(work);
                Db.SaveChanges();
            }

            return(RedirectToAction("Worklist"));
        }
Пример #22
0
 //update
 public bool update(work ennity)
 {
     try
     {
         var user = db.works.Find(ennity.Id);
         user.Id           = ennity.Id;
         user.dateWork     = ennity.dateWork;
         user.dateOut      = ennity.dateOut;
         user.nameEmployee = ennity.nameEmployee;
         user.position     = ennity.position;
         user.department   = ennity.department;
         db.SaveChanges();
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Пример #23
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Labelid.Text             = Session["account"].ToString();
        Session["PrincipalName"] = DAL.ManagerDAL.SelectInfo(Labelid.Text, "SelectName");
        Label3.Text = DAL.ManagerDAL.SelectJobCount(Labelid.Text).ToString();
        Label6.Text = Session["PrincipalName"].ToString();
        SqlDataReader reader = DAL.ManagerDAL.SelectNewJob(Session["account"].ToString());

        if (reader.Read())
        {
            Label1.Text = "1";
            work work = (work)LoadControl("work.ascx");
            work.User(work, reader);
            Panelwork.Controls.Add(work);
        }
        else
        {
            Label1.Text = "0";
        }
    }
Пример #24
0
    // Medium https://leetcode.com/problems/most-profit-assigning-work/description/
    // 2018/5/1
    //
    public int MaxProfitAssignment(int[] difficulty, int[] profit, int[] worker)
    {
        int result = 0;

        work[] works = new work[difficulty.Length];

        for (int i = 0; i < difficulty.Length; i++)
        {
            work temp = new work();
            temp.difficulty = difficulty[i];
            temp.profit     = profit[i];
            works[i]        = temp;
        }

        Array.Sort(works, (a, b) => a.difficulty - b.difficulty);

        for (int i = 1; i < works.Length; i++)
        {
            works[i].profit = Math.Max(works[i].profit, works[i - 1].profit);
        }

        Array.Sort(worker);

        for (int i = 0; i < worker.Length; i++)
        {
            int j = 0;
            while (j < works.Length && works[j].difficulty <= worker[i])
            {
                j++;
            }
            j = j - 1 >= 0 ? j - 1 : j;
            if (worker[i] >= works[j].difficulty)
            {
                result += works[j].profit;
            }
        }


        return(result);
    }
Пример #25
0
        public ActionResult Edit(Work workToUpdate)
        {
            try
            {
                // TODO: Add update logic here
                work dalWork = (from w in dbContext.works
                                where w.work_id == workToUpdate.work_id
                                select w).FirstOrDefault();

                dalWork.title         = workToUpdate.title;
                dalWork.author_id     = workToUpdate.author_id;
                dalWork.edition       = workToUpdate.edition;
                dalWork.language_id   = workToUpdate.language_id;
                dalWork.translator_id = workToUpdate.translator_id;
                dalWork.metadata_id   = workToUpdate.metadata_id;
                dalWork.user_entry_Id = workToUpdate.user_entry_id;
                dbContext.SubmitChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Пример #26
0
            public void run(int port)
            {
                // Create and start a server and client.
                TcpListener server = null;
                TcpClient client = null;

                try
                {
                    server = new TcpListener(IPAddress.Any, port);
                    server.Start();
                    client = new TcpClient("localhost", port);

                    // Obtain the sockets from the two ends of the connection.  We are using the blocking AcceptSocket()
                    // method here, which is OK for a test case.
                    Socket serverSocket = server.AcceptSocket();
                    Socket clientSocket = client.Client;

                    // Wrap the two ends of the connection into StringSockets
                    StringSocket sendSocket = new StringSocket(serverSocket, new UTF8Encoding());
                    StringSocket receiveSocket = new StringSocket(clientSocket, new UTF8Encoding());

                    // This will coordinate communication between the threads of the test cases
                    mre1 = new ManualResetEvent(false);
                    mre2 = new ManualResetEvent(false);

                    // Make two receive requests
                    receiveSocket.BeginReceive(CompletedReceive1, 1);
                    receiveSocket.BeginReceive(CompletedReceive2, 2);

                    // Now send the data.  Hope those receive requests didn't block!
                    String msg1 = "The FIRST string\n";
                    work w = new work(sendSocket, msg1, 1);
                    ThreadStart threadDelegate = new ThreadStart(w.sendOnThread);
                    Thread Thread1 = new Thread(threadDelegate);

                    String msg2 = "The SECOND string\n";
                    work w2 = new work(sendSocket, msg2, 2);
                    ThreadStart threadDelegate2 = new ThreadStart(w2.sendOnThread);
                    Thread Thread2 = new Thread(threadDelegate2);

                    Thread1.Start();
                    Thread2.Start();

                    // Make sure the lines were received properly.
                    Assert.AreEqual(true, mre1.WaitOne(timeout), "Timed out waiting 1");
                    Assert.AreEqual("The FIRST string", s1);
                    Assert.AreEqual(1, p1);

                    Assert.AreEqual(true, mre2.WaitOne(timeout), "Timed out waiting 2");
                    Assert.AreEqual("The SECOND string", s2);
                    Assert.AreEqual(2, p2);
                }
                finally
                {
                    server.Stop();
                    client.Close();
                }
            }
Пример #27
0
        public void test_rollback_hook_on_close_db()
	{
            using (sqlite3 db = ugly.open(":memory:"))
            {
                work w = new work();

                db.rollback_hook(my_rollback_hook, w);

		GC.Collect();

                db.exec("BEGIN TRANSACTION;");
                db.exec("CREATE TABLE foo (x int);");
            }
        }
Пример #28
0
        private static void my_trace_hook(object v, string sql)
        {
            work w = v as work;

            w.count_traces++;
        }
Пример #29
0
        private static void my_profile_hook(object v, string sql, long ns)
        {
            work w = v as work;

            w.count_profiles++;
        }
Пример #30
0
        private static void my_update_hook(object v, int typ, string db, string tbl, long rowid)
        {
            work w = v as work;

            w.count_updates++;
        }
Пример #31
0
        private static void my_rollback_hook(object v)
        {
            work w = v as work;

            w.count_rollbacks++;
        }
Пример #32
0
        public void test_hooks()
        {
            using (sqlite3 db = ugly.open(":memory:"))
            {
                work w = new work();
                Assert.AreEqual(w.count_commits, 0);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 0);
                Assert.AreEqual(w.count_traces, 0);
                Assert.AreEqual(w.count_profiles, 0);

                db.commit_hook(my_commit_hook, w);
                db.rollback_hook(my_rollback_hook, w);
                db.update_hook(my_update_hook, w);
                db.trace(my_trace_hook, w);
                db.profile(my_profile_hook, w);

                db.exec("CREATE TABLE foo (x int);");

                Assert.AreEqual(w.count_commits, 1);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 0);
                Assert.AreEqual(w.count_traces, 1);
                Assert.AreEqual(w.count_profiles, 1);

                db.exec("INSERT INTO foo (x) VALUES (1);");

                Assert.AreEqual(w.count_commits, 2);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 1);
                Assert.AreEqual(w.count_traces, 2);
                Assert.AreEqual(w.count_profiles, 2);

                db.exec("BEGIN TRANSACTION;");

                Assert.AreEqual(w.count_commits, 2);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 1);
                Assert.AreEqual(w.count_traces, 3);
                Assert.AreEqual(w.count_profiles, 3);

                db.exec("INSERT INTO foo (x) VALUES (2);");

                Assert.AreEqual(w.count_commits, 2);
                Assert.AreEqual(w.count_rollbacks, 0);
                Assert.AreEqual(w.count_updates, 2);
                Assert.AreEqual(w.count_traces, 4);
                Assert.AreEqual(w.count_profiles, 4);

                db.exec("ROLLBACK TRANSACTION;");

                Assert.AreEqual(w.count_commits, 2);
                Assert.AreEqual(w.count_rollbacks, 1);
                Assert.AreEqual(w.count_updates, 2);
                Assert.AreEqual(w.count_traces, 5);
                Assert.AreEqual(w.count_profiles, 5);

            }
        }
Пример #33
0
 public void test_exec_with_callback()
 {
     using (sqlite3 db = ugly.open(":memory:"))
     {
         db.exec("CREATE TABLE foo (x text);");
         db.exec("INSERT INTO foo (x) VALUES ('b')");
         db.exec("INSERT INTO foo (x) VALUES ('c')");
         db.exec("INSERT INTO foo (x) VALUES ('d')");
         db.exec("INSERT INTO foo (x) VALUES ('e')");
         db.exec("INSERT INTO foo (x) VALUES ('f')");
         string errmsg;
         work w = new work();
         db.exec("SELECT x FROM foo", my_cb, w, out errmsg);
         Assert.AreEqual(w.count, 5);
     }
 }
Пример #34
0
 //insert
 public int Insert(work entity)
 {
     db.works.Add(entity);
     db.SaveChanges();
     return(entity.Id);
 }