Beispiel #1
0
        private void btnCreateDespatch_Click(object sender, EventArgs e)
        {
            try
            {
                //bos eleamn olmaması
                if (validEmptyComponent())
                {
                    //tutar hesapla
                    calculateTotalAmount();

                    //kullanıcı bılgılerı getır
                    getUserInformationOnDb();

                    //////////UBL OLUSTURMA ISLEMI////////
                    DespatchAdviceUbl despatch = new DespatchAdviceUbl(gridPrice.RowCount, dateTimeDespatchDate.Value.Date, Convert.ToDateTime(cmbDespatchTime.Text),
                                                                       txtOrderId.Text, dateTimeOrderDate.Value.Date);


                    PartyType supParty;
                    PartyType cusParty;
                    string    schemaType;

                    //SUPPLİER  PARTY OLUSTURULMASI
                    supParty = despatch.createParty(partyName, cityName, telephone, mail);
                    if (senderVknTc.Length == 10) //sup vkn
                    {
                        schemaType = nameof(EI.VknTckn.VKN);
                        despatch.addPartyTaxSchemeOnParty(supParty);
                    }
                    else  //sup tckn .. add person metodu eklenır
                    {
                        schemaType = nameof(EI.VknTckn.TCKN);
                        despatch.addPersonOnParty(supParty, firstName, familyName);
                    }
                    despatch.addPartyIdentification(supParty, 1, schemaType, senderVknTc, "", "", "", "");
                    despatch.SetSupplierParty(supParty);

                    //CUST PARTY OLUSTURULMASI
                    cusParty = despatch.createParty(txtPartyName.Text, txtCity.Text, "", txtMail.Text);
                    if (msdVknTc.Text.Length == 10) //customer vkn
                    {
                        schemaType = nameof(EI.VknTckn.VKN);
                        despatch.addPartyTaxSchemeOnParty(cusParty);
                    }
                    else  //customer tckn
                    {
                        schemaType = nameof(EI.VknTckn.TCKN);
                        despatch.addPersonOnParty(cusParty, txtCustName.Text, txtCustSurname.Text);
                    }
                    despatch.addPartyIdentification(cusParty, 1, schemaType, msdVknTc.Text, "", "", "", "");
                    despatch.SetCustomerParty(cusParty);

                    //SHİPMENT
                    if (msdCarrierTcVkn.Text.Length == 10)
                    {
                        schemaType = nameof(EI.VknTckn.VKN);
                    }
                    else
                    {
                        schemaType = nameof(EI.VknTckn.TCKN);
                    }
                    despatch.createShipment(gridPrice.Rows.Count, txtPlate.Text, txtOrderId.Text, txtDriverName.Text, msdDriverTc.Text, dateTimeConsignmentDate.Value.Date, Convert.ToDateTime(cmbConsignmentTime.Text), schemaType, msdCarrierTcVkn.Text);


                    //INV LINE OLUSTURULMASI
                    foreach (DataGridViewRow row in gridPrice.Rows)
                    {
                        //Inv Lıne Olusturulması
                        //unıt code get fonk cagırılarak secılen bırımın unıt codu getırılırilerek aktarılır
                        despatch.addDespatchLine((row.Index + 1).ToString(), getUnitTimeCode(row.Cells[nameof(EI.InvLineGridRowClm.unit)].Value.ToString()), Convert.ToInt32(row.Cells[nameof(EI.InvLineGridRowClm.quantity)].Value),
                                                 row.Cells[nameof(EI.InvLineGridRowClm.productName)].Value.ToString(), Convert.ToDecimal(row.Cells[nameof(EI.InvLineGridRowClm.unitPrice)].Value), cmbMoneyType.Text);
                    }

                    despatch.setDespatchLines();


                    //olusturdugumuz nesne ubl turune cevrılır
                    var despatchUbl = despatch.baseDespatchUbl;

                    //xml olusturup dıske yazdır
                    string xmlPath = FolderControl.writeDiscDespatchConvertUblToXml(despatchUbl);

                    //xml olusturup yazdırma basarılı mı
                    if (xmlPath != null)
                    {
                        //db ye kaydet
                        if (Singl.DespatchAdviceDalGet.insertDespatchOnDbFromUbl(despatchUbl, xmlPath) == 1)
                        {
                            MessageBox.Show(xmlPath + "  irsaliye kaydedıldı");
                        }
                        else
                        {
                            MessageBox.Show("Db ye kaydetme başarısız");
                        }
                    }
                    else
                    {
                        MessageBox.Show("işlem basarısız");
                    }
                }
                else  //bos eleman varsa
                {
                    MessageBox.Show("yıldızlı alanları bos bırakmayınız");
                }
            }
            catch (FaultException <REQUEST_ERRORType> ex) //oib req error
            {
                if (ex.Detail.ERROR_CODE == 2005)
                {
                    Singl.authControllerGet.Login(FrmLogin.usurname, FrmLogin.password);
                }
                MessageBox.Show(ex.Detail.ERROR_SHORT_DES, "ProcessingFault", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                MessageBox.Show(Lang.dbFault, "DataBaseFault", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }