Exemplo n.º 1
0
 public ActionResult Edit()
 {
     Validator _val = new Validator();
     string customer_id = Common.doPost("customer_id");
     string id = Common.doPost("id");
     string content = Common.doPost("content");
     string oper = Common.doPost("oper");
     string sql;
     if (oper != "del")
     {
         if (oper == "edit")
         {
             _val.val(id, new String[] { "req", "int" });
         }
         _val.val(content, "req");
         if (_val.val(customer_id, new String[] { "req", "int" }))
         {
             int cid = Convert.ToInt32(customer_id);
             int customers_exist = (from c in this._db.recsys_customers
                                    where c.id == cid
                                    select c).Count();
             if (customers_exist == 0)
             {
                 _val.setValStatus(false);
             }
         }
         if (_val.getValStatus())
         {
             Member _member = new Member("users");
             Hashtable data = new Hashtable() {
                 { "content", content },
                 { "last_update", DateTime.Now.ToString("s") },
                 { "update_user_id", _member.infoBySession("id") }
             };
             if (oper == "edit")
             {
                 sql = Common.doUpdate(data, "log", "id = '" + id + "'");
             }
             else
             {
                 data["customer_id"] = customer_id;
                 data["create_date"] = DateTime.Now.ToString("s");
                 sql = Common.doInsert(data, "log");
             }
         }
         else
         {
             return Content(Common.json_encode(false));
         }
     }
     else
     {
         sql = Common.doDelete("log", "id = '" + id + "'");
     }
     this._db.ExecuteStoreCommand(sql);
     return Content(Common.json_encode(true));
 }
Exemplo n.º 2
0
        public ActionResult Edit()
        {
            Validator _val = new Validator();
            string id = Common.doPost("id");
            string name = Common.doPost("name");
            string status = Common.doPost("status2");
            string oper = Common.doPost("oper");
            string sql;
            if(oper != "del")
            {
                if(oper == "edit")
                {
                    _val.val(id, new String[] { "req", "int" });
                }
                _val.val(name, "req");
                _val.val(status, new String[] { "req", "int", "get=0", "let=1" });
                if(_val.getValStatus())
                {
                    Member _member = new Member("users");
                    Hashtable data = new Hashtable() {
                        { "name", name },
                        { "status", status },
                        { "last_update", DateTime.Now.ToString("s") },
                        { "update_user_id", _member.infoBySession("id") }
                    };
                    if(oper == "edit")
                    {
                        sql = Common.doUpdate(data, "supplier", "id = '" + id + "'");
                    }
                    else
                    {
                        sql = Common.doInsert(data, "supplier");
                    }

                }
                else
                {
                    return Content(Common.json_encode(false));
                }
            }
            else
            {
                sql = Common.doDelete("supplier", "id = '" + id + "'");
            }
            this._db.ExecuteStoreCommand(sql);
            return Content(Common.json_encode(true));
        }
Exemplo n.º 3
0
        public ActionResult Edit()
        {
            Validator _val = new Validator();
            string id = Common.doPost("id");
            string title = Common.doPost("title");
            string date = Common.doPost("date");
            string status = Common.doPost("status2");
            string oper = Common.doPost("oper");
            string sql;
            if(oper != "del")
            {
                if(oper == "edit")
                {
                    _val.val(id, new String[] { "req", "int" });
                }
                _val.val(date, "req");
                _val.val(status, new String[] { "req", "int", "get=0", "let=1" });
                if(_val.getValStatus())
                {
                    Member _member = new Member("holiday");
                    Hashtable data = new Hashtable() {
                        { "title", title },
                        { "date", date },
                        { "status", status }
                    };
                    if(oper == "edit")
                    {
                        sql = Common.doUpdate(data, "holiday", "id = '" + id + "'");
                    }
                    else
                    {
                        sql = Common.doInsert(data, "holiday");
                    }

                }
                else
                {
                    return Content(Common.json_encode(false));
                }
            }
            else
            {
                sql = Common.doDelete("holiday", "id = '" + id + "'");
            }
            this._db.ExecuteStoreCommand(sql);
            return Content(Common.json_encode(true));
        }
