Ejemplo n.º 1
0
        protected void btn_Cat_Click(object sender, EventArgs e)
        {
            try {
                SqlCommand     cmd  = new SqlCommand("select * from tbl_BookCategory where cat_name='" + txt_cat.Text + "' and school_code='" + Session["schoolcode"].ToString() + "' and branch='" + Session["Branch"].ToString() + "'", conn);
                SqlDataAdapter adpt = new SqlDataAdapter(cmd);
                DataSet        ds   = new DataSet();
                adpt.Fill(ds);
                int i = ds.Tables[0].Rows.Count;

                if (i > 0)
                {
                    ShowMessage("This category is already exists.");
                    ds.Clear();
                }
                else
                {
                    cmd             = new SqlCommand();
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = "insert into tbl_BookCategory " +
                                      "(cat_id,cat_name,cat_val,entry_dt,entry_by,mac_id,school_code,branch) " +
                                      "values('" + Global_Class.GenerateID("select count(*) from tbl_BookCategory where " +
                                                                           "school_code='" + Session["schoolcode"].ToString() + "' and branch='" + Session["Branch"].ToString() + "'", Session["schoolcode"] + "/CAT/").ToString() + "'," +
                                      "'" + txt_cat.Text + "','" + Global_Class.Drp_val_gen("select count(*) from tbl_BookCategory where school_code='" + Session["schoolcode"].ToString() + "' and branch='" + Session["Branch"].ToString() + "'", 0).ToString() + "','" + DateTime.Now.ToString("dd/MM/yyyy") + "','" + Session["uname"] + "','" + Global_Class.getFormatMac(Global_Class.GetMACAddress()) + "','" + Session["schoolcode"].ToString() + "','" + Session["Branch"].ToString() + "') ";
                    cmd.Connection = conn;
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                    conn.Open();
                    cmd.ExecuteNonQuery();
                    ShowMessage("Category saved.");
                    txt_id.Text     = Global_Class.GenerateID("select count(*) from tbl_BookCategory where school_code='" + Session["schoolcode"].ToString() + "' and branch='" + Session["Branch"].ToString() + "'", Session["schoolcode"] + "/CAT/");
                    txt_sub_id.Text = Global_Class.GenerateID("select count(*) from tbl_BookSubCategory where school_code='" + Session["schoolcode"].ToString() + "' and branch='" + Session["Branch"].ToString() + "'", Session["schoolcode"] + "/SUBCAT/");

                    fillcategory();
                    FillCatGrid();
                    FillSubCatGrid();
                    txt_cat.Text     = String.Empty;
                    txt_sub_cat.Text = String.Empty;
                }
            }
            catch (Exception ex) { ex.ToString(); }
        }
Ejemplo n.º 2
0
        protected void btn_class_add_Click(object sender, EventArgs e)
        {
            try {
                SqlCommand CheckSub = new SqlCommand();
                CheckSub.Connection  = conn;
                CheckSub.CommandType = CommandType.Text;
                CheckSub.CommandText = "SELECT COUNT(*) FROM CLASSFILE WHERE CLASSNAME = '" + txt_class_name.Text + "' and  school_code='" + Session["schoolcode"].ToString() + "' and branch='" + Session["Branch"].ToString() + "' ";
                int SubExists = (int)CheckSub.ExecuteScalar();

                if (SubExists > 0)
                {
                    ShowMessage("This class is already exists.");
                }
                else
                {
                    if (int.Parse(txt_class_name.Text) > 12)
                    {
                        ShowMessage("This class is not valid.");
                        txt_class_name.Text = "";
                    }
                    else
                    {
                        SqlCommand cmd = new SqlCommand();
                        cmd.Connection  = conn;
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = "insert into CLASSFILE" +
                                          " (CLASSCODE,CLASSNAME,CLASS_VAL,school_code,branch)" +
                                          " VALUES('" + txt_class_code.Text + "','" + txt_class_name.Text + "','" + Global_Class.Drp_val_gen("select count(*) from CLASSFILE where school_code='" + Session["schoolcode"].ToString() + "' and branch='" + Session["Branch"].ToString() + "'", 0).ToString() + "','" + Session["schoolcode"].ToString() + "','" + Session["Branch"].ToString() + "')";
                        cmd.ExecuteNonQuery();
                        ShowMessage("Recorded To The System Successfully");
                        txt_class_code.Text = Global_Class.GenerateID("select count(*) from CLASSFILE where  school_code='" + Session["schoolcode"].ToString() + "' and branch='" + Session["Branch"].ToString() + "'", Session["schoolcode"] + "/CLS/");
                        txt_class_name.Text = "";
                    }
                }
            }
            catch (Exception ex) { ex.ToString(); }
        }