public static int InsertOrUpdatePcMappings(PcMappings pcMappings, int flag) { int rlt = 0; string commText = string.Empty; if (flag == 0) { commText = "insert into [tPcMappings] (categoryid , morder , pid ,[container] ,widgetname ,widgetsettings ,clientvisible , pcupdate) values (" + pcMappings.Categoryid + "," + pcMappings.Morder + ",'" + pcMappings.Pid + "', '" + pcMappings.Container + "', '" + pcMappings.Widgetname + "', '" + pcMappings.Widgetsettings + "'," + pcMappings.Isvisible + " ,'" + pcMappings.Pcupdate + "')"; try { rlt = OleDbHelper.ExecuteNonQuery(commText); } catch (Exception ex) { throw ex; } } else if (flag == 1) { commText = "update [tPcMappings] set categoryid =" + pcMappings.Categoryid + ", morder =" + pcMappings.Morder + ", pid ='" + pcMappings.Pid + "', [container] ='" + pcMappings.Container + "', widgetname ='" + pcMappings.Widgetname + "', widgetsettings ='" + pcMappings.Widgetsettings + "', clientvisible =" + pcMappings.Isvisible + " , pcupdate= '" + pcMappings.Pcupdate + "' where pcmid =" + pcMappings.Pcmid; try { rlt = OleDbHelper.ExecuteNonQuery(commText); } catch (Exception ex) { throw ex; } } return rlt; }
protected void btnSave_Click(object sender, EventArgs e) { PcMappings pcMappings = new PcMappings(); pcMappings.Categoryid = Convert.ToInt32(dropdownlistCategories.SelectedValue); pcMappings.Pid = textBoxPid.Text.Trim(); pcMappings.Container = textBoxContainer.Text.Trim(); pcMappings.Morder =string.IsNullOrEmpty(textBoxMorder.Text) ? 0 : Convert.ToInt32(textBoxMorder.Text.Trim()); pcMappings.Widgetname = textBoxWidgetname.Text.Trim(); pcMappings.Widgetsettings = textBoxWidgetsettings.Text.Trim(); pcMappings.Isvisible = checkBoxIsVisible.Checked; pcMappings.Pcupdate = DateTime.Now; if (pageStatus == PageStatus.Add) { try { int rlt = DalHandler.InsertOrUpdatePcMappings(pcMappings, 0); } catch (Exception ex) { errorPlace.InnerText = ex.Message; } } else if (pageStatus == PageStatus.Modify) { pcMappings.Pcmid = Convert.ToInt32(labelID.Text); try { pcMappings.Pcmid = Convert.ToInt32(labelID.Text); int rlt = DalHandler.InsertOrUpdatePcMappings(pcMappings, 1); } catch (Exception ex) { errorPlace.InnerText = ex.Message; } } BindGridViewData(); BindDropDownList(); ReSetControlsStatus(); }