Exemplo n.º 4
0
        public ActionResult Edit()
        {
            Validator _val = new Validator();
            string id = Common.doPost("id");
            string name = Common.doPost("name");
            string type_id = Common.doPost("type_id2");
            string user_group = Common.doPost("user_group");
            string center = Common.doPost("center");
            string grade = Common.doPost("grade2");
            string employee_number = Common.doPost("employee_number");
            string username = Common.doPost("username");
            string oldpassword = Common.doPost("oldpassword");
            string password = Common.doPost("password");
            string password2 = Common.doPost("password2");
            string country_id = Common.doPost("country_id2");
            string phone_number = Common.doPost("phone_number");
            string email = Common.doPost("email");
            string status = Common.doPost("status2");
            string oper = Common.doPost("oper");
            string encryptedOldPassword = "";
            string encryptedOldPasswordDB = "";
            Member _member = new Member("users");
            if(oper != "del")
            {
                if(oper == "edit")
                {
                    _val.val(id, new String[] { "req", "int" });

                    if (!String.IsNullOrWhiteSpace(password) || !String.IsNullOrWhiteSpace(password2))
                    {
                        int userID =  Convert.ToInt32(id);
                        encryptedOldPasswordDB = (from u in this._db.recsys_users
                                                  where u.id == userID
                                                  select u.password).FirstOrDefault();
                        string salt = encryptedOldPasswordDB.Substring(0, 20);
                        encryptedOldPassword = _member.encrypt(oldpassword, salt);
                        if (!encryptedOldPassword.Equals(encryptedOldPasswordDB))
                            return Content("oldPasswordNotMatch");
                    }
                }
                _val.val(name, "req");
                _val.val(type_id, new String[] { "req", "int" });
                _val.val(user_group, new String[] { "req", "int", "get=0" });
                _val.val(center, new String[] { "req", "int" });
                _val.val(country_id, new String[] { "req", "int" });
                if (!string.IsNullOrWhiteSpace(phone_number)) _val.val(phone_number, "int");
                if (email != null)
                {
                    _val.val(email, "email");
                }
                _val.val(status, new String[] { "req", "int", "get=0", "let=1" });
                int t_id = Convert.ToInt32(type_id);
                Byte type = (from t in this._db.recsys_type
                             where t.status == 1 && t.id == t_id
                             select t.type).FirstOrDefault();
                if (!String.IsNullOrWhiteSpace(username))
                {
                    if (_member.isExist(username, "username", oper != "edit" ? "" : "id != '" + id + "'"))
                    {
                        _val.setValStatus(false);
                    }
                }
                if (!String.IsNullOrWhiteSpace(password) || !String.IsNullOrWhiteSpace(password2))
                {
                    _val.val(password, "req");
                    _val.val(password2, new String[] { "req", "equal=" + password });
                }
                if (type == null || !this._ctr.Contains(center))
                {
                    _val.setValStatus(false);
                }
                if (this.isDuplicatePhoneNumber(phone_number, id, country_id))
                {
                    _val.setValStatus(false);
                }
                if(_val.getValStatus())
                {
                    grade = string.IsNullOrEmpty(grade) ? null : grade;
                    Hashtable data = new Hashtable() {
                        { "name", name },
                        { "type_id", type_id },
                        { "type", type },
                        { "user_group", user_group },
                        { "center", center },
                        { "username", username },
                        { "email", email },
                        { "status", status },
                        { "last_update", DateTime.Now.ToString("s") },
                        { "update_user_id", _member.infoBySession("id") },
                        { "employee_number", employee_number},
                        { "country_id", country_id },
                        { "phone_number", phone_number },
                        { "grade", grade }
                    };
                    if(! String.IsNullOrWhiteSpace(password)) {
                        data["password"] = password;
                    }
                    if(oper == "edit")
                    {
                        _member.update(data, id, "id");
                    }
                    else
                    {
                        _member.insert(data);
                        id = (from m in this._db.recsys_users
                              orderby m.id descending
                              select m.id).FirstOrDefault().ToString();
                    }
                }
                else
                {
                    return Content("false");
                }
            }
            else
            {
                this._db.ExecuteStoreCommand(Common.doDelete("relate", "id2 = '" + id + "' AND table1 = 'group' AND table2 = 'users'"));
                _member.delete(Convert.ToInt32(id));
                Common.delDir("Upload/users/" + id + "/");
            }
            return Content(id);
        }
        public ActionResult Edit_Items_Template()
        {
            Validator _val = new Validator();
            string id = Common.doPost("id");
            string code = Common.doPost("code");
            string detail = Common.doPost("detail");
            string detail2 = Common.doPost("detail2");
            string price = Common.doPost("price");
            string oper = Common.doPost("oper");
            string sql;
            if (oper != "del")
            {
                if (oper == "edit")
                {
                    _val.val(id, new String[] { "req", "int" });
                }
                _val.val(code, "req");
                if (_val.getValStatus())
                {
                    Member _member = new Member("users");
                    Hashtable data = new Hashtable() {
                        { "code", code },
                        { "detail", detail },
                        { "detail2", detail2 },
                        { "price", price },
                        { "last_update", DateTime.Now.ToString("s") },
                        { "update_user_id", _member.infoBySession("id") }
                    };
                    if (oper == "edit")
                    {
                        sql = Common.doUpdate(data, "quotation_items_template", "id = '" + id + "'");
                    }
                    else
                    {
                        sql = Common.doInsert(data, "quotation_items_template");
                    }

                }
                else
                {
                    return Content(Common.json_encode(false));
                }
            }
            else
            {
                sql = Common.doDelete("quotation_items_template", "id = '" + id + "'");
            }
            this._db.ExecuteStoreCommand(sql);
            return Content(Common.json_encode(true));
        }
Exemplo n.º 6
0
        public ActionResult Edit_Jobs()
        {
            Validator _val = new Validator();
            string order_id = Common.doPost("order_id");
            string id = Common.doPost("id");
            string detail1 = Common.doPost("detail1");
            string detail2 = Common.doPost("detail2");
            string oper = Common.doPost("oper");
            string sql;
            if (oper != "del")
            {
                if (oper == "edit")
                {
                    _val.val(id, new String[] { "req", "int" });
                }
                else
                {
                    int order = Convert.ToInt32(order_id);
                    int order_exist = (from o in this._db.recsys_order
                                       where o.id == order
                                       select o).Count();
                    if (order_exist == 0)
                    {
                        _val.setValStatus(false);
                    }
                    _val.val(order_id, new String[] { "req", "int" });
                }
                _val.val(detail1, "req");
                _val.val(detail2, "req");
                if (_val.getValStatus())
                {
                    Member _member = new Member("users");
                    Hashtable data = new Hashtable() {
                        { "detail1", detail1 },
                        { "detail2", detail2 },
                        { "last_update", DateTime.Now.ToString("s") },
                        { "update_user_id", _member.infoBySession("id") }
                    };
                    if (oper == "edit")
                    {
                        sql = Common.doUpdate(data, "job", "id = '" + id + "'");
                    }
                    else
                    {
                        sql = Common.doInsert(data, "job");
                        this._db.ExecuteStoreCommand(sql);
                        id = (from j in this._db.recsys_job
                              orderby j.id descending
                              select j.id).FirstOrDefault().ToString();
                        data = new Hashtable()
                        {
                            { "id1", order_id },
                            { "id2", id },
                            { "table1", "order" },
                            { "table2", "job" }
                        };
                        sql = Common.doInsert(data, "relate");
                    }

                }
                else
                {
                    return Content(Common.json_encode(false));
                }
            }
            else
            {
                sql = Common.doDelete("relate", "id2 = '" + id + "' AND table2 = 'job'");
                this._db.ExecuteStoreCommand(sql);
                sql = Common.doDelete("job", "id = '" + id + "'");
            }
            this._db.ExecuteStoreCommand(sql);
            return Content(Common.json_encode(true));
        }
