Example #1
0
        public ActionResult Insert(TestMasterInfo entity, bool isPartialView = false, string fun = null)
        {
            if (!string.IsNullOrEmpty(fun) && fun == "Cancel")
            {
                return(Content(""));
            }
            var biz = new TestBiz.Master();

            if (biz.Load(null, null, entity.NO) != null)
            {
                ModelState.AddModelError("NO", "編號已存在");
            }

            if (ModelState.IsValid)//如果必要有值的話就執行 不然就拋回去
            {
                if (biz.Insert(entity) > 0)
                {
                    //return Read(new TestMasterInfo.Conditions { ID = entity.ID, NO = entity.NO });
                    string js = string.Format("$('#dumyID').val('{0}');$('#dumyList').submit();$('#dumyRead').submit();", entity.ID);
                    return(JavaScript(js));
                }
            }
            if (isPartialView)
            {
                return(PartialView("~/Views/Shared/Test/_Create.cshtml", entity));
            }
            else
            {
                return(View(entity));
            }
        }
Example #2
0
        protected void fvMaster_ItemInserting(object sender, FormViewInsertEventArgs e)
        {
            var entity = new TestMasterInfo
            {
                NO       = e.Values["NO"]?.ToString(),
                Name     = e.Values["Name"]?.ToString(),
                Address  = e.Values["Address"]?.ToString(),
                Phone    = e.Values["Phone"]?.ToString(),
                Birthday = string.IsNullOrEmpty(e.Values["Birthday"].ToString()) ? default(DateTime?) : Convert.ToDateTime(e.Values["Birthday"]),
            };
            var biz = new TestBiz.Master();
            int i   = biz.Insert(entity);

            if (i == 0)
            {
                e.Cancel = true;
            }
            else
            {
                fvMaster.ChangeMode(FormViewMode.ReadOnly);
                bindMasterForm(null, entity.ID);
                bindMaster(null);
                upGVMaster.Update();
            }
        }
Example #3
0
        //    protected void fvMaster_DoCommand(object sender, EventArgs e)
        //    {
        //        int? SID = null;
        //        string ID = string.Empty;
        //        if (fvMaster.CurrentMode == FormViewMode.Insert)
        //        {
        //            if(gvMaster.SelectedDataKey !=null)

        //        {
        //            SID = Convert.ToInt32(gvMaster.SelectedDataKey.Values[0]);
        //            ID = gvMaster.SelectedDataKey.Values[1].ToString();

        //        }
        //        }
        //        else
        //        {
        //            SID = Convert.ToInt32(dvMaster.DataKey.Values[0]);
        //            ID = dvMaster.DataKey.Values[1].ToString();

        //        }
        //        Button btn = (Button)sender;

        //if (btn.CommandName == "Create") {
        //        //TestBiz biz == new TestBiz.Master();
        //        //    No=e.
        //                }
        //        if (btn.CommandName == "Canel") {
        //            fvMaster.ChangeMode(FormViewMode.ReadOnly);
        //            bindMasterForm(SID, ID);
        //        }
        //    }

        protected void fvMaster_ItemInserting(object sender, FormViewInsertEventArgs e)
        {
            var entity = new TestMasterInfo
            {
                //NO = e.Values["NO"] == null ? null: e.Values["NO"].ToString(), //原本寫法
                NO   = e.Values["NO"]?.ToString(), //精簡寫法
                Name = e.Values["Name"]?.ToString(),
                //Address = e.Values["Address"]?.ToString(),
                //Address = ((DropDownList)fvMaster.FindControl("ddlAddress")).SelectedValue,
                Address  = e.Values["Address"]?.ToString().Split(new string[] { ":::" }, System.StringSplitOptions.None)[0],
                Phone    = e.Values["Phone"]?.ToString(),
                Birthday = e.Values[" Birthday"] == null ? default(DateTime?) : Convert.ToDateTime(e.Values["Birthday"])
            };

            if (Page.IsValid)
            {
                var biz = new TestBiz.Master();
                int i   = biz.Insert(entity);

                if (i == 0)
                {
                    e.Cancel = true;
                    //失敗的話執行這個
                }
                else
                {
                    fvMaster.ChangeMode(FormViewMode.ReadOnly);
                    bindMasterDetails(null, entity.ID);
                    bindMaster(null);
                    upGridView.Update();
                }
            }
        }
