public bool SP_ITEM_GROUP_INS(Item_group item_group, ref string strMessage) { bool blnResult = false; SqlConnection oConn = new SqlConnection(); SqlCommand oCommand = new SqlCommand(); SqlDataAdapter oAdapter = new SqlDataAdapter(); try { oConn.ConnectionString = _strConn; oConn.Open(); oCommand.Connection = oConn; oCommand.CommandType = CommandType.StoredProcedure; oCommand.CommandText = "sp_ITEM_GROUP_INS"; // - - - - - - - - - - - - SqlParameter oParam_Item_group_year = new SqlParameter("item_group_year", SqlDbType.NVarChar); oParam_Item_group_year.Direction = ParameterDirection.Input; oParam_Item_group_year.Value = item_group.item_group_year; oCommand.Parameters.Add(oParam_Item_group_year); // - - - - - - - - - - - - SqlParameter oParam_Item_group_name = new SqlParameter("item_group_name", SqlDbType.NVarChar); oParam_Item_group_name.Direction = ParameterDirection.Input; oParam_Item_group_name.Value = item_group.item_group_name; oCommand.Parameters.Add(oParam_Item_group_name); // - - - - - - - - - - - - SqlParameter oParam_Item_group_type = new SqlParameter("item_group_type", SqlDbType.NVarChar); oParam_Item_group_type.Direction = ParameterDirection.Input; oParam_Item_group_type.Value = item_group.item_group_type; oCommand.Parameters.Add(oParam_Item_group_type); // - - - - - - - - - - - - SqlParameter oParam_lot_code = new SqlParameter("lot_code", SqlDbType.NVarChar); oParam_lot_code.Direction = ParameterDirection.Input; oParam_lot_code.Value = item_group.lot_code; oCommand.Parameters.Add(oParam_lot_code); // - - - - - - - - - - - - SqlParameter oParam_Active = new SqlParameter("c_active", SqlDbType.NVarChar); oParam_Active.Direction = ParameterDirection.Input; oParam_Active.Value = item_group.c_active; oCommand.Parameters.Add(oParam_Active); // - - - - - - - - - - - - SqlParameter oParam_c_created_by = new SqlParameter("c_created_by", SqlDbType.NVarChar); oParam_c_created_by.Direction = ParameterDirection.Input; oParam_c_created_by.Value = item_group.c_created_by; oCommand.Parameters.Add(oParam_c_created_by); // - - - - - - - - - - - - oCommand.ExecuteNonQuery(); blnResult = true; } catch (Exception ex) { strMessage = ex.Message.ToString(); } finally { oConn.Close(); oCommand.Dispose(); oConn.Dispose(); } return(blnResult); }
private bool saveData() { bool blnResult = false; bool blnDup = false; string strScript = string.Empty; cItem_group oItem_group = new cItem_group(); DataSet ds = new DataSet(); try { #region set Data var item_group = new Item_group() { item_group_code = txtitem_group_code.Text.Trim(), item_group_name = txtitem_group_name.Text, item_group_year = cboYear.SelectedItem.Value, lot_code = cboLot_code.SelectedItem.Value, item_group_type = cboItem_type.SelectedItem.Value, c_active = chkStatus.Checked ? "Y" : "N", c_created_by = Session["username"].ToString(), c_updated_by = Session["username"].ToString() }; #endregion if (ViewState["mode"].ToString().ToLower().Equals("edit")) { #region edit if (!blnDup) { if (oItem_group.SP_ITEM_GROUP_UPD(item_group, ref _strMessage)) { blnResult = true; } else { lblError.Text = _strMessage.ToString(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true); } #endregion } else { #region check dup string strCheckDup = string.Empty; strCheckDup = " and item_group_name = '" + item_group.item_group_name + "' and item_group_year = '" + item_group.item_group_year + "' "; if (!oItem_group.SP_ITEM_GROUP_SEL(strCheckDup, ref ds, ref _strMessage)) { lblError.Text = _strMessage.ToString(); } else { if (ds.Tables[0].Rows.Count > 0) { strScript = "alert(\"ไม่สามารถเพิ่มข้อมูล เนื่องจากข้อมูล " + item_group.item_group_name + " ปี " + item_group.item_group_year + " ซ้ำ\");\n"; blnDup = true; } } #endregion #region insert if (!blnDup) { if (oItem_group.SP_ITEM_GROUP_INS(item_group, ref _strMessage)) { string strGetcode = " and item_group_name = '" + item_group.item_group_name.Trim() + "' and item_group_year = '" + item_group.item_group_year + "' "; if (!oItem_group.SP_ITEM_GROUP_SEL(strGetcode, ref ds, ref _strMessage)) { lblError.Text = _strMessage; } if (ds.Tables[0].Rows.Count > 0) { item_group.item_group_code = ds.Tables[0].Rows[0]["item_group_code"].ToString(); } ViewState["item_group_code"] = item_group.item_group_code; blnResult = true; } else { lblError.Text = _strMessage.ToString(); } } else { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "frMainPage", strScript, true); } #endregion } } catch (Exception ex) { lblError.Text = ex.Message.ToString(); } finally { oItem_group.Dispose(); } return(blnResult); }