Exemplo n.º 7
0
 public ActionResult Edit_Extra_Cost()
 {
     Validator _val = new Validator();
     string order_id = Common.doPost("order_id");
     string id = Common.doPost("id");
     string name = Common.doPost("name");
     string price = Common.doPost("price");
     string remark = Common.doPost("remark");
     string oper = Common.doPost("oper");
     string sql;
     if (oper != "del")
     {
         if (oper == "edit")
         {
             _val.val(id, new String[] { "req", "int" });
         }
         else
         {
             int order = Convert.ToInt32(order_id);
             int order_exist = (from o in this._db.recsys_order
                                where o.id == order
                                select o).Count();
             if (order_exist == 0)
             {
                 _val.setValStatus(false);
             }
             _val.val(order_id, new String[] { "req", "int" });
         }
         _val.val(name, "req");
         _val.val(price, new String[] { "req", "numdec" });
         if (_val.getValStatus())
         {
             Member _member = new Member("users");
             Hashtable data = new Hashtable() {
                 { "name", name },
                 { "price", price },
                 { "remark", remark },
                 { "last_update", DateTime.Now.ToString("s") },
                 { "update_user_id", _member.infoBySession("id") }
             };
             if (oper == "edit")
             {
                 sql = Common.doUpdate(data, "extra_cost", "id = '" + id + "'");
             }
             else
             {
                 data["create_date"] = DateTime.Now.ToString("s");
                 sql = Common.doInsert(data, "extra_cost");
                 this._db.ExecuteStoreCommand(sql);
                 id = (from ec in this._db.recsys_extra_cost
                       orderby ec.id descending
                       select ec.id).FirstOrDefault().ToString();
                 data = new Hashtable()
                 {
                     { "id1", order_id },
                     { "id2", id },
                     { "table1", "order" },
                     { "table2", "extra_cost" }
                 };
                 sql = Common.doInsert(data, "relate");
             }
         }
         else
         {
             return Content(Common.json_encode(false));
         }
     }
     else
     {
         sql = Common.doDelete("relate", "id2 = '" + id + "' AND table2 = 'extra_cost'");
         this._db.ExecuteStoreCommand(sql);
         sql = Common.doDelete("extra_cost", "id = '" + id + "'");
     }
     this._db.ExecuteStoreCommand(sql);
     return Content(Common.json_encode(true));
 }
Exemplo n.º 8
0
 public ActionResult Edit2(string id)
 {
     Validator _val = new Validator();
     string engineer_id_1 = Common.doPost("engineer_id_1");
     string engineer_id_2 = Common.doPost("engineer_id_2");
     Member _member = new Member("users");
     Hashtable data = new Hashtable() {
         { "engineer_id_1", engineer_id_1 },
         { "engineer_id_2", engineer_id_2 },
         { "last_update", DateTime.Now.ToString("s") },
         { "update_user_id", _member.infoBySession("id") },
     };
     string sql = Common.doUpdate(data, "order", "id = '" + id + "'");
     this._db.ExecuteStoreCommand(sql);
     return Content(Common.json_encode(true));
 }
