コード例 #1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime ngayan = DateTime.Now.Date;
                if (!DateTime.TryParse(txtNgayAn.Text.Trim(), ci, System.Globalization.DateTimeStyles.None, out ngayan))
                {
                    ngayan = DateTime.Now.Date;
                }

                if (ngayan < Config.NgayKhoaSo())
                {
                    Page.ClientScript.RegisterStartupScript(typeof(string), "insertupdatefail", "alert('Không lưu được ngày có thức ăn thừa trước ngày khóa sổ');", true);
                    return;
                }

                string s = "";
                foreach (string k in Request.Form.AllKeys)
                {
                    if (k.StartsWith("chuong") && Request.Form[k] != "")
                    {
                        s += "@" + k.Substring(6) + "/" + Request.Form[k] + "@";
                    }
                }

                csCont.CaSauAnThua_InsertUpdate(ngayan, s);
                for (int i = 0; i < int.Parse(hdNumListChuong.Value); i++)
                {
                    ListBox l = (ListBox)(phChuong.FindControl("lstChuong" + i.ToString()));
                    if (l != null)
                    {
                        foreach (ListItem item in l.Items)
                        {
                            item.Selected = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
        }