Example #1
0
        protected void btnSaveThucAn_Click(object sender, EventArgs e)
        {
            int res;

            if (ddlThucAn.SelectedValue == "0")
            {
                Page.ClientScript.RegisterStartupScript(typeof(string), "chuacovattu", "alert('Chưa chọn thức ăn');", true);
                return;
            }
            string arrNhanVien = hdNguoiChoAn.Value;

            if (arrNhanVien != "")
            {
                arrNhanVien = "@" + arrNhanVien.Replace(",", "@@");
                arrNhanVien = arrNhanVien.Remove(arrNhanVien.Length - 1);
            }
            if (ddlLoaiCa.SelectedValue == "0")
            {
                string ress = csCont.CaSauAn_InsertUpdateThucAn_SS(int.Parse(hdCaSauAn.Value), int.Parse(ddlThucAn.SelectedValue), decimal.Parse(txtKhoiLuong.Text), arrNhanVien, UserId);
                if (ress == "")
                {
                    Page.ClientScript.RegisterStartupScript(typeof(string), "daluuxong", "alert('Đã thêm thành công');", true);
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(typeof(string), "daluuxong", "alert('Một số loại cá không cho ăn được:" + ress + "');", true);
                }
                LoadThucAn();
                return;
            }
            string  StrPhanCachKhuChuong = "";
            string  khuchuong            = "";
            string  currkhuchuong        = "";
            string  StrSoLuongChuong     = "";
            string  StrSoLuongChuongTT   = "";
            string  StrChuong            = "";
            string  StrKL = "";
            decimal testKL;
            int     SoLuongCa = 0;
            int     SoLuongTT = 0;
            int     index     = 0;

            foreach (GridViewRow r in grvDanhSach.Rows)
            {
                TextBox txtKL      = (TextBox)(r.FindControl("txtKhoiLuong"));
                Label   lblSoLuong = (Label)(r.FindControl("lblSoLuong"));
                Label   lblSLTT    = (Label)(r.FindControl("lblSLTT"));
                Label   lblChuong  = (Label)(r.FindControl("lblChuong"));
                testKL = -1;
                if (Decimal.TryParse(txtKL.Text, out testKL) && testKL > 0)
                {
                    StrSoLuongChuong   += "@" + lblSoLuong.Text + "@";
                    StrSoLuongChuongTT += "@" + lblSLTT.Text + "@";
                    StrChuong          += "@" + lblChuong.ToolTip + "@";
                    StrKL        += "@" + txtKL.Text.Replace(",", ".") + "@";
                    SoLuongCa    += int.Parse(lblSoLuong.Text);
                    SoLuongTT    += int.Parse(lblSLTT.Text);
                    currkhuchuong = lblChuong.Text.Substring(0, 2);
                    if (currkhuchuong != khuchuong)
                    {
                        StrPhanCachKhuChuong += "@" + index + "@";
                        khuchuong             = currkhuchuong;
                    }
                    index++;
                }
            }
            if (StrPhanCachKhuChuong != "")
            {
                StrPhanCachKhuChuong = StrPhanCachKhuChuong.Substring(3) + "@" + index.ToString() + "@";
            }
            res = csCont.CaSauAn_InsertUpdateThucAn(int.Parse(hdCaSauAn.Value), int.Parse(ddlThucAn.SelectedValue), decimal.Parse(txtKhoiLuong.Text), int.Parse(ddlLoaiCa.SelectedValue), SoLuongCa, SoLuongTT, StrSoLuongChuong, StrSoLuongChuongTT, StrChuong, StrKL, StrPhanCachKhuChuong, arrNhanVien, UserId, true);
            if (res == 0)
            {
                Page.ClientScript.RegisterStartupScript(typeof(string), "daluuxong", "alert('Lưu không thành công! Có thể thời điểm cho ăn hoặc khối lượng thức ăn không hợp lệ');", true);
            }
            else
            {
                LoadThucAn();
            }
        }