Exemplo n.º 9
0
        public ActionResult Edit(string id,
            DateTime? completion_date,
            int? enquery_id,
            TimeSpan? end_time,
            int? engineer_id_1,
            int? engineer_id_2,
            string fault,
            string model,
            string remark2,
            string repair,
            DateTime? repair_date,
            string report,
            string reviewer,
            TimeSpan? start_time,
            byte? status,
            byte? tc,
            int? relate_id,
            string relate_table)
        {
            Validator _val = new Validator();
            string customer_code = Common.doPost("customer_code");
            string mode = Common.doGet("mode");
            string type = Common.doPost("type");
            string prefix = Common.doPost("prefix");
            string code = Common.doPost("code");
            string name = Common.doPost("name");
            string address1 = Common.doPost("address1");
            string address2 = Common.doPost("address2");
            string district1 = Common.doPost("district1");
            string district2 = Common.doPost("district2");
            string title = Common.doPost("title");
            string contact = Common.doPost("contact");
            string tel1 = Common.doPost("tel1");
            string tel2 = Common.doPost("tel2");
            string fax1 = Common.doPost("fax1");
            string fax2 = Common.doPost("fax2");
            string email = Common.doPost("email");
            string remark = Common.doPost("remark");
            //string model = Common.doPost("model");
            //string fault = Common.doPost("fault");
            //string repair = Common.doPost("repair");
            //dynamic tc = Common.doPost("tc");
            //string report = Common.doPost("report");
            //string repair_date = Common.doPost("repair_date");
            //string start_time = Common.doPost("start_time");
            //string end_time = Common.doPost("end_time");
            //string remark2 = Common.doPost("remark2");
            //string status = Common.doPost("status");
            string group_id = Common.doPost("group_id");
            string last_update = Common.doPost("last_update");
            string oper = Common.doPost("oper");
            //string relate_id = Common.doPost("relate_id");
            //string relate_table = Common.doPost("relate_table");

            string sql;
            if(oper != "del")
            {
                if (oper == "edit")
                {
                    if (_val.val(id, new String[] { "req", "int" }))
                    {
                        int order_id = Convert.ToInt32(id);
                        string time = ((from o in this._db.recsys_order
                                        where o.id == order_id
                                        select o.last_update).FirstOrDefault()).ToString();
                        if (! _val.val(last_update, "equal=" + time))
                        {
                            return Content(Common.alert("資料已被其他使用者更新"));
                        }
                    }
                }
                else
                {
                    if (type == "3")
                    {
                        _val.val(code, new String[] { "req", "int", "minlen=8", "maxlen=8" });
                    }
                    _val.val(type, new String[] { "req", "int", "get=1", "let=3" });
                }
                //_val.val(status, new String[] { "req", "int", "get=0", "let=1" });
                _val.val(status.ToString(), new String[] { "req", "int", "get=0", "let=1" });
                if(_val.getValStatus())
                {
                    Member _member = new Member("users");
                    Hashtable data = new Hashtable() {
                        { "type", type },
                        { "prefix", prefix },
                        { "code", code },
                        { "group_id", group_id },
                        { "name", name },
                        { "address1", address1 },
                        { "address2", address2 },
                        { "district1", district1 },
                        { "district2", district2 },
                        { "title", title },
                        { "contact", contact },
                        { "tel1", tel1 },
                        { "tel2", tel2 },
                        { "fax1", fax1 },
                        { "fax2", fax2 },
                        { "email", email },
                        { "remark", remark }
                    };
                    int count = (from c in this._db.recsys_customers
                                 where c.customer_code == customer_code
                                 select c.id).Count();
                    if (count == 0)
                    {
                        data["status"] = 1;
                        data["last_update"] = DateTime.Now.ToString("s");
                        data["update_user_id"] = _member.infoBySession("id");
                        data["create_date"] = DateTime.Now.ToString("s");
                        sql = Common.doInsert(data, "customers");
                        this._db.ExecuteStoreCommand(sql);
                        int cid = (from c in this._db.recsys_customers
                                   orderby c.id descending
                                   select c.id).FirstOrDefault();
                        Hashtable data2 = new Hashtable();
                        if (type != "3")
                        {
                            data2["auto_id"] = Convert.ToInt32((from c in this._db.recsys_customers
                                                               where c.type != 3 && c.auto_id != 0
                                                               orderby c.id descending
                                                               select c.auto_id).FirstOrDefault()) + 1;
                            code = data2["auto_id"].ToString().PadLeft(8, '0');
                        }
                        customer_code = this._type[type] + prefix + code;
                        data2["customer_code"] = customer_code;
                        sql = Common.doUpdate(data2, "customers", "id = '" + cid + "'");
                        this._db.ExecuteStoreCommand(sql);
                        data.Remove("status");
                        data.Remove("last_update");
                        data.Remove("update_user_id");
                        data.Remove("create_date");
                    }
                    int customer_id;
                    data["customer_code"] = customer_code;
                    customer_id = (from c in this._db.recsys_customers
                                   where c.customer_code == customer_code
                                   select c.id).FirstOrDefault();
                    data["customer_id"] = customer_id;
                    if (oper == "edit")
                    {
                        int order_id = Convert.ToInt32(id);
                        customer_id = (from o in this._db.recsys_order
                                       where o.id == order_id
                                       select o.customer_id).FirstOrDefault();
                        sql = Common.doUpdate(data, "relate_customers", "id = '" + customer_id + "'");
                        this._db.ExecuteStoreCommand(sql);
                    }
                    else
                    {
                        data["relate_type"] = 4;
                        sql = Common.doInsert(data, "relate_customers");
                        this._db.ExecuteStoreCommand(sql);
                        customer_id = (from c in this._db.recsys_relate_customers
                                       orderby c.id descending
                                       select c.id).FirstOrDefault();
                    }
                    recsys_order newOrder = new recsys_order()
                    {
                        by_system = 0,
                        completion_date = null,
                        create_date = DateTime.Now,
                        customer_id = customer_id,
                        enquery_id = enquery_id,
                        end_time = end_time,
                        engineer_id_1 = engineer_id_1,
                        engineer_id_2 = engineer_id_2,
                        fault = fault,
                        last_update = DateTime.Now,
                        model = model,
                        remark = remark2,
                        repair = repair,
                        repair_date = repair_date,
                        report = report,
                        reviewer = reviewer,
                        start_time = start_time,
                        status = status ?? 1,
                        tc = tc,
                        update_user_id = (int) _member.infoBySession("id")
                    };

                    if(oper == "edit")
                    {
                        ////
                        //sql = Common.doUpdate(data3, "order", "id = '" + id + "'");
                        this._db.ExecuteStoreCommand(sql);
                    }
                    else
                    {

                        try
                        {
                            this._db.recsys_order.AddObject(newOrder);

                            this._db.SaveChanges();

                            this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, newOrder);

                            if (newOrder.id > 0 && relate_id > 0)
                            {
                                id = newOrder.id.ToString();        //# temp solution

                                recsys_relate newRelation = new recsys_relate()
                                {
                                    id1 = relate_id.Value,
                                    id2 = newOrder.id,
                                    table1 = relate_table,
                                    table2 = "order"
                                };

                                this._db.recsys_relate.AddObject(newRelation);

                                this._db.SaveChanges();

                                this._db.Refresh(System.Data.Objects.RefreshMode.StoreWins, newRelation);

                            }

                            //data3["customer_id"] = customer_id;
                            //data3["create_date"] = DateTime.Now.ToString("s");
                            //sql = Common.doInsert(data3, "order");
                            //this._db.ExecuteStoreCommand(sql);
                            //id = (from o in this._db.recsys_order
                            //      orderby o.id descending
                            //      select o.id).FirstOrDefault().ToString();
                            //if (!String.IsNullOrWhiteSpace(relate_id))
                            //{
                            //    Hashtable data4 = new Hashtable()
                            //{
                            //    { "id1", relate_id },
                            //    { "id2", id },
                            //    { "table1", relate_table },
                            //    { "table2", "order" }
                            //};
                            //    sql = Common.doInsert(data4, "relate");
                            //    this._db.ExecuteStoreCommand(sql);
                            //}

                        }
                        catch(OptimisticConcurrencyException)
                        {
                            //# log down
                        }

                    }
                    return RedirectToAction("edit", new { id = id, mode = mode, customer_id = customer_id, relate_id = relate_id, relate_table = relate_table });
                }
                else
                {
                    return Content(Common.alert("輸入錯誤"));
                }
            }
            else
            {
                int order_id = Convert.ToInt32(id);
                int customer_id = (from o in this._db.recsys_order
                                   where o.id == order_id
                                   select o.customer_id).FirstOrDefault();
                sql = Common.doDelete("relate_customers", "id = '" + customer_id + "'");
                this._db.ExecuteStoreCommand(sql);
                int[] parts_id = (from r in this._db.recsys_relate
                                  where r.id2 == order_id && r.table1 == "parts" && r.table2 == "order"
                                  select r.id1).ToArray();
                if (parts_id.Length > 0)
                {
                    sql = Common.doDelete("parts", "id IN ('" + String.Join("','", parts_id) + "')");
                    this._db.ExecuteStoreCommand(sql);
                }
                int[] job_id = (from r in this._db.recsys_relate
                                where r.id1 == order_id && r.table1 == "order" && r.table2 == "job"
                                select r.id2).ToArray();
                if (job_id.Length > 0)
                {
                    sql = Common.doDelete("job", "id IN ('" + String.Join("','", job_id) + "')");
                    this._db.ExecuteStoreCommand(sql);
                }
                int[] extra_cost_id = (from r in this._db.recsys_relate
                                       where r.id1 == order_id && r.table1 == "order" && r.table2 == "extra_cost"
                                       select r.id2).ToArray();
                if (extra_cost_id.Length > 0)
                {
                    sql = Common.doDelete("extra_cost", "id IN ('" + String.Join("','", extra_cost_id) + "')");
                    this._db.ExecuteStoreCommand(sql);
                }
                sql = Common.doDelete("relate", "(id1 = '" + id + "' AND table1 = 'order') OR (id2 = '" + id + "' AND table2 = 'order')");
                this._db.ExecuteStoreCommand(sql);
                sql = Common.doDelete("order_report", "order_id = '" + id + "'");
                this._db.ExecuteStoreCommand(sql);
                sql = Common.doDelete("order", "id = '" + id + "'");
                this._db.ExecuteStoreCommand(sql);
                return Content(Common.json_encode(true));
            }
        }