Example #4
0
        // POST api/<controller>
        public dynamic Post(string id, [FromBody] dynamic value)
        {
            bool result = false;

            if (id == "load")
            {
                ModelRequest    model      = JsonConvert.DeserializeObject <ModelRequest>(JsonConvert.SerializeObject(value));
                var             biz        = new TestBiz.Master();
                PageInationInfo pagination = model.pagination;

                ModelResponse resultLoad = new ModelResponse {
                    conditions = model.conditions
                };
                resultLoad.data = biz.Load(ref pagination, model.conditions).AsEnumerable()
                                  .Select(i => new TestMasterInfo
                {
                    SID        = i.Field <int>("SID"),
                    ID         = i.Field <string>("ID"),
                    NO         = i.Field <string>("NO"),
                    Name       = i.Field <string>("Name"),
                    Address    = i.Field <string>("Address"),
                    Phone      = i.Field <string>("Phone"),
                    Age        = i.Field <decimal?>("Age"),
                    Birthday   = i.Field <DateTime?>("Birthday"),
                    CreateTime = i.Field <DateTime>("CreateTime"),
                    UpdaueTime = i.Field <DateTime>("UpdaueTime")
                })
                                  .ToList();
                resultLoad.pagination = new ModelResponse.PaginationInfo {
                    Index = pagination.Index, Size = pagination.Size, Total = pagination.Total
                };
                return(resultLoad);
            }
            if (id == "create")
            {
                TestMasterInfo model = JsonConvert.DeserializeObject <TestMasterInfo>(JsonConvert.SerializeObject(value));
                if (ModelState.IsValid)
                {
                    var biz = new TestBiz.Master();
                    return(biz.Insert(model));
                }
                return("資料驗證錯誤");
            }
            return(result);
        }
Example #5
0
        protected void dvMaster_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            var entity = new TestMasterInfo
            {
                //NO = e.Values["NO"] == null ? null: e.Values["NO"].ToString(), //原本寫法
                NO       = e.Values["NO"]?.ToString(), //精簡寫法
                Name     = e.Values["Name"]?.ToString(),
                Address  = e.Values["Address"]?.ToString(),
                Phone    = e.Values["Phone"]?.ToString(),
                Birthday = e.Values[" Birthday"] == null ? default(DateTime?) : Convert.ToDateTime(e.Values["Birthday"])
            };

            var biz = new TestBiz.Master();
            int i   = biz.Insert(entity);

            if (i == 0)
            {
                e.Cancel = true;
                //失敗的話執行這個
            }
            else
            {
                dvMaster.ChangeMode(DetailsViewMode.ReadOnly);
                bindMasterDetails(null, entity.ID);
                bindMaster(null);
            }

            //精簡寫法
            //            var biz = new TestBiz.Master();
            //            biz.Insert(new TestMasterInfo
            //            {
            //                Name = e.Values["Name"].ToString(),
            //                Address = e.Values["Address"].ToString(),
            //                Phone = e.Values["Phone"].ToString(),
            //                Birthday = Convert.ToDateTime(e.Values["Birthday"])
            //            }
            //            );
        }
Example #6
0
        protected void dvMaster_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            var entity = new TestMasterInfo
            {
                NO       = e.Values["NO"]?.ToString(),
                Name     = e.Values["Name"]?.ToString(),
                Address  = e.Values["Address"]?.ToString(),
                Phone    = e.Values["Phone"]?.ToString(),
                Birthday = e.Values["Birthday"]?.ToString() == null ? default(DateTime?) : Convert.ToDateTime(e.Values["Birthday"]?.ToString())
            };
            var biz = new TestBiz.Master();
            int i   = biz.Insert(entity);

            if (i == 0)
            {
                e.Cancel = true;
            }
            else
            {
                dvMaster.ChangeMode(DetailsViewMode.ReadOnly);
                bindMasterDetail(null, entity.ID);
                bindMaster(null);
            }
        }