public t f_put_payment_wd(t args) { t payment = args["payment"]; t order=args["order"]; t payments_to_kibicom = args["payments_to_kibicom"]; //возвращаемые данные t res = new t() { {"payments_to_kibicom",payments_to_kibicom}, {"self", this} }; if (payment["dt_make"].f_is_empty() || payment["sm"].f_is_empty()) { return res; } t_msslq_cli mssql_cli=new t_msslq_cli(new t() { {"conn", dbconn._db.command.Connection} }); this["mssql_cli"].f_set(mssql_cli); DataTable tab_payment = dbconn._db.GetDataTable("select top 0 * from paymentdoc"); tab_payment.TableName = "paymentdoc"; DataTable tab_paymentgroup = dbconn._db.GetDataTable("select * from paymentgroup"); DataRow dr_o=dbconn._db.GetDataRow("select * from orders where guid ='"+order["wd_order_guid"].f_str()+"' "); //если у платежа нет guid из WD значит платеж новый if (payment["wd_paymentdoc_guid"].f_is_empty()) { DataRow dr = tab_payment.NewRow(); string idpaymentdoc = mssql_cli.f_exec_cmd(new t() { {"cmd" , "exec gen_id 'gen_paymentdoc'"}, {"exec_scalar", true} })["res_cnt"].f_str(); Guid guid = Guid.NewGuid(); //MessageBox.Show(payment["tab_payment_way"][0]["name"].f_str()); DataRow[] pg_dr_arr = tab_paymentgroup.Select("name = '" + payment["tab_payment_way"][0]["name"].f_str()+"'"); dr["idpaymentdoc"] = idpaymentdoc; dr["idorder"] = dr_o["idorder"].ToString(); dr["name"] = payment["name"].f_str(); dr["idpaymentdocgroup"] = f_get_idpaymentdocgroup(new t() { { "payment", payment } })["idpaymentdocgroup"].f_str(); dr["idpaymentgroup"] = (pg_dr_arr.Length > 0 ? "0" : pg_dr_arr[0]["idpaymentgroup"].ToString()); dr["iddocoper"] = 5; dr["smbase"] = payment["sm"].f_str(); dr["comment"] = payment["comment"].f_str(); dr["guid"] = guid; tab_payment.Rows.Add(dr); mssql_cli.f_store_tab(new t() { {"tab", tab_payment}, { "f_done", new t_f<t,t>(delegate (t args2) { //запоминаем сформированный guid и помещаем на отправку в кибиком payment["wd_paymentdoc_guid"].f_set(guid.ToString().ToLower()); payments_to_kibicom.Add(payment); res.f_when_done(new t() { {"f_name", "f_done"}, {"f_args", new t(){{"payments_to_kibicom",payments_to_kibicom}}} }); return new t(); }) } }); } else //иначе обновляем существующий по guid { /* DataRow dr = tab_payment.NewRow(); dr["name"] = payment["name"].f_str(); dr["idpaymentgroup"] = tab_paymentgroup.Select("name = '" + payment["tab_payment_way"]["name"].f_str()); dr["smbase"] = payment["smbase"].f_str(); dr["comment"] = payment["comment"].f_str(); dr["guid"] = payment["wd_paymentdoc_guid"].f_str(); dr.SetModified(); mssql_cli.f_exec_cmd(new t() { { "cmd" , @"update paymentdoc " +" set name="+payment["name"].f_str()+"," +" set idpaymentgroup"+tab_paymentgroup.Select ( "name = '" + payment["tab_payment_way"]["name"].f_str() )+"," +" set smbase"++"," }, {"exec_scalar", true} })["res_cnt"].f_str(); */ } /* string cmd = "insert "+tab_name+" (id, idgood, marking, idorder, name, qu) values ("+ t_sql_builder.f_db_val(tabres_id)+","+ t_sql_builder.f_db_val(mc_dr, "id_good")+","+ t_sql_builder.f_db_val(mc_dr, "marking_id")+","+ t_sql_builder.f_db_val(mc_dr, "idorder")+","+ t_sql_builder.f_db_val("good_needs")+","+ t_sql_builder.f_db_val(mc_dr, "qu")+")" */ return res; }
public t f_cre_local_db(t args) { string store_type = args["store_type"].f_str(); t_sql_store_cli cli = null; if (store_type == "mssql") { //параметры переданне для этого подключения t mssql_cli=args["mssql_cli"]; //создаем клиента cli = new t_msslq_cli(new t() { {"connection_str", mssql_cli["connection_str"]}, {"server", mssql_cli["server"]}, {"server_name", mssql_cli["server_name"].f_def("")}, {"login", mssql_cli["login"]}, {"pass", mssql_cli["pass"]}, {"db_name", mssql_cli["db_name"]}, {"tab_name", mssql_cli["tab_name"]}, {"conn", mssql_cli["conn"]}, {"conn_keep_open", mssql_cli["conn_keep_open"].f_def(true)} }); } else if (store_type=="sqlite") { //параметры переданне для этого подключения t sqlite_cli = args["sqlite_cli"]; string file_name = sqlite_cli["file_name"].f_str(); if (File.Exists(file_name)) File.Delete(file_name); //создаем клиента, подключаемся cli = new t_sqlite_cli(new t() { {"location", file_name}, {"conn_keep_open", true} }); } //запоминаем клиента this["sql_store_cli"].f_set(cli); return this; }