Exemplo n.º 10
0
 public ActionResult report(string id)
 {
     Validator _val = new Validator();
     dynamic checklist = Common.doPost("checklist");
     string model = Common.doPost("model");
     string fault = Common.doPost("fault");
     string repair = Common.doPost("repair");
     string report = Common.doPost("report");
     string repair_date = Common.doPost("repair_date");
     string start_time = Common.doPost("start_time");
     string end_time = Common.doPost("end_time");
     string remark = Common.doPost("remark");
     string oper = Common.doPost("oper");
     string sql;
     if (oper == "edit")
     {
         _val.val(id, new String[] { "req", "int" });
     }
     if (_val.getValStatus())
     {
         Member _member = new Member("users");
         Hashtable data = new Hashtable() {
                 { "checklist", checklist != null && checklist.GetType() == typeof(ArrayList) ? String.Join(",", checklist.ToArray()) : checklist },
                 { "remark", remark },
                 { "last_update", DateTime.Now.ToString("s") },
                 { "update_user_id", _member.infoBySession("id") }
             };
         if (oper == "edit")
         {
             sql = Common.doUpdate(data, "order_report", "order_id = '" + id + "'");
         }
         else
         {
             data["order_id"] = id;
             sql = Common.doInsert(data, "order_report");
         }
         data = new Hashtable() {
             { "model", model },
             { "fault", fault },
             { "repair", repair },
             { "report", report },
             { "repair_date", repair_date },
             { "start_time", start_time },
             { "end_time", end_time },
             { "last_update", DateTime.Now.ToString("s") },
             { "update_user_id", _member.infoBySession("id") },
         };
         sql = Common.doUpdate(data, "order", "id = '" + id + "'");
         this._db.ExecuteStoreCommand(sql);
     }
     else
     {
         return Content(Common.alert("輸入錯誤"));
     }
     this._db.ExecuteStoreCommand(sql);
     return RedirectToAction("report", new { id = id });
 }
Exemplo n.º 11
0
 public ActionResult Parts_Edit()
 {
     Validator _val = new Validator();
     string id = Common.doPost("id");
     string order_id = Common.doPost("order_id");
     string supplier_id = Common.doPost("supplier_id");
     string name = Common.doPost("name");
     string invoice = Common.doPost("invoice");
     string price1 = Common.doPost("price1");
     string price2 = Common.doPost("price2");
     string detail = Common.doPost("detail");
     string account_date = Common.doPost("account_date2");
     string remark = Common.doPost("remark");
     string status = Common.doPost("status2");
     string oper = Common.doPost("oper");
     string sql;
     if(oper != "del")
     {
         if(oper == "edit")
         {
             _val.val(id, new String[] { "req", "int" });
         }
         _val.val(order_id, new String[] { "req", "int" });
         _val.val(name, "req");
         _val.val(status, new String[] { "req", "int", "get=0", "let=1" });
         if(_val.getValStatus())
         {
             Member _member = new Member("users");
             Hashtable data = new Hashtable() {
                 { "supplier_id", supplier_id },
                 { "name", name },
                 { "invoice", invoice },
                 { "price1", price1 },
                 { "price2", price2 },
                 { "detail", detail },
                 { "account_date", account_date },
                 { "remark", remark },
                 { "status", status },
                 { "last_update", DateTime.Now.ToString("s") },
                 { "update_user_id", _member.infoBySession("id") }
             };
             if(oper == "edit")
             {
                 sql = Common.doUpdate(data, "parts", "id = '" + id + "'");
             }
             else
             {
                 sql = Common.doInsert(data, "parts");
                 this._db.ExecuteStoreCommand(sql);
                 id = (from p in this._db.recsys_parts
                       orderby p.id descending
                       select p.id).FirstOrDefault().ToString();
                 data = new Hashtable()
                 {
                     { "id1", id },
                     { "id2", order_id },
                     { "table1", "parts" },
                     { "table2", "order" }
                 };
                 sql = Common.doInsert(data, "relate");
             }
         }
         else
         {
             return Content(Common.json_encode(false));
         }
     }
     else
     {
         sql = Common.doDelete("relate", "id1 = '" + id + "' AND table1 = 'parts'");
         this._db.ExecuteStoreCommand(sql);
         sql = Common.doDelete("parts", "id = '" + id + "'");
     }
     this._db.ExecuteStoreCommand(sql);
     return Content(Common.json_encode(true));
 }
