protected void btn_save_Click(object sender, EventArgs e) { Chicken_raisingTableAdapter ch = new Chicken_raisingTableAdapter(); Detail_Chicken_raisingTableAdapter dc = new Detail_Chicken_raisingTableAdapter(); FarmTableAdapter ff = new FarmTableAdapter(); BuildingTableAdapter bu = new BuildingTableAdapter(); Problem_recommendTableAdapter pp = new Problem_recommendTableAdapter(); if (txt_D1.Text != "" && txt_S.Text != "") { int nuch = Convert.ToInt32(ch.ScalarQuery().ToString()); int np1 = nuch + 1; string idpro = ""; if (np1 <= 9) { idpro = "C000" + np1.ToString(); } else if (np1 <= 99) { idpro = "C00" + np1.ToString(); } else { idpro = "C0" + np1.ToString(); } string idf2 = Session["ID_Login"].ToString(); idf2 = idf2.Substring(0, 1); if (idf2 == "F") { ch.InsertQuery(idpro, Session["ID_Bu"].ToString(), Request.QueryString["NameFarm"].ToString(), Request.QueryString["NameOF"].ToString(), Session["Name_Login"].ToString(), ff.GetDataBy4(Request.QueryString["NameFarm"].ToString()).Rows[0][2].ToString(), Request.QueryString["NameBu"].ToString(), Session["S_Bu"].ToString(), Session["In_Ch"].ToString(), bu.GetDataBy2(Request.QueryString["NameBu"].ToString()).Rows[0][3].ToString(), txt_D1.Text, txt_S.Text, DateTime.Now.ToString()); int nupp = Convert.ToInt32(pp.ScalarQuery1("S0001").ToString()); for (int i = 0; i < nupp; i++) { dc.InsertQuery(idpro, pp.GetDataBy2("S0001").Rows[i][0].ToString(), pp.GetDataBy2("S0001").Rows[i][1].ToString(), pp.GetDataBy2("S0001").Rows[i][2].ToString(), pp.GetDataBy2("S0001").Rows[i][3].ToString(), pp.GetDataBy2("S0001").Rows[i][4].ToString(), pp.GetDataBy2("S0001").Rows[i][5].ToString(), pp.GetDataBy2("S0001").Rows[i][6].ToString(), pp.GetDataBy2("S0001").Rows[i][7].ToString(), pp.GetDataBy2("S0001").Rows[i][8].ToString()); } for (int i1 = 0; i1 < nupp; i1++) { string iidpp = pp.GetDataBy2("S0001").Rows[0][0].ToString(); pp.DeleteQuery(iidpp); } string message = "บันทึกการเลี้ยงเรียบร้อย !!"; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("{"); sb.Append("alert('"); sb.Append(message); sb.Append("')};"); sb.Append("</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString()); ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script language=javascript>fini();</script>"); } else { } } else { string message = "กรุณากรอกจำนวนไก่ที่นำไปขายและไก่ที่ตาย !!"; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("{"); sb.Append("alert('"); sb.Append(message); sb.Append("')};"); sb.Append("</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString()); } }
public static string S1(string age, string data, string pro, string time, string solu, string ids, string re, string datere) { Problem_recommendTableAdapter pr = new Problem_recommendTableAdapter(); if (Convert.ToInt32(pr.ScalarQuery().ToString()) == 0) { pr.InsertQuery("P0001", "S0001", "", "", "", "", "", "", ""); } int np = Convert.ToInt32(pr.ScalarQuery().ToString()); int np1 = np + 1; string idpro = ""; if (np1 <= 9) { idpro = "P000" + np1.ToString(); } else if (np1 <= 99) { idpro = "P00" + np1.ToString(); } else { idpro = "P0" + np1.ToString(); } string aggee0 = pr.GetDataBy2(ids).Rows[np - 1][0].ToString(); string aggee1 = pr.GetDataBy2(ids).Rows[np - 1][1].ToString(); string aggee2 = pr.GetDataBy2(ids).Rows[np - 1][2].ToString(); string aggee3 = pr.GetDataBy2(ids).Rows[np - 1][3].ToString(); string aggee4 = pr.GetDataBy2(ids).Rows[np - 1][4].ToString(); string aggee5 = pr.GetDataBy2(ids).Rows[np - 1][5].ToString(); string aggee6 = pr.GetDataBy2(ids).Rows[np - 1][6].ToString(); string aggee7 = pr.GetDataBy2(ids).Rows[np - 1][7].ToString(); string aggee8 = pr.GetDataBy2(ids).Rows[np - 1][8].ToString(); if (aggee1 != ids || aggee2 != pro || aggee3 != time || aggee4 != re || aggee5 != datere || aggee6 != solu || aggee7 != age || aggee8 != data) { int ii1 = 0; for (int i = 0; i < Convert.ToInt32(pr.ScalarQuery1("S0001").ToString()); i++) { if (time == pr.GetDataBy2("S0001").Rows[i][3].ToString()) { ii1 = ii1 + 1; } if (age != pr.GetDataBy2("S0001").Rows[i][7].ToString()) { ii1 = 0; } } if (ii1 == 0) { pr.InsertQuery(idpro, ids, pro, time, re, datere, solu, age, data); } if (re != "" && ii1 == 0) { pr.InsertQuery(idpro, ids, pro, time, re, datere, solu, age, data); } } return(aggee0); }