Sunday, 17 March 2013

how to save multiple record at a time using list

 if (OnSubmitValidation())
                {
                    List<POS_TemplateDesign> listRecord = new List<POS_TemplateDesign>();
                    POS_TemplateDesign obj = new POS_TemplateDesign();
                    obj.Template_ID = int.Parse(GetSelectedList("Invoice")[0].ToString());
                    obj.Template_Type_ID = int.Parse(GetSelectedList("Invoice")[1].ToString());
                    obj.Created_By = UserID;
                    obj.Company_Id = CompanyID;
                    obj.mark = 3;
                    listRecord.Add(obj);

                    obj = new POS_TemplateDesign();
                    obj.Template_ID = int.Parse(GetSelectedList("Shipping")[0].ToString());
                    obj.Template_Type_ID = int.Parse(GetSelectedList("Shipping")[1].ToString());
                    obj.Created_By = UserID;
                    obj.Company_Id = CompanyID;
                    obj.mark = 3;
                    listRecord.Add(obj);

                    obj = new POS_TemplateDesign();
                    obj.Template_ID = int.Parse(GetSelectedList("Packaging")[0].ToString());
                    obj.Template_Type_ID = int.Parse(GetSelectedList("Packaging")[1].ToString());
                    obj.Created_By = UserID;
                    obj.Company_Id = CompanyID;
                    obj.mark = 3;
                    listRecord.Add(obj);
                    ERPManagement.GetInstance.InsertTemplateFinal(listRecord);
                    MessageCustome("Data Saved Successfully", 'i');
                    listRecord.Clear();
                    OnPageDefault();
                }
            }

 public void InsertTemplateFinal(List<POS_TemplateDesign> objlist)
        {
            foreach (POS_TemplateDesign obj in objlist)
            {
                SqlCommand cm = new SqlCommand("Pos.KC_SelectTemplateDesignSetup");
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.AddWithValue("@Company_ID", obj.Company_Id);
                cm.Parameters.AddWithValue("Template_ID", obj.Template_ID);
                cm.Parameters.AddWithValue("@Template_Type_ID", obj.Template_Type_ID);
                cm.Parameters.AddWithValue("@Created_By", obj.Created_By);
                cm.Parameters.AddWithValue("@mark", obj.mark);
                ExecuteStoredProcedure(cm);
            }

        }

No comments:

Post a Comment