Exemplo n.º 12
0
 public ActionResult Edit()
 {
     Validator _val = new Validator();
     string id = Common.doPost("id");
     string relate_id = Common.doPost("relate_id");
     string table_name = Common.doPost("table_name");
     string user_id = Common.doPost("user_id");
     string supplier_id = Common.doPost("supplier_id");
     string center = Common.doPost("center");
     string cost_id = Common.doPost("cost_id");
     string invoice = Common.doPost("invoice");
     string price1 = Common.doPost("price1");
     string price2 = Common.doPost("price2");
     string account_date = Common.doPost("account_date2");
     string remark = Common.doPost("remark");
     string status = Common.doPost("status2");
     string oper = Common.doPost("oper");
     string sql;
     if(oper != "del")
     {
         if(oper == "edit")
         {
             _val.val(id, new String[] { "req", "int" });
         }
         _val.val(relate_id, new String[] { "req", "int" });
         _val.val(table_name, "req");
         _val.val(status, new String[] { "req", "int", "get=0", "let=1" });
         _val.val(cost_id, new String[] { "req", "int" });
         if (user_id != "0")
         {
             _val.val(user_id, new String[] { "req", "int" });
             int user = Convert.ToInt32(user_id);
             int user_exist = (from u in this._db.recsys_users
                               where u.status == 1 && u.id == user && u.type == 4
                               select u).Count();
             if (user_exist == 0)
             {
                 _val.setValStatus(false);
             }
         }
         else
         {
             _val.val(supplier_id, new String[] { "req", "int" });
             int supplier = Convert.ToInt32(supplier_id);
             int supplier_exist = (from s in this._db.recsys_supplier
                                   where s.status == 1 && s.id == supplier
                                   select s).Count();
             if (supplier_exist == 0)
             {
                 _val.setValStatus(false);
             }
         }
         if(_val.getValStatus())
         {
             Member _member = new Member("users");
             Hashtable data = new Hashtable() {
                 { "user_id", user_id },
                 { "supplier_id", supplier_id },
                 { "cost_id", cost_id },
                 { "center", center },
                 { "invoice", invoice },
                 { "price1", price1 },
                 { "price2", price2 },
                 { "account_date", account_date },
                 { "remark", remark },
                 { "status", status },
                 { "last_update", DateTime.Now.ToString("s") },
                 { "update_user_id", _member.infoBySession("id") }
             };
             if(oper == "edit")
             {
                 sql = Common.doUpdate(data, "costs", "id = '" + id + "'");
             }
             else
             {
                 sql = Common.doInsert(data, "costs");
                 this._db.ExecuteStoreCommand(sql);
                 id = (from cs in this._db.recsys_costs
                       orderby cs.id descending
                       select cs.id).FirstOrDefault().ToString();
                 data = new Hashtable()
                 {
                     { "id1", id },
                     { "id2", relate_id },
                     { "table1", "costs" },
                     { "table2", table_name }
                 };
                 sql = Common.doInsert(data, "relate");
             }
         }
         else
         {
             return Content(Common.json_encode(false));
         }
     }
     else
     {
         sql = Common.doDelete("relate", "id1 = '" + id + "' AND table1 = 'costs'");
         this._db.ExecuteStoreCommand(sql);
         sql = Common.doDelete("costs", "id = '" + id + "'");
     }
     this._db.ExecuteStoreCommand(sql);
     return Content(Common.json_encode(true));
 }
        public ActionResult Edit()
        {
            Validator _val = new Validator();
            string quotationPackage_id = Common.doPost("quotationPackage_id");
            int quotationPackageID = Convert.ToInt32(quotationPackage_id);
            string id = Common.doPost("id");

            string code = Common.doPost("code");
            if (!string.IsNullOrEmpty(code))
                code = code.Trim();
            else
                code = "";

            string detail_chi = Common.doPost("detail_chi");
            if (!string.IsNullOrEmpty(detail_chi))
                detail_chi = detail_chi.Trim();
            else
                detail_chi = "";

            string detail_eng = Common.doPost("detail_eng");
            if (!string.IsNullOrEmpty(detail_eng))
                detail_eng = detail_eng.Trim();
            else
                detail_eng = "";

            string price = Common.doPost("price");

            if (string.IsNullOrEmpty(detail_chi) &&
                string.IsNullOrEmpty(detail_eng) &&
                string.IsNullOrEmpty(code))
            {
                string message = "必須輸入Code或內容";
                ArrayList arr = new ArrayList();
                arr.Add(new Hashtable() {
                                { "status",    false },
                                { "message",  message }
                            });
                return Content(Common.json_encode(arr));
            }

            if (string.IsNullOrEmpty(price) || (!string.IsNullOrEmpty(price) && string.IsNullOrEmpty(price.Trim())))
            {
                price = "0.00";
            }

            string sql;

            _val.val(id, new String[] { "req", "int" });

            if (_val.getValStatus())
            {
                Member _member = new Member("users");
                Hashtable data = new Hashtable() {
                    { "code", code },
                    { "detail_chi", detail_chi },
                    { "detail_eng", detail_eng },
                    { "price", price },
                    { "update_date", DateTime.Now.ToString("s") },
                    { "update_by", _member.infoBySession("id") }
                };

                if (int.TryParse(quotationPackage_id, out quotationPackageID))
                {
                    //check whether there is existing active quotation_package_item with the same code in this quotation or not
                    int quotationPackageItemID;
                    int.TryParse(id, out quotationPackageItemID);
                    var items = from i in this._db.recsys_quotation_package_items
                                where i.quotation_package_id == quotationPackageID && i.status == 1
                                select i;

                    foreach (recsys_quotation_package_items item in items)
                    {
                        if (!string.IsNullOrEmpty(code) && code.Trim().ToUpper() == item.code.Trim().ToUpper() && quotationPackageItemID != item.id)
                        {
                            string message = "已有Quotation Package item (" + code.Trim().ToUpper() + ")";
                            ArrayList arr = new ArrayList();
                            arr.Add(new Hashtable() {
                                { "status",    false },
                                { "message",  message }
                            });
                            return Content(Common.json_encode(arr));
                        }
                    }

                }
                sql = Common.doUpdate(data, "quotation_package_items", "id = '" + id + "'");

            }
            else
            {
                return Content(Common.json_encode(false));
            }

            this._db.ExecuteStoreCommand(sql);

            //update quotation package total price
            double? total = (from qpi in this._db.recsys_quotation_package_items
                             where qpi.quotation_package_id == quotationPackageID && qpi.status == 1
                             select qpi.price).Sum();

            recsys_quotation_packages quotationPackage = this._db.recsys_quotation_packages.FirstOrDefault(qp => qp.id == quotationPackageID);
            quotationPackage.price = total != null ? total : 0.0;

            try
            {
                this._db.SaveChanges();
            }
            catch (OptimisticConcurrencyException)
            {
                //# log down
            }

            return Json(new { total = quotationPackage.price });
        }
