protected void BtnCategory_Save_Click(object sender, EventArgs e) { if (btn_save.Text == "Save") { // StringBuilder object StringBuilder str = new StringBuilder(); Dictionary <string, string> selectedvalues = new Dictionary <string, string>(); cmd = new MySqlCommand("insert into location_groups (location_group_name,user_sno) values (@location_group_name,@user_sno)"); cmd.Parameters.Add("@location_group_name", txt_groupname.Text); cmd.Parameters.Add("@user_sno", User_sno); long sno = vdm.insertScalar(cmd); // Select the checkboxes from the GridView control for (int i = 0; i < grdMylocation.Rows.Count; i++) { GridViewRow row = grdMylocation.Rows[i]; bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked; if (isChecked) { cmd = new MySqlCommand("insert into location_groups_mapping (location_group_sno,branch_sno) values (@location_group_sno,@branch_sno) "); cmd.Parameters.Add("@location_group_sno", sno); cmd.Parameters.Add("@branch_sno", grdMylocation.Rows[i].Cells[9].Text); vdm.insert(cmd); // Column 2 is the name column] //selectedvalues.Add(grdMylocation.Rows[i].Cells[11].Text, grdMylocation.Rows[i].Cells[10].Text); // str.Append(grdMylocation.Rows[i].Cells[2].Text); } } } else { GridViewRow gvr = list_groups.SelectedRow; string group_id = gvr.Cells[1].Text; if (group_id != "") { cmd = new MySqlCommand("update location_groups set location_group_name=@location_group_name,user_sno=@user_sno where sno=@sno"); cmd.Parameters.Add("@location_group_name", txt_groupname.Text); cmd.Parameters.Add("@user_sno", User_sno); cmd.Parameters.Add("@sno", group_id); vdm.Update(cmd); cmd = new MySqlCommand("delete from location_groups_mapping where location_group_sno=@lgs"); cmd.Parameters.Add("@lgs", group_id); vdm.Delete(cmd); for (int i = 0; i < grdMylocation.Rows.Count; i++) { GridViewRow row = grdMylocation.Rows[i]; bool isChecked = ((CheckBox)row.FindControl("chkSelect")).Checked; if (isChecked) { cmd = new MySqlCommand("insert into location_groups_mapping (location_group_sno,branch_sno) values (@location_group_sno,@branch_sno) "); cmd.Parameters.Add("@location_group_sno", group_id); cmd.Parameters.Add("@branch_sno", grdMylocation.Rows[i].Cells[9].Text); vdm.insert(cmd); // Column 2 is the name column] //selectedvalues.Add(grdMylocation.Rows[i].Cells[11].Text, grdMylocation.Rows[i].Cells[10].Text); // str.Append(grdMylocation.Rows[i].Cells[2].Text); } } } } FillCategoryName(); BtnMyLocatoinRefresh_Click(null, null); // prints out the result // Response.Write(str.ToString()); }
protected void BtnSave_Click(object sender, EventArgs e) { try { vdm = new VehicleDBMgr(); if (Session["DtStockInv"] == null) { lblmsg.Text = "Session Expired "; } else { string SalesOfficeId = ddlSalesOffice.SelectedValue; if (SalesOfficeId == "472") { SalesOfficeId = "158"; } DataTable dtInvReport = (DataTable)Session["DtStockInv"]; //DataTable dtProReport = (DataTable)Session["DtStockPro"]; //DataTable dtStockInvProduct = (DataTable)Session["dtStockInvProduct"]; foreach (DataRow dr in dtInvReport.Rows) { try { cmd = new MySqlCommand("Insert into clotrans(BranchID,Amount,IndDate,SalesType,BranchType,BranchRouteID,EmpID) Values(@BranchID,@Amount,@IndDate,@SalesType,@BranchType,@BranchRouteID,@EmpID)"); cmd.Parameters.AddWithValue("@BranchID", dr["AgentCode"].ToString()); cmd.Parameters.AddWithValue("@Amount", dr["Amount"].ToString()); cmd.Parameters.AddWithValue("@IndDate", DateTime.Now.AddDays(-1)); cmd.Parameters.AddWithValue("@SalesType", 20); cmd.Parameters.AddWithValue("@EmpID", Session["UserSno"].ToString()); cmd.Parameters.AddWithValue("@BranchType", dr["CollectionType"].ToString()); cmd.Parameters.AddWithValue("@BranchRouteID", dr["RouteID"].ToString()); long Sno = vdm.insertScalar(cmd); //long Sno = 0; DataRow[] drInvData = dtInvReport.Select("AgentCode=" + dr["AgentCode"].ToString()); if (drInvData.Count() > 0) { DataTable dtInv = drInvData.CopyToDataTable(); foreach (DataRow drv in dtInv.Rows) { cmd = new MySqlCommand("Insert into closubtraninventory (RefNo,InvSno,StockQty) values(@RefNo,@InvSno,@StockQty)"); cmd.Parameters.AddWithValue("@RefNo", Sno); cmd.Parameters.AddWithValue("@InvSno", drv["Inv_Sno"].ToString()); cmd.Parameters.AddWithValue("@StockQty", drv["Qty"].ToString()); vdm.insert(cmd); } } } catch { } } //cmd = new MySqlCommand("Insert into clotrans(BranchID,IndDate,SalesType,EmpID) Values(@BranchID,@IndDate,@SalesType,@EmpID)"); //cmd.Parameters.AddWithValue("@BranchID", SalesOfficeId); //cmd.Parameters.AddWithValue("@IndDate", DateTime.Now); //cmd.Parameters.AddWithValue("@SalesType", 21); //cmd.Parameters.AddWithValue("@EmpID", Session["UserSno"].ToString()); //long RefSno = vdm.insertScalar(cmd); //foreach (DataRow drv in dtProReport.Rows) //{ // cmd = new MySqlCommand("Insert into closubtranprodcts (RefNo,ProductID,StockQty,LeakQty) values(@RefNo,@ProductID,@StockQty,@LeakQty)"); // cmd.Parameters.AddWithValue("@RefNo", RefSno); // cmd.Parameters.AddWithValue("@ProductID", drv["Product_sno"].ToString()); // float BranchQty = 0; // float LeakQty = 0; // float.TryParse(drv["BranchQty"].ToString(), out BranchQty); // float.TryParse(drv["LeakQty"].ToString(), out LeakQty); // cmd.Parameters.AddWithValue("@StockQty", BranchQty); // cmd.Parameters.AddWithValue("@LeakQty", LeakQty); // if (BranchQty != 0 || LeakQty != 0) // { // vdm.insert(cmd); // } //} //foreach (DataRow drv in dtStockInvProduct.Rows) //{ // cmd = new MySqlCommand("Insert into closubtraninventory (RefNo,InvSno,StockQty) values(@RefNo,@InvSno,@StockQty)"); // cmd.Parameters.AddWithValue("@RefNo", RefSno); // int Qty = 0; // int.TryParse(drv["Qty"].ToString(), out Qty); // cmd.Parameters.AddWithValue("@InvSno", drv["sno"].ToString()); // cmd.Parameters.AddWithValue("@StockQty", Qty); // if (Qty != 0) // { // vdm.insert(cmd); // } //} lblmsg.Text = "Saved successfully"; } } catch (Exception ex) { lblmsg.Text = ex.ToString(); } }