Exemplo n.º 14
0
        public ActionResult Edit(
            string ID,
            string Code,
            string Name,
            string RegionID,
            string GroupID2,
            string Status2,
            string oper)
        {
            Validator _val = new Validator();
            //string id = Common.doPost("id");
            //string code = Common.doPost("code");
            //string name = Common.doPost("name");
            //string region = Common.doPost("region");
            //string group_id = Common.doPost("group_id2");
            //string status = Common.doPost("status2");
            //string oper = Common.doPost("oper");
            string sql;
            if(oper != "del")
            {
                if(oper == "edit")
                {
                    _val.val(ID, new String[] { "req", "int" });
                }
                //_val.val(RegionID, new String[] { "req", "int", "get=1", "let=3" });
                _val.val(Code, new String[] { "req", "maxlen=10" });
                _val.val(Name, "req");
                _val.val(GroupID2, new String[] { "req", "int" });
                _val.val(Status2, new String[] { "req", "int", "get=0", "let=1" });
                int group = Convert.ToInt32(GroupID2);
                int group_exist = (from g in this._db.recsys_group
                                   where g.status == 1 && g.id == @group
                                   select g).Count();
                if (group_exist == 0)
                {
                    _val.setValStatus(false);
                }
                if(_val.getValStatus())
                {
                    Member _member = new Member("users");
                    Hashtable data = new Hashtable() {
                        { "group_id", GroupID2 },
                        { "region", RegionID },
                        { "code", Code },
                        { "name", Name },
                        { "status", Status2 },
                        { "last_update", DateTime.Now.ToString("s") },
                        { "update_user_id", _member.infoBySession("id") }
                    };
                    if(oper == "edit")
                    {
                        sql = Common.doUpdate(data, "district", "id = '" + ID + "'");
                    }
                    else
                    {
                        sql = Common.doInsert(data, "district");
                    }

                }
                else
                {
                    return Content(Common.json_encode(false));
                }
            }
            else
            {
                sql = Common.doDelete("district", "id = '" + ID + "'");
            }
            this._db.ExecuteStoreCommand(sql);
            return Content(Common.json_encode(true));
        }
Exemplo n.º 15
0
        public ActionResult Edit()
        {
            Validator _val = new Validator();
            string id = Common.doPost("id");
            string name = Common.doPost("name");
            string supervisor_id = Common.doPost("supervisor_id2");
            string engineer = Common.doPost("engineer2");
            string status = Common.doPost("status2");
            string oper = Common.doPost("oper");
            string sql;
            if(oper != "del")
            {
                if(oper == "edit")
                {
                    _val.val(id, new String[] { "req", "int" });
                }
                _val.val(name, "req");
                _val.val(supervisor_id, new String[] { "req", "int" });
                if (! String.IsNullOrWhiteSpace(engineer))
                {
                    _val.val(engineer, @"customize=^(\d+(,\d+)*)?$");

                    string[] str = engineer.Split(',');
                    #region Checking - Engineer can only join 1 group
                    foreach (String engineer_id in str)
                    {
                        int groupID = (oper == "edit") ? int.Parse(id) : 0;
                        int engineerID = int.Parse(engineer_id);
                        var groupRecord = (from r in this._db.recsys_relate
                                           join u in this._db.recsys_users on r.id2 equals u.id
                                           where r.table1 == "group" && r.table2 == "users" && r.id2 == engineerID && r.id1 != groupID
                                           select u).FirstOrDefault();
                        if (groupRecord != null) return Json(new { success = false, errorType = "Duplicate-Member", message = string.Format("{0}已加入其他組別。請先把{0}從此組別剔除。", groupRecord.name) });
                    }
                    #endregion Checking - Engineer can only join 1 group

                }
                _val.val(status, new String[] { "req", "int", "get=0", "let=1" });
                int user_id = Convert.ToInt32(supervisor_id);

                if (user_id != 0)
                {
                    int users_exist = (from u in this._db.recsys_users
                                       where u.status == 1 && u.id == user_id
                                       select u).Count();
                    if (users_exist == 0)
                    {
                        _val.setValStatus(false);
                    }
                }
                if(_val.getValStatus())
                {
                    Member _member = new Member("users");
                    Hashtable data = new Hashtable() {
                        { "name", name },
                        { "supervisor_id", supervisor_id },
                        { "status", status },
                        { "last_update", DateTime.Now.ToString("s") },
                        { "update_user_id", _member.infoBySession("id") }
                    };
                    if(oper == "edit")
                    {
                        sql = Common.doUpdate(data, "group", "id = '" + id + "'");
                    }
                    else
                    {
                        sql = Common.doInsert(data, "group");
                    }
                    this._db.ExecuteStoreCommand(sql);
                    if (oper == "edit")
                    {
                        sql = Common.doDelete("relate", "id1 = '" + id + "' AND table1 = 'group'");
                        this._db.ExecuteStoreCommand(sql);
                    }
                    if (! String.IsNullOrWhiteSpace(engineer))
                    {
                        if (oper == "add")
                        {
                            id = (from g in this._db.recsys_group
                                  orderby g.id descending
                                  select g.id).FirstOrDefault().ToString();
                        }

                        string[] str = engineer.Split(',');

                        foreach (String engineer_id in str)
                        {
                            Hashtable hash = new Hashtable()
                            {
                                { "id1", id },
                                { "id2", engineer_id },
                                { "table1", "group" },
                                { "table2", "users" }
                            };
                            sql = Common.doInsert(hash, "relate");
                            this._db.ExecuteStoreCommand(sql);
                        }
                    }
                }
                else
                {
                    return Content(Common.json_encode(false));
                }
            }
            else
            {
                sql = Common.doDelete("relate", "id1 = '" + id + "' AND table1 = 'group'");
                this._db.ExecuteStoreCommand(sql);
                sql = Common.doDelete("group", "id = '" + id + "'");
                this._db.ExecuteStoreCommand(sql);
            }
            return Content(Common.json_encode(true));
        }
Exemplo n.º 16
0
        public ActionResult Edit()
        {
            Validator _val = new Validator();
            string quotation_id = Common.doPost("quotation_id");
            string id = Common.doPost("id");

            string code = Common.doPost("code");
            if (!string.IsNullOrEmpty(code))
                code = code.Trim();
            else
                code = "";

            string detail = Common.doPost("detail");
            if (!string.IsNullOrEmpty(detail))
                detail = detail.Trim();
            else
                detail = "";

            string detail2 = Common.doPost("detail2");
            if (!string.IsNullOrEmpty(detail2))
                detail2 = detail2.Trim();
            else
                detail2 = "";

            string price = Common.doPost("price");

            if (string.IsNullOrEmpty(detail) &&
                string.IsNullOrEmpty(detail2) &&
                string.IsNullOrEmpty(code))
            {
                string message = "必須輸入Code或內容";
                ArrayList arr = new ArrayList();
                arr.Add(new Hashtable() {
                                { "status",    false },
                                { "message",  message }
                            });
                return Content(Common.json_encode(arr));
            }

            if (string.IsNullOrEmpty(price) || (!string.IsNullOrEmpty(price) && string.IsNullOrEmpty(price.Trim())))
            {
                price = "0.00";
            }
            string oper = Common.doPost("oper");
            string sql;
            if (oper != "del")
            {
                if (oper == "edit")
                {
                    _val.val(id, new String[] { "req", "int" });
                }
                else
                {
                    int quotation = Convert.ToInt32(quotation_id);
                    int quotation_exist = (from q in this._db.recsys_quotation
                                           where q.id == quotation
                                           select q).Count();
                    if (quotation_exist == 0)
                    {
                        _val.setValStatus(false);
                    }
                    _val.val(quotation_id, new String[] { "req", "int" });
                }
                //_val.val(code, "req");            //# Eddie: 20131011 remove validation
                if (_val.getValStatus())
                {
                    Member _member = new Member("users");
                    Hashtable data = new Hashtable() {
                        { "code", code },
                        { "detail", detail },
                        { "detail2", detail2 },
                        { "price", price },
                        { "last_update", DateTime.Now.ToString("s") },
                        { "update_user_id", _member.infoBySession("id") }
                    };
                    if (oper == "edit")
                    {
                        int quotationID;
                        if (int.TryParse(quotation_id, out quotationID))
                        {
                            //check whether there is existing quotation_item with the same code in this quotation or not
                            int quotationItemId;
                            int.TryParse(id, out quotationItemId);
                            var items = from i in this._db.recsys_quotation_items
                                                                             join r in this._db.recsys_relate on i.id equals r.id2
                                                                             where r.id1 == quotationID && r.table1 == "quotation" && r.table2 == "quotation_items"
                                                                             select i;

                            foreach (recsys_quotation_items item in items)
                            {
                                if (!string.IsNullOrEmpty(code) && code.Trim().ToUpper() == item.code.Trim().ToUpper() && quotationItemId != item.id)
                                {
                                    string message = "已有Quotation item (" + code.Trim().ToUpper() + ")";
                                    ArrayList arr = new ArrayList();
                                    arr.Add(new Hashtable() {
                                        { "status",    false },
                                        { "message",  message }
                                    });
                                    return Content(Common.json_encode(arr));
                                }
                            }

                        }
                        sql = Common.doUpdate(data, "quotation_items", "id = '" + id + "'");

                    }
                    else
                    {
                        sql = Common.doInsert(data, "quotation_items");
                        this._db.ExecuteStoreCommand(sql);
                        id = (from i in this._db.recsys_quotation_items
                              orderby i.id descending
                              select i.id).FirstOrDefault().ToString();
                        data = new Hashtable()
                        {
                            { "id1", quotation_id },
                            { "id2", id },
                            { "table1", "quotation" },
                            { "table2", "quotation_items" }
                        };
                        sql = Common.doInsert(data, "relate");
                    }

                }
                else
                {
                    return Content(Common.json_encode(false));
                }
            }
            else
            {
                sql = Common.doDelete("relate", "id2 = '" + id + "' AND table2 = 'quotation_items'");
                this._db.ExecuteStoreCommand(sql);
                sql = Common.doDelete("quotation_items", "id = '" + id + "'");
            }
            this._db.ExecuteStoreCommand(sql);
            return Content(Common.json_encode(true));
        }